proof-of-concept: driving 13 servos with attiny2313 over usb

Heh, that proved to be a nice rant on an arduino-lover that complained something about the inability on mega1280 to drive enough servos for his app (usb controlled pan and tilt for a few cams).
I picked an uC that has nor the hardware output-compare channels to drive all 13 servos, nor any hardware usb (attiny2313), threw up a small board and after a few dozen lines of code, here we go:
Attiny2313 driving 13 servos with 16-bit pwm over the usb with little to no external components. I also fitted in an option to set each output to Z-state from the commandline effectively relaxing a servo.


How does that work?
Dumb as hell. I use the only avaliable 16-bit timer to count up to ICR1, and issue an interrupt overflow. All the output-compare logic is done in an endless loop when the uC is not busy doing USB transfers. With all the goodies it fits into 1918 bytes leaving pretty much space avaliable(over 100 bytes!).
The results looked bad at first. With 12Mhz crystal it was still a way TOO jumpy to be of any use. However, when I fitted a 16Mhz crystal it became almost as smooth as I would get it with hardware OC. I guess 18Mhz or 20Mhz would deliver even better results, but I didn’t have those around. (Although the firmware has those freqs defined).
The client software is written (yet again) in lua, and is part of lunartool on the github. (servo-ctl applet)
The project schematics, pcb and firmware are also up on the github.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.