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.

PIC16f877A, PWM, to increase the speed of motor according to temperature increasing

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, I have really stock with this part in my project.
I want to increase the speed of motor as the temperature increasing, therefore I've got idea to use different frequency for different temperature.
I know I have to use CCP1CON ,PR2, T2CON . after initializing the PWM I write: CCPR1L=0; to stop the pwm because I want to activate this pin while the temperature is higher than 30 degree. but while I write CCPR1L=0; the PWM is not generating pulse even while the temperature is higher than 27.

here is my code :

unsigned char speed=50;

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

else if (temperature>27)
{


CCPR1L=speed;
}


any suggestion?


thanks
 

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
yes
but first I need to correct my condition actually the condition is not working properly , I have just downloaded some sample which they used 4 buttons to increase the speed decrease and change the direction, instead of button now I want to use if else condition for temperature, but this program while executed the motor keeping running and after some seconds it will be stop. and then while I delete the // if(speed<255)speed+=1; it does not activated any more, what should I do sir ???
else if (temperature>30)

{
// 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);

}

---------- Post added at 19:44 ---------- Previous post was at 19:40 ----------

Do you mind if I send you whole program by email and you tell me what is the problem with this problem, this problem is actually show the temperature and light in LCD and then for certain temperature and light intensity the fan and lamp will be activated. now my lecture gives me new task to increase the speed of fan according to the increasing temperature.
the submission date its just this Monday :(
 

horace1

Advanced Member level 5
Joined
Nov 18, 2008
Messages
2,123
Helped
596
Reputation
1,188
Reaction score
573
Trophy points
1,393
Location
Norwich, UK
Activity points
13,071
don't use PIC16s anymore but below is some PWM code I wrote some years back for a Microchip Mechatronics board
Mechatronics Demonstration Kit

it used a PIC16F917 - hopefully the comments explain what is going on
Code:
// initialise PWM using Capture Compare PWM Module 2
void PWMinitialise(void)
{
        // assume Fosc uses oscillator 8MHz - call systemInitialise() first
        TRISD2=0;                // set RD2/CCP2 is output
        TRISD7=0;                // set RD7 is output
        PR2=0x3f;                // set PR2 to 31.2 kHz PWM (PWM value will be 8 bits)
        // Configure Capture Compare PWM Module 2
        CCPR2L=0;                // set PWM duty cycle to 0
        CCP2CON=0xC;             // set PWM mode
        TMR2ON=1;                // Turn on Timer 2 PWM
}

// set PWM duty cycle - value between 0 and 100
void PWMcontrol(int dutyCycle)
{
        // get 8 bit value for PWM control at 31.2 kHz PWM
        dutyCycle = (int) (dutyCycle * 255L / 100L);             // get 8 bit value
        RD7=1;                                                   // switch on motor
        // load most significant 6 bits in CCPR2l and least significant two bits in CCP2CON
        CCPR2L=dutyCycle >> 2;                          
        CCP2CON = (CCP2CON & 0xF) + ((dutyCycle << 4) & 0x30);   // set bits 4 and 5
}
 

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
thanks for replaying. why u say dun use pic16s? can i know the reason?
so how can I activate and deactivate the pwm so
?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top