In addition to generating the fuse, clock, RS-232, and #define command code, the PIC Wizard
will generate main C source code to initialize the target PIC’s peripheral set according to the
programmer’s configuration input:
#include “C:\servo-ccs-firgelli\firgelli-ccs.h”
#define ACT_DIR PIN_B0
#define ACT_PWM PIN_B1
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_OFF);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
}
All of the PIC18F2620 fuse, clock, RS-232, and #define command code gets stuffed into the
firgelli-ccs.h file. As you can see in the code snippet, I cut the #define commands out of the
firgelli-ccs.h file and pasted them into the main C source created by the PIC Wizard utility. Note that all of
the PIC18F2620 peripheral configuration code inside of the C main function is composed of CCS
compiler built-in functions. These functions eliminate searching through the PIC datasheet for each
peripheral’s SFR (Special Function Register) bit definitions. Another advantage of using the compiler’s
built-in functions is that you can read the function arguments and immediately know what is
enabled, disabled, on, and off.
We must take a peek at the LMD18200T H-bridge datasheet to understand how to write our
Firgelli linear actuator driver code. The LMD18200T is a 3A H-bridge that is specifically designed for
motion control applications. All of the necessary H-bridge safeguards are built into the LMD18200T
to prevent thermal or transient initiated
damage to the actuator motor. This H-bridge is an excellent robotic motion
part as it is inexpensive, available, and
rugged.
The LMD18200T’s DIRECTION input
determines which pair of OUTPUT
MOSFETs is active. The BRAKE input is
used to quickly stop a motor attached to
the LMD18200T H-bridge’s OUTPUT pins
by shorting like-powered MOSFETs in the
H-bridge. Our actuators won’t be
moving fast enough to need breaking.
So, we’ll tie the BREAK input to ground
which disables the LMD18200T’s
braking function. Normally, the H-bridge’s PWM input would be used to
control the speed of a motor being
driven by the LMD18200T. We’ll use the
PWM input as a power switch. When
the PWM pin is driven logically low, the
DIRECTION input logic level is ignored
and only the source MOSFETs attached
SCREENSHOT 2. The PIC Wizard allows the
programmer to associate all of the target PIC’s available
I/O with a logical name. If you choose to use the
Wizard to generate the #define commands instead of
manually coding them, the associations will be placed in
the #include file instead of your main C source file.
SERVO 08.2010 71