PDA

View Full Version : Stepper motor with L293B and pic16f648A



manjero
- 31st March 2008, 01:08
Hi.
Im trying to make a stepper motor move right or left with this pic.
I've connected everything according to examples and the datasheets but still no movement.
i guess its my code and im missing something. i would really appreciate if someone can please point me in the right direction.

DEFINE ADC_CLOCK 3
steps var word
stepArray var byte(4)

CMCON = 7
TRISA = 1
TRISB = %11110000
PORTB = %11111111
input porta.0
input porta.1
stepArray[0] = %00001010
stepArray[1] = %00000110
stepArray[2] = %00000101
stepArray[3] = %00001001

pause 500

main:
if porta.1 = 1 then
steps = steps + 1
endif

if porta.0 = 1 then
steps = steps -1
endif

PORTB = stepArray[steps // 4]
pause 3

goto main

the motor is connected on port b - 0-3 and the buttons are on pins a0 and a1
anyone?

thanks in advance,
Shahar

Raflex
- 31st March 2008, 01:35
Hello, try with this modified code:



DEFINE OSC 4 'Change it for your osc
DEFINE ADC_CLOCK 3
steps var word
stepArray var byte(4)
x var byte

CMCON = 7
TRISA = %00000011 'Porta.0 and porta.1 as input
TRISB = %00000000 'Portb as output, 0=Output, 1=Input
PORTB = 0
x=0
'input porta.0 ' You dont need this, just TRISA command
'input porta.1
stepArray[0] = %00001010
stepArray[1] = %00000110
stepArray[2] = %00000101
stepArray[3] = %00001001

pause 500

main:
if porta.1 = 1 then
for x=0 to 3
PORTB = stepArray[x]
pause 20 'Change it for diferent speed
next x
endif

if porta.0 = 1 then

for x=0 to 3
PORTB = stepArray[3-x]
pause 20 'Change it for diferent speed
next x
endif



goto main

manjero
- 31st March 2008, 06:52
Thanks Raflex but it still doesnt work. when i use this program with the simulator it gets nothing - the stepper motor isnt even getting ready and all PORTB is not an output.
when i used the original code - i saw the motor getting ready (green) but when i pressed the button - it didnt do anything.

anyone?

Raflex
- 31st March 2008, 07:32
Thanks Raflex but it still doesnt work. when i use this program with the simulator it gets nothing - the stepper motor isnt even getting ready and all PORTB is not an output.
when i used the original code - i saw the motor getting ready (green) but when i pressed the button - it didnt do anything.

anyone?

Check the configuration fuses, mclr, internal or external osc, etc:



@ DEVICE pic16F648a, INTRC_OSC_NOCLKOUT
' System Clock Options (HS_OSC, INTRC_OSC, INTRC_OSC_NOCLKOUT)
@ DEVICE pic16F648a, WDT_OFF
' Watchdog Timer
@ DEVICE pic16F648a, PWRT_OFF
' Power-On Timer
@ DEVICE pic16F648a, MCLR_OFF
' Master Clear Options (External)
@ DEVICE pic16F648a, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F648a, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F648a, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F648a, PROTECT_OFF
' Program Code Protection