Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Control 2 servo motors (continuous rotation) with PIC18F452

Status
Not open for further replies.

skyx

New Member
I'm having trouble controlling 2 servo motors with the PIC18F452. These two motors are used for the movement of my robot. I've tried the PWM approach but this PIC only has 1 timer (TIMER2) this mode.

I also use the Compare Mode, but can't seem to get the servos to respond correctly. Does anyone have had experience this PIC and can give some advices/suggestions?
 
Re: Control 2 servo motors (continuous rotation) with PIC18F

skyx said:
I'm having trouble controlling 2 servo motors with the PIC18F452. These two motors are used for the movement of my robot. I've tried the PWM approach but this PIC only has 1 timer (TIMER2) this mode.

Its true there is only one Timer2 which means that the PWM period is fixed for two PWM channels but the two PWM channels can have different duty cycles available on two output pins. You can change the duty cycle of each one individually. This means you can control the speed of two motors differently using the PWM outputs.

Just choose a PWM period suitable for both motors.
 
You could use the PIC's CCP along with timer1 to time the pulses down to 1us (@8mhz). You can have a servo handler run every 20ms for 2.5ms for 1 servo, then another 2.5ms for the other servo, then use/wait another 15ms for the rest of your code. If you'd like to combine the code a bit more, you can time them both in a 2.5ms slice using CCP1 and CCP2 (I'm assuming your PIC has both).

Rick
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top