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.

servo motor control via pulse width modulation

Status
Not open for further replies.

systemchaos

Newbie level 2
Joined
Feb 21, 2007
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
generate pwm to control servo motor

i am a newbie and i'm working on a c programming code to control servo motor via pwm. i'm using pic16f877A because it has 2 CCP pins that i can use to generate pwm with 20MHz osc. Since then i have a few problem to make the servo to turn clockwise, counterclockwise and stop in writing the program's code. The most problem i'm probably faced is how to set the timer value.
According to the PIC16F877A datasheet, it provide an equation which is
pwm period= [PR2+1]*4*Tosc*[TMR2 prescale value]

From the equation what is 'pwm period' , 'PR2' and 'TMR2 prescale value'?

I've found a c programming code on the internet where he use an equation
pwm period = (1/clock)*4*t2div*(period+1)
I think this equation might be same as the equation provided by the datasheet. From his calculations, he use 1 MHz osc to find the period where the period must be an 8-bit value due to the fact that the PIc use an 8-bit divisor which 0-255. Then he use pwm period=10ms , and t2div=16 since the t2div can have three possible values 1, 4, or 16). Finally he get the period=155 (in the range of 0-255).
Since i used osc=20MHz and pwm period=20 ms, i get the period= 6249 which is too big. Now i'm don't know what to do. i've tried to search the solution through the internet but still not get it.:cry:
So, what is the possible solution that i should make this done? Which timer should i use, is it tmr0, tmr1 or tmr 2? and how to find the pwm value to stop, cw and ccw the servomotors?

The next problem is when i'm using source boost IDE (boostc) . How to define and set up the CCP pin and the timer? Should i have to use C2C-plus? And how to write the programming in c?
I hope that anyone can guide me and i'm really appreciate that..regards
systemchaos
 

control servo pic tmr

I use the PIC18FX and its PWM equation looks the same to me
I hope the attached EXCEL file will help you
 

servo motor control pulse width

hey jepeto,
thanks for the attached file..
a have a question..what is CCP (10bit)? how it suppose to be?.. any example??
 

motor control via pwm

10bit for PWM DUTY CYCLE
8bit - CCPRxL + 2bit CCPxCON<5:4>

the MAX Resolution bits - the maximum bits allowed to use otherwise the DUTY CYCLE will bigger them 100%
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top