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.
im looking for c code for programing pic
to controll 8 servo motors.
the pic shold get serial string from the serial port(rs-232)
and drive 8 sevos,each servo have to get puls between
ill be very gratefull for some help
Because your pulse width is so short (1-2msec) you don't have much time to be reading the incoming serial info. At 9600 baud it would take 1ms to transmit 10 bytes of data (start/stop bytes and 8 bytes of servo data). So every time you transmit to your servos, you may get a blip or hickup in your servos (not good).
Now if you setup the hardware UART with interrupts - you will have no problems. You can do plenty in between UART interrupts at 9600. I have controlled 6 motors with direction lines and series of LEDs that were pulse for ilum control (7PWMs and 6 +/- control) without problems.
Operating at 20MHz you should be good to send the appropriate servo PWMs on the PORTB for instance. Just setup 8 software timers and decrement them in time. As each timer goes to zero, load the new timer value (from the uart interrupt info), and flip the appropriate bit on portb. I would not recommend changing each port indiudally - setup a byte and change that byte - in the end write that byte to port b.
Attached is CC5X C code that I wrote to do this. It's big, but it may help.
Now, I has a project. I want to use AT89C51 to controll servo motor(ac or dc). I have some questions for you:
- Have you got any documents about servo motors?
- On what principle does servo work?
- Can use the AT89C51 to controll servo?
Please nswere on this forum or send to me by email: [email protected]
Thanks and regards!