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.

PWM to controll the fan(12 dc motor with driver) using 16f877a and lm35***help plz***

Status
Not open for further replies.

erfan.khalilian69

Member level 4
Joined
Feb 7, 2011
Messages
71
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Kualalampur
Activity points
1,916
Hi everyone
in my project I want to increasing the speed of dc motor according to the temperature , I have found some sample source I try to modified it but it does not working (simulated with Proteus)
here is the code :
#define alarm RC1 // activate as fan but I put led for this part
#define motor RC2//DC motor activate as fan


unsigned char speed=50;


//////////////////////SET PWM//////////////////////////////////////

CCP1CON = 0b00001100; //PWM Mode
PR2 = 0xFF; //PWM Period Setting//PWM frequecy set as 4.88KHz
T2CON = 0b00000101; //Timer2 On, prescale 4
CCPR1L=0;

f(temperature>27)// when the temperature goes above the 27 degree C the fan activated otherwise the fan is deactivated
{
alarm=1;
}


else if (temperature>30)
{

while(temperature>30)continue;

CCP1CON = 0b00001100; //PWM Mode
PR2 = 0xFF; //PWM Period Setting//PWM frequecy set as 4.88KHz
T2CON = 0b00000101; //Timer2 On, prescale 4
CCPR1L=speed; }




/* else if (temperature<27)

{
CCPR1L=0;
}*/





/*else if (temperature>35)

{
if(speed<255)speed+=1;
CCPR1L=speed; // INCREMENT THE SPEED OF MOTOR
delay(5000);
}

else if (temperature<35)
{
if(speed>0)speed-=1;
CCPR1L=speed; // DECREMENT THE SPEED OF MOTOR
delay(5000);

}

plzzzzzzzzzz help

actually while I write CCPR1L=0; then it does not work at all ? i dun know why ?

any advice ?



thanks everyone

---------- Post added at 20:39 ---------- Previous post was at 20:37 ----------

here is the main code which I have tried to modified it :

//==========================================================================
#define BUTTON1 RA1
#define BUTTON2 RA2
#define BUTTON3 RA3
#define BUTTON4 RA4
#define CCW RB1
#define CW RB2

// function prototype
//==========================================================================
void delay(unsigned long data);

// global variable
unsigned char temp=50;

// main function
//==========================================================================
void main(void)
{

ADCON1 = 0x06; //Configure Poart A as digital I/O

TRISA = 0b11111111; //Set pin RA1 to RA4 as input for press button switch
TRISB = 0b00000000; //Set pin RB1 & RB2 as output for MD10A
TRISC = 0b11000000; //Set pin RC2 as output for PWM

CCP1CON = 0b00001100; //PWM Mode

//PWM frequecy set as 4.88KHz
PR2 = 0xFF; //PWM Period Setting
T2CON = 0b00000101; //Timer2 On, prescale 4

//Motor stop
CCPR1L = 0; //No PWM Duty Cycle
CW = 0;
CCW = 0;

while(1) //Infinity Loop
{
if(BUTTON1==0) //Brake
{
CCPR1L=0;
CW=0;
CCW=0;
}

else if(BUTTON2==0) //Change the Rotational Direction
{
while(BUTTON2==0)continue;
CCPR1L=temp;
CW=!CW;
CCW=!CW;
}

else if(BUTTON3==0) //Speed Increment
{
if(temp<255)temp+=1;
CCPR1L=temp;
delay(5000);
}

else if(BUTTON4==0) //Speed Decrement
{
if(temp>0)temp-=1;
CCPR1L=temp;
delay(5000);
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top