View previous topic :: View next topic |
Author |
Message |
Jent
Joined: 04 Feb 2012 Posts: 20
|
Simple DC Motor Control with PIC18f4550 |
Posted: Mon Feb 06, 2012 8:18 am |
|
|
Hi... Before this, I had tested the LCD 16x2 and it can be done successfully with the experts' helps from here. Thanks a lot.
Now, I'm testing the dc motor with PIC18f4550 with the coding below with ccs c compiler.
Code: |
#include <18F4550.h>
#fuses NOLVP, NOWDT, HS, NOPBADEN
#use delay(clock=20M, crystal)
#define L293D_2 PIN_B3
#define L293D_7 PIN_B4
#define L293D_10 PIN_B1
#define L293D_15 PIN_B2
//function Prototypes//
void r_forward(void); //Forward run funtion
void r_backward(void); //Backward run function
void breaks(void); //Motors stop function
void main ()
{
setup_adc_ports(NO_ANALOGS);
set_tris_b(0x00);
output_b(0x00);
delay_ms(50);
while(true)
{ r_forward(); //Run forward
delay_ms(5000);
breaks(); //Motors Stopped
delay_ms(3000);
r_backward(); //Run backward
delay_ms(5000);
breaks();
delay_ms(3000);
}
}
void r_forward(void)
{
output_high(L293D_2); //L293D input1 set as 1//
output_low(L293D_7); //L293D input2 set as 0//
output_high(L293D_10); //L293D input3 set as 1//
output_low(L293D_15); //L293D input1 set as 0//
)
void r_backward(void)
{
output_high(L293D_7); //L293D input2 set as 1//
output_low(L293D_2); //L293D input1 set as 0//
output_high(L293D_15); //L293D input4 set as 1//
output_low(L293D_10); //L293D input3 set as 0//
}
void breaks(void)
{
output_low(L293D_7); //L293D input2 set as 0//
output_low(L293D_2); //L293D input1 set as 0//
output_low(L293D_15); //L293D input4 set as 0//
output_low(L293D_10); //L293D input3 set as 0//
}
|
However, I am facing errors.----> A numeric expression must appear here----> void r_forward(void), void r_backward(void) and void breaks(void)
I don't know what's that means? Can any experts help me? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Mon Feb 06, 2012 8:29 am |
|
|
I think it may be expecting a value after 'crystal' in #use delay(). If your crystal is 20MHz then all you need is #use delay(clock = 20MHz) with the fuses you've set.
RF Developer |
|
|
Jent
Joined: 04 Feb 2012 Posts: 20
|
|
Posted: Mon Feb 06, 2012 9:16 am |
|
|
I changed a bit the coding into the void main(), it can be compiled. Motor can run too. But two motors can't run simultaneously.
I've checked the output voltage in output of L293D, i supply to DC motor is 12V, but obtaining 10V something for runs forward for first motor, 4V something for backward. Second motor obtaining 10V something for runs forward, but 5V something for runs backward.
Any way to get the two motors run forward and backward simultaneously? And why I just got 10volt something but supplying with 12V? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Feb 06, 2012 10:14 am |
|
|
Without seeing the hardware drawings, impossible to answer.
Obvious things:
1) You have got Vss connected to 5v, and Vs connected to 12v?.
2) You have got enough capacitance on the 12v rail to prevent this rising unacceptably when you switch the motors off?.
3) You have got the enable pins pulled to 5v?.
4) You are sure your 12v supply can drive two motors?.
5) How is the PIC 5v generated?. You have got good HF smoothing close to the PIC?.
etc. etc...
Best Wishes |
|
|
|