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.

Dc motor speed control using pwm + pic16f877a

Status
Not open for further replies.

coolvasanth07

Member level 1
Member level 1
Joined
Sep 25, 2012
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,506
Hi, in my project i want to control dc motor using pwm...am using pic16f877a+hi-tech c compiler..it's urgent plz...
>>thanks in advance<<
 

Here an example of pwm setting but codes' explained in turkish still it will help you
 

Attachments

  • PWM try.rar
    52.8 KB · Views: 216
Hi, in my project i want to control dc motor using pwm...am using pic16f877a+hi-tech c compiler..it's urgent plz...
>>thanks in advance<<

You can get what you need here: https://www.edaboard.com/blog/1812/

Circuit + Waveform:
6122637700_1353603051.png


Code:
//-------------------------------------------------------------------------------------------------------

//Programmer: Syed Tahmid Mahbub
//Compiler: mikroC PRO for PIC v4.60

unsigned int ADR;

void main() {
     PORTC = 0;
     TRISC = 0; //all PORTC pins output
     PORTA = 0;
     TRISA = 0x01; //RA0 input for pot
     CMCON = 7; //Disable analog comparators
     T2CON = 0; //Prescaler 1:1, TMR2 off
     ADCON1 = 14; //AN0 only analog
     ADC_Init(); //mikroC initializes ADC
     CCP1CON = 12; //PWM mode
     PR2 = 249; //16kHz PWM frequency
     while (1){
           ADR = ADC_Get_Sample(0) >> 2; //Get ADC reading for channel 0
           //and divide reading by 4
           if (ADR < 10){ //Setting lower bound
              TMR2ON_bit = 0; //Stop Timer and so stop PWM
              TMR2 = 0; //Clear Timer
              RC2_bit = 0; //Clear PWM output
           }
           else{
                if (ADR > 240){ //Setting upper bound
                   TMR2ON_bit = 0; //Stop Timer and so stop PWM
                   TMR2 = 0; //Clear Timer
                   RC2_bit = 1; //Keep PWM output high
                }
                else{ //Within upper and lower bounds
                      CCPR1L = ADR; //Set PWM duty cycle
                      TMR2ON_bit = 1; //If not on, turn on TMR2. If on, keep on
                }
           }
     }
}

//-------------------------------------------------------------------------------------------------------


Although the code there is in mikroC, you can very easily port it to Hi-Tech C.

Hope this helps.
Tahmid.
 
Dear Tahmid I have messaged u my code. Kindly chek that code. I dont know where the lies. I have read ur tutorials and made the accordingly but the PWM is not working I think.. I want to use fix pwm at 50%. It gives the pulse for some time but not untill the condition is satisfied. plz check my code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top