the double-tap clock signals later on.
Let’s generate a sine table that
represents a full step of 90° as 16
microsteps. Screenshot 5 is a view of
an Excel spreadsheet that I whipped up
to do the sine-to-PWM value conversions. The Excel sine-to-PWM duty cycle
formula for an eight-bit PWM unit is:
PWM Duty Cycle Value =
where ACELL_VALUE is the value of the
DEGREES PER STEP cell in column A;
255 is the eight-bit sine table multiplier.
Excel uses RADIANS instead of
DEGREES in its sine calculations. The
RADIANS statement in the Excel
formula converts the RADIANS value to
DEGREES in the computation. Since we
are computing the PWM duty cycle
value for an eight-bit PWM subsystem,
we use eight bits (0xFF or 255) as our
sine table multiplier. The PIC18F2620
contains a 10-bit PWM subsystem,
which allows us to use a 10-bit sine table
multiplier of 1023 (0x3FF). The results of
the 10-bit PWM duty cycle calculations
are also shown in Screenshot 5.
Allow me to illustrate why we only
need to compute and load the 16 PWM
duty cycle values. The L6208PD will
settle into a home position of 45° following power-up or a PIC18F2620 initiated reset operation. This 45° position
is not a physical location of the stepper
motor’s rotor shaft. It is a full step position state reflected in the L6208PD’s
step generator and phase generator.
If you pull out your scientific calculator and take the sine and cosine of
45°, you will find that the result for both
is 0.707 and some change. In stepper
motor land, that means that the current
though the coils — which are, in this
case, aligned to a full step home position — is equal. The L6208PD’s internal
phase generator is also sitting at its
home position along with the L6208PD
step generator. At this point, the PWM
duty cycle value associated with the 45°
state has been loaded into the
PIC18F2620’s CCPR1L and CCPR2L duty
cycle registers by our firmware.
Let’s start our sine and cosine
cycles by moving through the 16 sine
entries. Remember, a cosine wave is
SCREENSHOT 5. This is all we need to generate sine and cosine functions for our L6208PD.
All we really care about is putting together 90° phase transitions with the PWM. The
L6208PD’s built-in phase generator takes care of the motor state transitions for us.
90° out of phase with a sine wave. We
will move one of our PWM duty cycle
registers from 45° to 90° and then back
through 45° to 0° and up again to 45°.
Simultaneously, we will move the
other PWM duty cycle register from
45° to 0° and then back up through
45° to 90° and down again to 45°. If
you were to graph this out by hand,
you would come up with something
similar to the CleverScope capture I’ve
snared in Screenshot 6.
By simply rotating through the PWM
duty cycle sine table values with a 90°
phase difference, we can use a pair of
PIC18F2620 PWM outputs to generate
the necessary sine and cosine waveforms
we will need to microstep our Minebea
stepper motor using the L6208PD
mounted on our Motor Driver Board.
I switched the CleverScope scope
probe off of the second PWM and onto
the L6208PD CLOCK pin. To properly
microstep with the L6208PD, we must
generate a clock pulse on every required
phase reversal. In other words, a clock
pulse must be generated every time we
cross a 90° boundary in the sine table.
SCREENSHOT 6. This is how the CleverScope saw my PWM-generated sine and cosine
signals. Note that you can make out the PWM “steps” inside of the sine and cosine
waveforms. There are 16 PWM steps for each 90° phase.
SERVO 03.2008 55