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.

PIC16F684 to L239D Driver to Bipolar Stepper Motor. Programming question.

Status
Not open for further replies.

TwistedE

New Member
PIC16F684 to L293D Driver to Bipolar Stepper Motor. Programming question.

Hi,
I'm a bit confused in my project that uses a pic microcontoller to send information to a motor driver which in turn tells the motor exactly how far to move and supplies the appropriate required current.

My questions are:

1. Do I have to program the L293D motor driver or is it pre-programmed?
2. What kind of information do I have to send from the PIC to the driver and how is this to be done? Are there any examples of this?

I know about 90% of the required hardware connections and am using MPLAB and MikroC to program the PIC microcontroller. If the L239D driver requires programming, please refer me to a program and language that allows this.

Thank you.
 
Last edited:
You have to make it do what you want by programming the port pins. Find a data sheet, and read it. Here is a partial one.
 
Thanks for the reply.
I was actually meaning to refer to the L293D but accidentally made a typo in the thread title.

Anyways, I have some knowledge now and I'm trying to program my pic on mikroBasic PRO but I'm having some small issues in the code.

Code:
program Prog1

'int x;

main:

PORTA = 0
ANSEL = 0
TRISC = 0b110000
T1CON = 0b00010001

  for x = 1 to 50
   {
   
      PORTC = 0b001010;
      PORTC = 0b000110;
      PORTC = 0b000101;
      PORTC = 0b001001;
    
      for  (n = 0; n < 259; n++);   // 4ms Delay
    
   }
 end

Here are the errors:
0 1 mBPic.exe -DBG -pP16F684 -MSF -Y -DL -O11111114 -fo8 -N"C:\Users\***\Desktop\PIC16F684 Program\Prog1.mbppi" -SP"C:\Users\Public\Documents\Mikroelektronika\mikroBasic PRO for PIC\defs\" -SP"C:\Users\Public\Documents\Mikroelektronika\mikroBasic PRO for PIC\Uses\P16\" -SP"C:\Users\***\Desktop\PIC16F684 Program\" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_String.mcl" "__Lib_Conversions.mcl" "__Lib_Time.mcl" "__Lib_Trigon.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_B.mcl" "__Lib_EEPROM.mcl" "__Lib_PWM_c5.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "Prog1.mbas"
0 155 Available RAM: 112 [bytes], Available ROM: 2048 [bytes]
0 133 Compilation Started C:\Users\***\Desktop\PIC16F684 Program\Prog1.mbas
1 1015 Hint: Compiling unit "C:\Users\***\Desktop\PIC16F684 Program\Prog1.mbas" Prog1.mbas
9 304 Syntax error: Expected "integral constant" but "0b110000" found Prog1.mbas
10 304 Syntax error: Expected "integral constant" but "0b00010001" found Prog1.mbas
12 301 "for"is not valid identifier Prog1.mbas
12 304 Syntax error: Expected "end" but "for" found Prog1.mbas
12 304 Syntax error: Expected "." but "x" found Prog1.mbas
0 102 Finished (with errors): 24 Feb 2011, 13:54:22 Prog1.mbppi



I know its a bit long but any help is appreciated. I'm basically trying to move my stepper motor 50 steps by sending Ports C0-3 with information from the table below:

Step wire 1 wire 2 wire 3 wire 4
1 High low high low
2 low high high low
3 low high low high
4 high low low high


The combination of the 4 steps moves the motor 1 step...hope all this makes sense.
 
Thanks blueroomelectronics for the quick reply. I've modified the code to this:

Code:
program Prog1

'int x;

main:

PORTA = 0
ANSEL = 0
TRISC = 110000

for  (n = 0; n < 64750; n++);   // initial Delay of   1s


  for x = 1 to 50
   {
   
      PORTC = 001010;
       for  (n = 0; n < 259; n++);   // 4ms Delay
      PORTC = 000110;
       for  (n = 0; n < 259; n++);   // 4ms Delay
      PORTC = 000101;
       for  (n = 0; n < 259; n++);   // 4ms Delay
      PORTC = 001001;
       for  (n = 0; n < 259; n++);   // 4ms Delay

   } end

Sorry for the elementary questions but this is the first time I"m programming a pic microcontroller and it's not exactly a small project. Honestly, I'm not sure what the 0b is for, I just saw it on some examples on the internet.


Errors:
9 305 Argument is out of range "110000" to "byte" Prog1.mbas
9 327 Incompatible types ("complex type" to "simple type") Prog1.mbas
10 304 Syntax error: Expected "end" but "T1CON" found Prog1.mbas
10 304 Syntax error: Expected "." but "=" found Prog1.mbas
0 102 Finished (with errors): 24 Feb 2011, 14:36:55 Prog1.mbppi


Why are errors saying the argument is out of range. From what I understand, the PIC16F684 has RC0-5 so basically 6 bits right? I want to connect RC0-RC3 to the motor driver and send the step signals. During this whole time RC4 and 5 will be inputs with lows all the time. This is just a sample program to get the motors moving initially. Btw, I'm running it at 8mhz so each cycle is 125ns so I'm guessing a 4ms delay is more than sufficient.

Please hlep me with the programming errors.
 
Somhow I figured out most of my errors and used Mikrobasic pro to program the PIC. I got it running with while loops but when I use subroutines it just twitches and returns back to the original position after moving 1 step I think.

Here is the code without subroutines for 100 steps
Code:
program Prog1

dim x as byte

main:

PORTA = 0
ANSEL = 0
TRISC = $30

x = 0

delay_ms(1000) ' delay of 1s

 while (x < 100)
 
      PORTC = $0A
       delay_ms(10)
      PORTC = $06
       delay_ms(10)
      PORTC = $05
       delay_ms(10)
      PORTC = $09
       delay_ms(10)
       
       x = x + 1
      
 wend

 end.

The above program runs fine for 100 steps but if I change it to a subroutine like below....I get a twitch.

Code:
while (x < 100)

Goto Forward
x = x + 1

wend

Forward:
     PORTC = $0A
       delay_ms(10)
      PORTC = $06
       delay_ms(10)
      PORTC = $05
       delay_ms(10)
      PORTC = $09
       delay_ms(10)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top