down for us on the demonstration board. So, let’s build up
our A3959 controller.
PICing an A3959 Motor Driver
Controller
I’ve chosen the PIC18F4620 to perform the A3959
controller duty. If you’ve ever designed with a PIC microcontroller, there’s nothing new for you here. In fact, the PIC
controller hardware is so easy, I could simply tell you to look
the circuit over in Schematic 1 and be done with it. As you
can see in Photo 3, the PIC hardware is so simple, I
hand-wired the PIC A3959 controller circuit on a perfboard.
I elected to leave the SLEEP pin alone and tie it to an
inactive state. I also chose to use the lesser PWM Blank
time ( 6 / fOSC ) by tying the BLANK pin to ground.
There are plenty of I/O pins to spare. So, if you want to
experiment with the control lines I’ve chosen to logically tie
to a static state, don’t be afraid to hook up the SLEEP and
BLANK control lines to the PIC. If you use my existing
control line code as an example, you won’t have any
problems coding in the extra control lines.
The real work involved with building up an A3959
motor driver controller is in the firmware. With that, let’s
begin our firmware build by associating the A3959 control
pins with their PIC18F4620 counterparts:
//*******************************************************
//* A3959 PIN DEFINITIONS
//*******************************************************
#define PFD1 LATB0
#define PFD2 LATB1
#define ENABLE LATB2
#define PHASE LATB3
#define MODE LATB4
PHOTO 3. It doesn’t get
much better than this.
I’ve taken to powering
small PIC projects like
this from a PC USB port.
48 SERVO 07.2008
The names I’ve assigned to the PIC18F4620 PORTB I/O
pins should be very familiar to you. It would be nice if we
reduced the complexity of the PFDx selections, as well:
#define decay_slow
PFD1 = 0;
PFD2 = 0;
PFD1 = 1;
PFD2 = 0;
PFD1 = 0;
PFD2 = 1;
PFD1 = 1;
PFD2 = 1;
\
#define decay_mixed_15
\
#define decay_mixed_48
\
#define decay_fast
\
Using C macros to put human-readable names on the
PFDx selections will make life a bit easier if you want to
experiment with the PDFx settings. The same holds true for
the EXT MODE selections as well:
#define ext_mode_fast
#define ext_mode_slow
MODE = 0
MODE = 1
The reason we are here is to turn the BDPG-60-110
motor shaft. So, it would be fitting to put together some
motion macros:
#define CW
#define CCW
#define motion_CW
#define motion_CCW
#define motion_HALT
1
0
ENABLE = 1; \
PHASE = CW;
ENABLE = 1; \
PHASE = CCW;
ENABLE = 0;
Note the use of the A3959 ENABLE pin to start and stop
the BDPG-60-110-24V-3000-R326. When you run your motor,
remember that clockwise and counter-clockwise rotation is
determined depending on how you attached the motor leads
to the A3959 OUTx pins. These CW and CCW settings worked
for me. The PHASE logic swaps the polarity of the OUTx pins.
If your CW and CCW directions are opposite of mine
here, it’s much easier to simply swap the motor leads than
recompile and reload the PIC18F4620.
With all of our A3959-to-PIC18F4620 definitions and
associations complete, we can add this bit of code at the
end of our initialization routine:
//*******************************************************
//* INITIALIZE A3959 MOTOR DRIVER HARDWARE
//*******************************************************
decay_mixed_15; // PFD1 = 1 - PFD2 = 0
ext_mode_fast; // MODE = 0
motion_HALT; // ENABLE = 0
I promised that we would also write some PIC firmware
that would allow us to control the BDPG-60-110 through
the A3959 controller’s serial port. I have coded up all of the
necessary EUSART firmware for the PIC18F4620. You can
see what I’ve done with the PIC18F4620’s EUSART by
downloading the A3959 driver firmware from the SERVO