Servo Control

In my first lab we were getting a feel for the dsPIC30F4011 micro controller which we haven’t used before, we have used the MSP430 chip before and they work fairly similarly, just need to learn the names of the functions like P1DIR is like TRISD in the PIC. The way we’re doing this is by writing a code to control a servo, we’ll be controlling the servo using the bit banging method which is switching an output on and off creating certain length pulses. Using the pulse width modulation in the chip would be better but doing bit banging will help use get used to the __delay32.

We start with a code given to us by our lecturer which would switch from 0 degrees to 180 degrees but when I tested it, it didn’t look like it was going the full 180 degrees so I decided to change the pulse on top and bottom of the range to find the real values for 0 and 180 degrees. The datasheet suggests the values around 1ms to 2ms for the full range but from trial and error I found to get the full range of angles, the pulse range is 0.7ms to 2.2ms. The circuit and the final code for switching between 0 and 180 degrees is below, the code was edited from here. Continue reading