Logo Dspic-Servo Project


Project Description

This project was developed as an inexpensive way to drive small dc brushed motors as positioning servos for use on a desktop sized CNC machine. The board is interfaced to the PC through 2 pins of a parallel port. The drive signal on these pins is known as quadrature drive. The power stage consists of a power op amp driven in constant current mode. The internal PIC processor ( a 30f4012 from Microchip ) is programmed in C through the C30 compiler and the Microchip IDE. The servo loop parameters are programmed through a serial port connection and are saved in the dspic eeprom. Once set for a particular drive, they should not need to be changed.
A YouTube video by Ted Maczulat.

The serial programming interface is used to tune the PID and other servo loop parameters to optimize the performance in a particular application. The serial port runs at a fixed baud rate of 9600N81. Any terminal program such as minicom, gtkterm, or hyperterminal may be used to talk to the dspic-servo. On powerup you will see the following:


dspic-servo by L. Glaister
(c)25-Sept-2006 by VE7IT

using setup from eeprom.. ? for help

Current Settings:
servo enabled = 1
(p) = 0.020000
(i) = 0.000000
(d) = 0.000050
FF(0) = 0.000000
FF(1) = 0.000000
dead(b)and = 1.000000
(m)ax output = 2.500000
(f)ault error = 1024.000000
(x)pc cmd multiplier = 3
(t)icks per servo cycle= 10

To change a value, type the cmd letter/number and then a value for example:
The current values will be redisplayed with the new value set. The p,i,d, ff0 and ff1 values are standard loop gain parameters. You can reference the source code for a better explanation. The deadband parameter is the number of encoder counts the servo can be out of position without the servo loop taking any corrective action. The max output is the maximum current output allowed in amps and should be set for the particular motor you are using. This number can be up to 7 amps. The fault error parameter is used to set the number of counts the servo can be out of position before the drive gives up and indicates a drive fault. This is used to detect crashes and jammed axis or input command conditions beyound the capabilities of the motor. The pc command multiplier is useful for cases where you have a high resolution encoder on the motor and a PC that is limited in the number of pulses/second it can output. For most operation this number will be set to 1, but if you have trouble reaching the top speed you need from the drive, it may be helpful to set this number to a higher value. The internal servo loop works by keeping 2 counters. The first is the commanded position from the PC, the second is the actual position from the encoder. The servo loop of the drive attempts to keep these 2 numbers as close as possible to each other. The ticks per servo cycle gives a way to set how often the pid calculation cycle is run. The number is the count of how many times the internal 100us interrupt fires between requesting the servo calculations. This can be set as low as 2 (200us or 5khz servo rate) to as high as 100 (0.01sec or 100hz servo rate). After this number is changed, you must power down the servo card and restart it to make the rate change. With the motors I am using, I found no advantage to slower or faster rates than the standard value of 10 ( 1khz rate ).

System Requirements

You will need a programmer for the dspic processor, the Microchip IDE evironment and the C30 compiler (demo version OK) from Microchip. Although the design uses a combination of surface mount and through hole components, the larger 1206 size surface mount components are easy to work with without special equipment. The single sided circuit board can be etched or if you have a milling machine, these boards can be milled using the pcb-gcode.ulp program available for the eagle pcb software.

Electrical Drawing(s)

Schematic Drawing - dspic-servo-schematic.png(69K)
PCB Xray View - dspic-servo-layout.png(31K)
Eagle PCB file - dspic-servo-2.sch(245K)
Eagle PCB file - dspic-servo-2.brd(28K)

Source Code

C30 Project - dspic-servo-25sep-2006.zip(92K)
C30 Project - (revised) dspic-servo-29jan2008.zip(108.9K)
Hex file for above version using 6Mhz crystal - dspic-servo-29jan2008-6MHz.hex(93K)
EMC bottom drill file - dspic-servo-2bd.ngc(8k)
EMC bottom mill file - dspic-servo-2bot.ngc(126k)


Newer versions of MPLAB have caused a few issues. I have built both versions of software listed above using mplab after performing the following steps:

home.jpg Back to Lawrence's Software Stuff Page