Introduction: DIY 18 Port Servo Controller (Outdated)

This is going to be my first instructables to bear with me, and yes i do have very bad spelling too, so dont hate me for that. This whole project started because i wanted to build my own hexapod and didnt want to have to deal with buying a prebuilt controller or the bot itself (Whats the fun in that?!?!?!?)

This is still a "Work in Progress" i got my boards in a few weeks ago and am working on getting everything to work how i would like it. You are welcome to use anything that i post, but please if you do use what i provide double check and make sure that things are how you want them.

Ill post with this every thing that i have avaliable.

BOM from digikey,
Circuit Schematic, and
Board Layout

Step 1: Background/Prototype

In stead of using a legitimate PWM i did a hacked version of it with an (3 actualy) output compare and a chip with peripheral pin select


since servos operate (typicaly) between 1ms and 2ms, yes i understand there are variations to the actual period for each servo but you get the idea. it is set up such that the 3 output compairs are only at a specific pin for 2ms before they are moved to the next pin. this cycle continues till there is no more servo pins left and foes to a "dummy" state, and then after the 20ms has elapsed the system restarts the servo control. I under stand i may not have said that quite right but ohwell, ill attach some sample code that shows that i mean.

I have 2 designs posted, 1 on the breadboard was the orriginal proof of concept before i designed the board

the final design calls for a 5v regulator the servos, and a 3v regulator for the pic24fj64gb004 and everything in between

=======================================================================================
                                             Code Below
=======================================================================================
void __attribute__ ((interrupt, no_auto_psv)) _T1Interrupt(void) // 20ms
{
// enable the initial settings for an interrup
clock2ms = 0;
//initialize/Reset the 2ms timer
Init2msTimer();
_T2IF = 1;
_T1IF = 0; // clear the interrupt flag
}

void __attribute__ ((interrupt, no_auto_psv)) _T2Interrupt(void) // 2ms
{
// 0-5 represent the 6 servos per Output compair pins
// each case moves the output compair to the respective pins
// enables the servo pin
// sets the output compair value to servo curpos
// default represents that all 6 servo sets have been serviced and to disable the timer
/* case x:
* enable output compare for respective pin
* turn on servo pin
* set output compare value
* disable output compare on previous pin
*
*/


switch(clock2ms)
{
case 0:
// configure the pin
// move OC to the servopp
S1G1PP = OC1_PPS;
S2G1PP = OC2_PPS;
S3G1PP = OC3_PPS;

// Configure the OC
OC1CON1 = 0x0002;
OC2CON1 = 0x0002;
OC3CON1 = 0x0002;
// load value into the OC
OC1R = OneMs;
OC2R = OneMs + OneMs/2;
OC3R = 2*OneMs;
break;
case 1:
S1G1PP = NO_OC;
S2G1PP = NO_OC;
S3G1PP = NO_OC;

// configure the pin
// move OC to the servopp
S1G2PP = OC1_PPS;
S2G2PP = OC2_PPS;
S3G2PP = OC3_PPS;

// Configure the OC
OC1CON1 = 0x0002;
OC2CON1 = 0x0002;
OC3CON1 = 0x0002;
// load value into the OC
OC1R = OneMs;
OC2R = OneMs + OneMs/2;
OC3R = 2*OneMs;
break;
case 2:
S1G2PP = NO_OC;
S2G2PP = NO_OC;
S3G2PP = NO_OC;

// configure the pin
// move OC to the servopp
S1G3PP = OC1_PPS;
S2G3PP = OC2_PPS;
S3G3PP = OC3_PPS;

// Configure the OC
OC1CON1 = 0x0002;
OC2CON1 = 0x0002;
OC3CON1 = 0x0002;
// load value into the OC
OC1R = OneMs;
OC2R = OneMs + OneMs/2;
OC3R = 2*OneMs;
break;

default:
// remove the OC from last servo group to use it.
S1G3PP = NO_OC;
S2G3PP = NO_OC;
S3G3PP = NO_OC;
Disable2msTimer();

break;
}


clock2ms ++;
_T2IF = 0; // clear the interrupt flag
}

Step 2: Finaly Design


My final design has capabilites for both USB and also serial connections sofar i have been having issues with the USB part of it and have yet to do anything for the serial connection. so please this is where i definatly mean that you should double check the design. besides the usb and serial connection (havent tested serial) i have not had any issues with the design what so ever, have tested all 18 servo pins using a logic analyzer that can test 16 of my 18 pins simultaniously

Im pretty sure that the issue lies with the middle two pins for the usb connector are shifted 1 over from where they are supposed to be but i will let you make that call.

Im still working on the program for this and hoping to get this up and working here shortly.  hoping to be able to implement a system where my computer side program is able to send a new configuration method without having to reflash the chip.

Comments

author
AJMansfield (author)2013-05-30

Could you please upload corrected schematics and stuff once you work out the problem with the USB?

author
zaped212 (author)AJMansfield2013-05-30

Thank you for your interest in this project, unfortunately i have not worked on this project since i ran into the issue.

there are more efficient ways to accomplish the same task, this one is very pin hungry.

Eventually i will be redoing this project and doing pwm through shift registers on the spi line.

if you are interested in that, there is a library that i have used before called Shift PWM, its an arduino library but the concept is the same regardless of the system you are using.

Hope this helps.

author
mattthegamer463 (author)2011-07-02

Nice project, where did you get your board produced? How much did it cost?

author
zaped212 (author)mattthegamer4632011-07-03

I got my boards fabbed from seeedstudio
http://www.seeedstudio.com/depot/fusion-pcb-service-p-835.html?cPath=185
they are 5x10 cm boards, and i beleive it was around 25 for 10 boards. wich i think is pretty cheap, the only thing is since i had to get them sent internationaly it took some time to get the boards in. but otherwise

author
mattthegamer463 (author)zaped2122011-07-03

Very nice, thanks.

author
bernardroth (author)2011-06-28

What program do you use to compile your code?

author
zaped212 (author)bernardroth2011-06-29

Im using the new MPLAB X compiler from Microchip for the pic that im using. and just for reference, i did create a header file with some #defines so i could change some names around. so anywhere where there is a SxGx that name conventiion was one i am using on the project so it makes it easier to reference specific servo pins