//*******************************************************
//* DETERMINE SERVO ROTOR DIRECTION
//*******************************************************
always @(posedge clk_1mhz)
if(window_32ms == 0)
case(btn_input)
2’b01: servo_vector <= servo_vector + 1;
2’b10: servo_vector <= servo_vector - 1;
2’b11: servo_vector <= 500;
endcase
endmodule
The only thing I really need to explain is the Verilog
case structure. Otherwise, the Verilog case block works just
like the C case block. All of the possible btn_input input
logic levels are represented except 2’b00, whose omission
brands it as a “don’t care” or “do nothing” logic level. The
“2’b” in each case choice represents the number of binary
bits in the case comparison argument. The stated number
of binary bits follows. In our application, each bit in the
case comparison arguments represents a particular input
pin. The logic we have implemented stops the servo rotor
when both btn_input pins are logically low. The servo rotor
is centered when both btn_input pins are logically high.
If you’re wondering how we know which btn_input pin
is associated with which bit, the ISE WebPACK generates a
pin list report like the one you see in Screenshot 3 with
The CPLD Servo Driver
every successful CPLD or FPGA design implementation pass.
The most significant bit of our register and wire bit range
patterns is represented by the left-most bit in the range
declaration ([most significant bit:least significant bit]). Now
you can see how the order of the btn_input bit range declaration pattern ([1:0]) relates to the Verilog case comparison
arguments (2’b01, 2’b10, etc.) and to the XC2C64A I/O pins.
Rotating Out
Driving hobby servos is only one of the tricks a CPLD
can perform. In addition to turning servo rotors, you can
use a CPLD to expand the I/O capability of your host
microcontroller. You can also use a CPLD to replace a
number of discreet logic ICs in your next robotic design.
If you see CPLD logic in your robotic future, I’ve provided
all of the source code we generated in this discussion as a
download package from the SERVO website ( www.servomag
azine.com). You can get the hardware scoop on the XC2C64A
development board as a download package from the Nuts &
Volts website ( www.nutsvolts.com). CPLDs are easy to understand and easy to design into your projects. So, gather up a
couple of hobby servos, build up the XC2C64A Development
Board, and drive some servos with a CPLD yourself. SV
Fred Eady can be reached via email at fred@edtp.com.
HE8EJI FH;<;H >?J; 9 )0'
.EW 2OBOT 3ERVOS
>_j[Y
Ej^[h 8hWdZ
+ 65 6* + 65 6* + 65 7*
6SHHG VHF 6SHHG VHF 6SHHG VHF
7RUTXH R] LQ 7RUTXH R] LQ 7RUTXH R] LQ
6WHHO *HDUV 6WHHO *HDUV 7LWDQLXP
$// 63(&,),&$7,216 $7 92/76
7KH UHVXOWV RI DQ LQIRUPDO SROO WDNHQ UHFHQWO\ DW WKH )LUVW
$QQXDO :RUOG 'RPLQDWLRQ 6\PSRVLXP DUH QRZ LQ 5RERWV
SUHIHU +LWHF VHUYRV RYHU RWKHU VHUYR EUDQGV 7KH\ NQRZ WKH ZLGH
VHOHFWLRQ RI +LWHF DQDORJ DQG GLJLWDO VHUYRV SURYLGH WKHP ZLWK WKH SRZHU DQG GHSHQG
DELOLW\ QHHGHG WR HYHQWXDOO\ WDNH RYHU WKH :RUOG 0DNH \RXU URERW KDSS\ XVH +LWHF VHUYRV
3DLQH 6WUHHW _ 3RZD\ _ &DOLIRUQLD _ _ _ ZZZ KLWHFUFG FRP
SERVO 08.2008 43