Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Dc motor speed control using pwm + pic16f877a

Status
Not open for further replies.

coolvasanth07

Member level 1
Joined
Sep 25, 2012
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
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<<
 

tusemo

Advanced Member level 4
Joined
May 28, 2012
Messages
109
Helped
23
Reputation
46
Reaction score
22
Trophy points
1,298
Location
Turkey
Activity points
1,841
Here an example of pwm setting but codes' explained in turkish still it will help you
 

Attachments

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
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/entry1812.html

Circuit + Waveform:


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.
 

coolvasanth07

Member level 1
Joined
Sep 25, 2012
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,506
Thank u friends (tusemo and Tahmid )....thanx a lot....i got it.....
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545

tak_iiec@yahoo.com

Newbie level 6
Joined
Feb 28, 2011
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,420
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top