CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using the built in PWM functions for PIC18F1330 with LM18200

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dk-info



Joined: 13 Apr 2009
Posts: 5
Location: Melbourne, Florida

View user's profile Send private message Send e-mail

Using the built in PWM functions for PIC18F1330 with LM18200
PostPosted: Fri Oct 16, 2009 12:31 pm     Reply with quote

I am new to PWM, I built a circuit that controls a pump motor using a LM18200 H-Bridge IC.
The LM18200 is connected as follows:
    Direction input: (RB2 - pin 17)
    PWM input (RB0 - PWM0 - Pin 8)
    Brake input (RB1 - Pin 9).

Using a signal generator with PWM output I am able to control the LM18200 just fine, so I believe in the circuit wiring.

So, turning to the IDE version 4.076, I tried to use the wizard to enable PWM code with no results. I cannot access the PWM selection in the CCP setup dialog.

Doing it manually, I used the example code (EX_PWM.C). It shows how to use the PWM functions, the only problem is the PIC18F1330 does not have a timer 2, and when I try to use the built-in functions setup_ccp1(CCP_PWM), I get an error 12 from the compiler. if I try to use the built in function set_pwm1_duty() I also get a compiler error 12.

This chip is supposed to be "the motor control" chip, and the chip info in the IDE indicates that it knows this chip has built in PWM features, but I cant seem to access them using the built in functions.

So, long story short, How do I set up my PIC18F1330 with the following parameters?

    internal 8 mHz clock
    using PWM0 (pin 8)
    2 kHz frequency
    variable duty cycle from 5% to 95%

I would appreciate any help with this, even if it is an admonishment to "RTFM", as long as the requisite "FM" is listed.

David
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 16, 2009 2:21 pm     Reply with quote

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); 
     }

  }

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group