Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] PWM and RPM of DC fan

Status
Not open for further replies.

aameer

Full Member level 4
Full Member level 4
Joined
May 12, 2010
Messages
216
Helped
33
Reputation
64
Reaction score
32
Trophy points
1,308
Location
Bangalore
Activity points
2,503
i want to interface dc 12v dc fan to micro controller and with 2 switches i want to increase or decrease the speed of the fan ,simultaneously i want to measure the rpm of that fan and display on LCD. i just now started to interface LCD and switches. how to proceed please guide me.
i am using at89c52 micro controller and Kiel u vision 4 for c programming.

Please its urgent
Code:
#include<reg51.h>

#define lcd_data_port P1

sbit lcd_rs = P0^0;
sbit lcd_en = P0^1;

sbit inc_key=P2^0;
sbit dec_key=P2^1;


void lcd_initial(void);
void lcd_initial_msg(void);
void lcd_cmd(unsigned char cmd_value);
void lcd_data(unsigned char data_value);
void lcd_data_string(unsigned char *string);

void delay_ms(unsigned int delay_value);


void main()
{
	lcd_initial();
	delay_ms(100);
	lcd_initial_msg();
	delay_ms(100);

	while(1)
	{
		if(inc_key==0)
		{
			
		}

		else if(dec_key==0)
		{

		}


	}

}

void lcd_initial_msg(void)
{
	lcd_cmd(0x01);
	lcd_data_string(" PWM & RPM ");
	lcd_cmd(0xC1);
	lcd_data_string("with DC Fan");
	delay_ms(300);
	lcd_cmd(0x01);
}


void lcd_initial(void)
{
	lcd_cmd(0x01);
	lcd_cmd(0x06);
	lcd_cmd(0x38);
	lcd_cmd(0x0C);
}

void lcd_cmd(unsigned char cmd_value)
{
	lcd_data_port = cmd_value;
	lcd_rs = 0;
	lcd_en = 1;
	delay_ms(2);
	lcd_en = 0;
}

void lcd_data(unsigned char data_value)
{
	lcd_data_port = data_value;
	lcd_rs = 1;
	lcd_en = 1;
	delay_ms(2);
	lcd_en = 0;

}

void lcd_data_string(unsigned char *string)
{
	unsigned char m=0;
	while(string[m]!='\0')
	{
 	  	lcd_data(string[m]);				  
 	  	m++;
   	}
}

void delay_ms(unsigned int delay_value)
{
	unsigned int x,y;
	for(x=0;x<delay_value;x++)
		for(y=0;y<1275;y++);
}

pwm.png
 

https://cache.freescale.com/files/microcontrollers/doc/app_note/AN3471.pdf

this is just reference for you.One thing you try to control DC ceiling fan?if yes then just increase the duty cycle when up or increment duty cycle of your PWM and decrease the duty cycle when down or decrement key pressed.

To generate the PWM you can use the timer for generate the desired frequency signal.
 

thanks for the response. i am interfacing 12v dc fan

1pc-Brushless-DC-Cooling-Fan-25x25x10mm-12V-2510S.jpg
 

I can give you PIC code. How much is 40 pin AT89C51 ? 1 $ ? 2 $ ? If you can use a 1.2 $ PIC12F1840 then I can write a code for you to control fan speed using PWM based on temperature. PIC12F1840 is a 8 pin PIC. It has ADC and PWM. To get precise PWM signal you can also use external crystal.
 

thanks milan. i can understand you but it is for academic project for my cousin.Their lecturers want them to do in 8051 as they have in academic subject. In PIC there well be inbuilt PWM. i also told him but he is not willing.
 

thanks ud. Can u tell me the hardware part. whether i have to use optocoupler or h bridge . Please provide me the circuit between micro controller pin and Dc fan.
 
Last edited:

Hello!

I'm not sure you can control a brushless motor by PWM. This is not a program issue but a
system issue.
- A brushed DC motor gets the proper current at the proper time by using a current collector
ring (I don't know the word in english, sorry) and brushes.
- In the case of a motor that runs continuously for long periods, the brushes would get damaged
vey quickly, therefore the commutation is replaced by position detection with hall or optical
sensors. This means that you have an electronic board aimed at commuting the proper current
at the proper coil. This board works of course in DC.

Now you are apparently experienced with processor. Try to imagine that you are powering
your processor with a PWM signal instead of DC,,,

That said, I can't pretend I know all the brushless motors technology and maybe you can control
some of them in PWM, but I would say you simply can't.

Dora.
 

can i use opto coupler ,SCR or h bridge for interfacing fan with micro controller for speed control
Code:
#include<reg51.h>

#define lcd_data_port P1

sbit PWMPIN = P2^4  ;

sbit lcd_rs = P0^0;
sbit lcd_en = P0^1;

sbit quarter_key=P2^0;//switches
sbit half=P2^1;
sbit threefourth=P2^2;
sbit full=P2^3;


unsigned char pwm_width;
bit pwm_flag = 0;

void pwm_setup(unsigned char z);

void lcd_initial(void);
void lcd_initial_msg(void);
void lcd_cmd(unsigned char cmd_value);
void lcd_data(unsigned char data_value);
void lcd_data_string(unsigned char *string);

void delay_ms(unsigned int delay_value);

void timer0() interrupt 1 
{
	if(!pwm_flag) 
	{	//Start of High level
		pwm_flag = 1;	//Set flag
		PWMPIN = 1;	//Set PWM o/p pin
		TH0 = pwm_width;	//Load timer
		TF0 = 0;		//Clear interrupt flag
		return;		//Return
	}
	else 
	{	//Start of Low level
		pwm_flag = 0;	//Clear flag
		PWMPIN = 0;	//Clear PWM o/p pin
		TH0 = 255 - pwm_width;	//Load timer
		TF0 = 0;	//Clear Interrupt flag
		return;		//return
	}
}
void main()
{
	lcd_initial();
	delay_ms(100);
	lcd_initial_msg();
	delay_ms(100);

	while(1)
	{
		if(quarter_key==0)
			pwm_setup(65);

		else if(half==0)
			pwm_setup(130);
		else if(threefourth==0)
			pwm_setup(190);
		else if(full==0)
			pwm_setup(255);


	}

}

void lcd_initial_msg(void)
{
	lcd_cmd(0x01);
	lcd_data_string(" PWM & RPM ");
	lcd_cmd(0xC1);
	lcd_data_string("with DC Fan");
	delay_ms(300);
	lcd_cmd(0x01);
}

void pwm_setup(unsigned char z)
{
	TMOD = 0;
	pwm_width = z;
	EA = 1;
	ET0 = 1;
	TR0 = 1;
}


void lcd_initial(void)
{
	lcd_cmd(0x01);
	lcd_cmd(0x06);
	lcd_cmd(0x38);
	lcd_cmd(0x0C);
}

void lcd_cmd(unsigned char cmd_value)
{
	lcd_data_port = cmd_value;
	lcd_rs = 0;
	lcd_en = 1;
	delay_ms(2);
	lcd_en = 0;
}

void lcd_data(unsigned char data_value)
{
	lcd_data_port = data_value;
	lcd_rs = 1;
	lcd_en = 1;
	delay_ms(2);
	lcd_en = 0;

}

void lcd_data_string(unsigned char *string)
{
	unsigned char m=0;
	while(string[m]!='\0')
	{
 	  	lcd_data(string[m]);				  
 	  	m++;
   	}
}

void delay_ms(unsigned int delay_value)
{
	unsigned int x,y;
	for(x=0;x<delay_value;x++)
		for(y=0;y<1275;y++);
}
 

you need use current driver like mosfet opto coupler won't help you. you can use h bridge or check the maxim link will help you.
 

People don't usually change the direction of Brushless DC Fan. H-Bridge is used to change direction of motor.
 

for h bridge i need 2 inputs rite.how shall i connect
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top