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 support@ccsinfo.com

DC motors with L293D not running..

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



Joined: 14 Oct 2010
Posts: 14

View user's profile Send private message

DC motors with L293D not running..
PostPosted: Sun Jan 09, 2011 3:18 pm     Reply with quote

Hi all, what could make this code from not running properly??

H bridge: L293D
2 DC motors connected to each side of L293D.

It waits for corresponding character from VB app before taking the action.

Code:
#include "C:\Documents and Settings\Talha\My Documents\codes_CCS\VB_DC motor all directions\vb_motor_all directns.h"



#define LEFT_CONTROL_2A  PIN_C0  //2A of L293D
#define LEFT_CONTROL_1A  PIN_C1  //1A
#define LEFT_MOTOR       PIN_C2  //1,2EN
#define LED PIN_D1
#define RIGHT_MOTOR      PIN_D4  //3,4EN
#define RIGHT_CONTROL_4A PIN_D5  //4A
#define RIGHT_CONTROL_3A PIN_D6 //3A

void backward()
{         output_low(LEFT_CONTROL_1A);
          output_high(LEFT_CONTROL_2A);
          output_low(RIGHT_CONTROL_3A);
          output_high(RIGHT_CONTROL_4A);
          output_high(LEFT_MOTOR);
          output_high(RIGHT_MOTOR);
           
         
          }
void forward()
{         output_high(LEFT_CONTROL_1A);
          output_low(LEFT_CONTROL_2A);
          output_high(RIGHT_CONTROL_3A);
          output_low(RIGHT_CONTROL_4A);
          output_high(LEFT_MOTOR);
          output_high(RIGHT_MOTOR);
           
         
          }
void left()
{
          output_high(LEFT_CONTROL_1A);
          output_low(LEFT_CONTROL_2A);
          output_high(RIGHT_CONTROL_4A);
          output_low(RIGHT_CONTROL_3A);
          output_high(LEFT_MOTOR);
          output_high(RIGHT_MOTOR);
         
         
          }
void right()
{
          output_low(LEFT_CONTROL_1A);
          output_high(LEFT_CONTROL_2A);
          output_high(RIGHT_CONTROL_3A);
          output_low(RIGHT_CONTROL_4A);
          output_high(LEFT_MOTOR);
          output_high(RIGHT_MOTOR);
         
          }
void reset()
{
          output_low(LED);
          output_low(LEFT_CONTROL_1A);
          output_low(LEFT_CONTROL_2A);
          output_low(RIGHT_CONTROL_4A);
          output_low(RIGHT_CONTROL_3A);
          output_low(LEFT_MOTOR);
          output_low(RIGHT_MOTOR);
          delay_ms(100);
          }

         
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   char cmd;


do{
  if(kbhit())
{    cmd=getch();
output_high(LED);
   
      switch (cmd)
      {
 case '0': //backward
 printf("backward");
           reset();
           backward();
                     
                         
               
            break;
           
 case '1': //forward
 printf("forward");
 reset();
             forward();
         
           
           break;

case '2': //left
 printf("left");
reset();
            left();
             
           break;
case '3': //right
 printf("right");
reset();
         right();
             
           
           break;
case '4': //stop
 printf("stop");
         reset();


    break;
   
 
         }
         
}
} while(1) ;
}





PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 09, 2011 3:29 pm     Reply with quote

Post this file:
Quote:
vb_motor_all directns.h

We need to see the #include line for your PIC, the #fuses, #use delay(),
#use rs232(), etc.

Also post your CCS compiler version.
talhahs



Joined: 14 Oct 2010
Posts: 14

View user's profile Send private message

PostPosted: Mon Jan 10, 2011 2:05 am     Reply with quote

Compiler version: PCWHD 4.104

Code:
#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES RESERVED                 //Used to set the reserved FUSE bits

#use delay(clock=12000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Mon Jan 10, 2011 3:34 am     Reply with quote

Glaring thing, you _must_ have 'errors' in your RS232 definition.

Generally, this should _always_ be used, unless _you_ are handling UART errors yourself.
In your case, not having it, will almost certainly hang the UART. Problem is the long delays. You have delays for the prints, and long timing delays in the code. If more than two characters arrive in any of these, the UART _will_ be hung....

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 10, 2011 6:52 am     Reply with quote

Do you have a MAX232 or equal on the serial I/O lines?

Serial cable is wired correctly?

Are you sure the VB program is sending an ASCII 0...4 ?

Have you tried hyperterminal or another terminal software package?

Try a loopback echo program to be sure..even have the PIC do it, before executing the case code...

I'd add a case 'else' statement to turn off the motors for invalid commands.
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