website at www.servomagazine.com. Here’s the code
that will put the menu up in a terminal emulator window:
void show_menu(void)
{
cls();
cls();
printf(“%c[2;4H SERVO A3959 MOTOR CONTROL
MENU”,esc);
printf(“%c[5;7H F - ROTATE CW”,esc);
printf(“%c[6;7H R - ROTATE CCW”,esc);
printf(“%c[7;7H S - STOP”,esc);
}
Entering an F, an R, or an S invokes the main routine code,
which is looping continuously:
//*******************************************************
//* MAIN SERVICE LOOP
//*******************************************************
show_menu();
do{
if(CharInQueue())
{
bytein = recvchar();
switch(toupper(bytein))
{
case ‘F’:
motion_HALT;
mdelay1(100);
motion_CW;
break;
case ‘R’:
motion_HALT;
mdelay1(100);
motion_CCW;
break;
case ‘S’:
motion_HALT;
break;
}
}
}while(1);
The CharInQueue() function informs the main routine
that a character is waiting in the EUSART’s external buffer.
When a character arrives from the personal computer, we
retrieve it from the external buffer and parse it. If the
character is an F, we stop the BDPG-60-110-24V-3000-R326,
wait for 100 ms and rotate the BDPG-60-110’s shaft in the
clockwise direction. An incoming “R” stops the motor, waits
for 100 ms, and forces the BDPG-60-110’s motor shaft to
rotate in the counterclockwise direction. To stop the motor
shaft, we simply drop the ENABLE line to a logical low.
That’s all there is to it!
Spinning Out
My version of the A3959 motor controller is shown
attached to its demonstration board in Photo 4. When
you’re ready to put the A3959 to work in a real-world
PHOTO 4. You’ll want to build up an A3959 motor driver board
without the socket if you plan to run a motor for an extended
length of time. It is important to make sure that the A3959
heatsink tabs are soldered to the copper heatsink area.
SOURCES
Allegro MicroSystems — www.allegromicro.com
A3959
A3959 Demonstration Board
Microchip — www.microchip.com
PIC18F4620
HI-TECH Software — www.htsoft.com
HI-TECH PICC- 18 C Compiler
Anaheim Automation — www.anaheimautomation.com
BDPG-60-110-24V-3000-R326
motor driver application, be sure to solder the A3959 directly
to the PCB. The A3959 tabs need to be soldered to a
copper heatsink area provided on the PCB. Give the
heatsink area as much of the PCB’s copper as you can.
The download package firmware was written using the
HI-TECH PICC- 18 C compiler and contains lots of goodies
you can use in other projects, such as timer manipulation
routines, timer interrupt handlers, serial communication
routines, and serial communications interrupt handlers. The
A3959 is a really robust and easy to use part. I have no
doubt you’ll have your aluminum human doing some heavy
lifting in no time flat. See you next time! SV
Fred Eady can be reached via email at fred@edtp.com.
SERVO 07.2008 49