PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 16, 2009 2:21 pm |
|
|
I believe the LMD18200 is the modern name for the LM18200 H-Bridge
controller.
Here is a project that we did (for fun), using the LMD18200 and a
Sparkfun UAV IMU board (vs. 1a). http://www.sparkfun.com/datasheets/GPS/EvalBoards/GPS%20UAV%20Manual%20Part1.pdf
Connections between the 18F2520 and the LMD18200 are:
Code: |
PIC pin LMD18200 pin
13 - RC2 - CCP1 3 - Direction
12 - RC1 - CCP2 5 - PWM
|
On the LMD18200 board, there are 10K pull-down resistors on
pins 3 and 5. This holds the LMD18200 in a safe state (i.e., motor does
not move) if the cable between the PIC and the motor board is removed.
The Brake pin on the LMD18200 is connected to ground. The other
connections to the LMD18200 are (I believe) according to the data sheet,
in the Locked Anti-Phase schematic section.
LMD18200 data sheet:
http://www.national.com/ds/LM/LMD18200.pdf
In the following program, CCP1 provides the PWM signal to the Direction
pin of the LMD18200. The CCP2 pin is connected to the PWM pin of the
LMD18200. It's used as an ordinary i/o pin, and it's set to a high level,
per the LMD18200 data sheet, in the section on "Locked Anti-Phase".
In the program below, you can press 'F' to turn the motor in the Forward
direction. Press it more times to go faster. Press 'S' to stop. Press 'R'
to go in reverse. Press 'R' more times to go faster in Reverse.
Code: |
#include <18F2520.h>
#device adc=10
#fuses H4, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=40000000)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4, INVERT, stream=PC)
// #use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, stream=GPS)
#define DIRECTION_PIN PIN_C2 // CCP1
#define PWM_PIN PIN_C1 // CCP2
//===========================
void main()
{
char c;
int8 pwm_duty;
// Setup to drive the LMD18200 in locked anti-phase mode.
// This is done by holding the PWM pin high, and then
// sending PWM signals to the Direction pin.
output_high(PWM_PIN);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_4, 255, 1);
pwm_duty = 128; // Init pwm duty cycle to 50%
set_pwm1_duty(pwm_duty);
while(1)
{
c = toupper(getc(PC)); // Wait for input
if(c == 'F')
{
if(pwm_duty < 255)
{
pwm_duty++;
set_pwm1_duty(pwm_duty);
}
}
if(c == 'R')
{
if(pwm_duty > 0)
{
pwm_duty--;
set_pwm1_duty(pwm_duty);
}
}
if(c == 'S')
{
pwm_duty = 128;
set_pwm1_duty(pwm_duty);
}
}
} |
|
|