the 1023 mark. The 135° position begins
at the second 723 marker with the 0° position being marked as named. Sinetable2
begins 90° out-of-phase with sinetable1
with the first 723 value representing 135°.
As with sinetable1, the 0° position
is marked by a zero value in the table.
The second 723 value in sinetable2 is
the 45° position, which is followed by
the 90° position at the 1023 marker.
The sinetable1 and sinetable2 values
are continually rotated through from
beginning to end with a pair of clock
pulses occurring at every eighth and
ninth, 16th and 17th, 24th and 25th,
and 31st and 32nd value in the table.
Or, simply put, every 90°.
The majority of the L6208PD stepper motor driver code is simple on-off
I/O code. The PWM duty cycle loader
code is the most busy. Once the PWMs
are initialized, the 10-bit sinetable values
are parsed with the two least significant
bits being placed in the respective
CCPxCON register (CCP1CON or
CCP2CON) and the eight most signifi-
cant bits being routed to their respective
duty cycle register (CCPR1L or CCRR2L):
pwm_lsbs = (sinetable1[sinetable_
index] & 0x0003) << 4;
CCP2CON &= 0b11001111;
CCP2CON |= pwm_lsbs;
CCPR2L = sinetable1[sinetable_index]
pwm_lsbs = (sinetable2[sinetable_
index] & 0x0003) << 4;
CCP1CON &= 0b11001111;
CCP1CON |= pwm_lsbs;
CCPR1L = sinetable2[sinetable_index]
The PIC18F2620 holds the least significant bits of the PWM duty cycle value
in bits 4 and 5 of the CCPxCON register.
The remaining eight bits are placed into
the CCPRxL duty cycle registers.
You now have all of the hardware
information you need (within the extents
of this article) to build up your own version of the L6208PD Motor Driver Board
I’ve presented. What you don’t have is a
complete set of the HI-TECH C-based
L6208PD stepper motor driver source
code. I’ll provide the C source to you via
a download from the SERVO website
( www.servomagazine.com). I’ll also
post the ExpressPCB file and the Excel
sine table spreadsheet for your access.
And, by the way, you can completely assemble your L6208PD Motor Driver
Board and still play with the PIC and the
PWM stuff. Just set the L6208PD ENABLE
pin to zero in your initialization code.
That will disable the L6208PD internal H-bridges so you can do your thing with the
motor control and PWM signals without
worrying about doing something bad to
your L6208PD. See you next time! SV
Contact the Author
Fred Eady can be reached via email
Let new ideas spring forth!
All modules shown actual size
TReX dual motor controller:
innovative design allows instant TReX Jr $59.95
switching between radio control
(RC) or analog voltage and
(RS-232or TTL) with
a multitude of
TReX dual motor
Orangutan LV-168: full-featured
robot controller perfect for low-voltage
robots.ATmega168 uC, 2-channel H-
TReX Jr: all the great features
ofthefull TReXinalower-power, lower-costpackage.
Orangutan LV-168 $59.95
Find out more at www.pololu.com or by calling 1-877-7-POLOLU.
SERVO 03.2008 57