The CPLD Servo Driver
SCREENSHOT 1. This pulse width
is right on the money. Upon
sensing this signal, the rotor of
my JR Sport SM8 hobby servo
snapped to the central position.
similar to a while(1) C loop that runs continuously. Verilog
always blocks run freely and are triggered every time the
condition in the always block sensitivity list is met. In the
rcservo module we’ve just coded, the Verilog always block’s
sensitivity list contains a trigger for every positive edge
(posedge) of the incoming 1 MHz clock signal (clk_1mhz).
That equates to the always block’s code between the
Verilog begin and end block delimiters executing every
microsecond.
The “<=” Verilog operator in our always loop code tells
us that the logic associated with this operator is clocked,
which means all of the statements using a “<=” operator
are termed “unblocked” and execute in parallel. If you’re
having trouble with this concept, think of a bunch of D
flip-flops with all of their clock lines tied to the same clock
source. When clocked, every D flip-flop will switch its D
input to the Q output simultaneously. So, everything to the right
of the “<=” operator will execute
and the results will end up to
the left of the “<=” operator
beginning with every positive
edge of the 1 MHz clock. The
window_32ms <= window_32ms
+ 1; Verilog statement is very
easy to understand as every
microsecond we are incrementing
the count that is being held
within the 15-bit window_32ms
register.
The pwm_out <=
(window_32ms < (servo_vector + minpulsewidth)); Verilog
statement takes a bit more thought. Associate logically high
with Boolean TRUE and logically low with Boolean FALSE as
you sound it out:
The pwm_out output pin is logically high as long
as the window_32ms register count is less than the
servo_vector value plus the minimum servo position
pulse width value.
We know that we want to generate a 1.5 ms servo
position pulse with our rcservo Verilog module. So, let’s
sound out the pwm_out <= (window_32ms < (servo_vector
+ minpulsewidth)); Verilog statement again, but this time
we’ll sound it out mathematically:
When the window_32ms
register value is less than
1500 decimal, the pwm_out
pin is logically high. When
the window_32ms register
value is greater than 1500
decimal, the pwm_out
pin is logically low. The
window_32ms versus servo
position value comparison is
made at every rising edge of
SCREENSHOT 2. My JR Sport SM8
hobby servo didn’t chatter while
under the control of this 32.768
ms servo control pulse window
timing. The 4. 8 volt SM8 ran well
using the XC2C64A’s 3. 3 volt I/O
supply voltage. However, I’m sure
you’ll get the most out of the SM8
with a + 5.0 volt servo supply.
Note the rising-edge-to-rising-edge timing in this shot.
40 SERVO 08.2008