Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Bidirectional DC motor control with PWM controlable speed using PIC microcontroller

Status
Not open for further replies.

Cantafford

Member
Hello everybody and happy new year!

I'm trying to make a simple project in which I control the direction of a DC motor with a L293D driver and it's speed in ratios of 25%, 50%, 75% and 100% of full speed. Therefore I suppose I need to use 2 PWM's from the PIC(CCP module). The PIC I'm using is PIC18F2620. Datasheet here: https://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf
I have chosen a frequency of 1.5 Khz for the PWM signal.

This is my schematic:
m8nwya.png


The truth table for the L293D motor driver is this:
dg5ono.jpg


I've never used 2 CCPs before but from what I understood from the datasheet of my PIC, to use one PWM module I have to make it as output. Not sure if this is the right way to do it .So my logic was, configure the duty cycle and period and then make the CCP module that I want to use as output. For example: If I want CCW direction, make CCP1 pin(RC2) as output and hold CCP2 pin(RC1) as input. Sorry if the explanation is ambiguous.
 
Last edited:
you are using ccp1con for both CW and CCW. also I would just put the non-changing reg's before the main code so I'm not spending time changing them everytime to the same thing, it also makes debugging abit easier... (put PR2 and TIMER2 in the same place as your TRIS and OSCCON)
 
Last edited:
I vaguely recall using that driver. Just one pin high / low changed direction and, IIRC, another one provided a PWM but not sure really. If true, you would need just one PWM signal, common for both cases.
 
you are using ccp1con for both CW and CCW. also I would just put the non-changing reg's before the main code so I'm not spending time changing them everytime to the same thing, it also makes debugging abit easier... (put PR2 and TIMER2 in the same place as your TRIS and OSCCON)
Yes you are right about the PR2 and TIMER2 things I will put them where you said after I get it to work for now I keep it like this so I can see easier all operations I do to configure a PWM signal.

I have modified CCP1CON and CCPR1L for CW and CCP2CON and CCPR2L for CCW but I have the same problem. There is no PWM on my two pins, they are always in high impedance mode therefore the motor does not rotate in any way :(
 
Last edited:
leave your TRISCbits as an output. change the ccpr1l/h and ccpr2l/h as needed for on/off. I would just run the program full on full off until you get them to operate correctly, then play w/ the speeds.
 
I did leave TRISC as output but no matter what combination of CCPR1l and CCPRL2 I do only CCP1 pwm works. I can't get CCP2 to work it stays in 0 all the time.
Also another wierd problem: When I make the TRISC as output even if I don't configure the motor will start rotating in the CCW direction.
 
I don't see any caps shown on your schmatic???? I would try to run the motor w/o the ccpcon's, just set LATCbits for each direction first, also after the "void main" area I always add a while(1){.......} around the code that I want to run,
like this..............


int main()
{
OSCCON = 0x76; // set internal oscillator to 8Mhz
TRISA = 0b11111111; // buttons are here
TRISB = 0b00000000; // indicator leds are here

while(1)
{
all your code
}
} // end of int main()

I don't know if it makes a differance? but that's how I code.
 
The problem was that I was driving the PWM signal on the input pin of the L293D bridge. The PWM should be driven on the enable pin. Nice dog btw ;)
 
Status
Not open for further replies.

Latest threads

Back
Top