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

Simple DC Motor Control with PIC18f4550

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



Joined: 04 Feb 2012
Posts: 20

View user's profile Send private message

Simple DC Motor Control with PIC18f4550
PostPosted: Mon Feb 06, 2012 8:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 06, 2012 8:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 06, 2012 9:16 am     Reply with quote

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: 19498

View user's profile Send private message

PostPosted: Mon Feb 06, 2012 10:14 am     Reply with quote

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
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