PDA

View Full Version : storing arrays and reading arrays



Yue
- 5th March 2004, 23:03
i have a problem, can anyone help me

my situation involves stepper motors, the purpose of my code is to make my program self learn. when we move the motor left we store this position at array2 and in binary numbers. this is later compared and tells which direction the motor must run. we run the stepper motor and every pusle that it turn we increment a varible and that varible is stored in an array1 during the position it is in.

once this is store and we want to display what it had just done, it should, but its not. the motor is just spining in any random direction.

here a set of our codes

include "modedefs.bas"

steps VAR WORD
stepArray VAR BYTE(4)


Pause 1000
'our1 VAR WORD
OurArray VAR BYTE(30)
'new1 var word
NewArray VAR BYTE(30)
TRISB = %00000000
TRISA = %11111111
ADCON1 = 7
x VAR BYTE
y VAR BYTE
A VAR BYTE
B VAR BYTE

Main:
if portA.0 = 1 then
gosub manual
endif
if portA.1 = 1 then
gosub prepro
' else
' gosub case1
endif
goto Main

manual:
OurArray = 0
NewArray = 0

x = 0
y = 0
man:
if portA.0 = 0 then
return
endif
if portA.2 = 1 then
gosub right
endif
if portA.3 = 1 then
gosub left
endif
' if portA.4 = 1 then
' gosub forward
' endif
' if portA.0 = 0 then
' return
' endif
' if portA.5 = 1 then
' gosub backward
' endif
' if portE.0 = 1 then
' gosub top
' endif
' if portE.1 = 1 then
' gosub bottom
' endif
goto man

right:
x = 0
ri:
OurArray[y] = %00010000
stepArray[0] = %00001010
stepArray[1] = %00000110
stepArray[2] = %00000101
stepArray[3] = %00001001
steps = steps + 1
PORTB = stepArray[steps //4]
pause 6
x = x + 1
NewArray[y] = x
if PORTA.2 = 0 then
y = y + 1
return
endif
goto ri

left:
x = 0
le:
OurArray[y] = %00100000
stepArray[0] = %00001001
stepArray[1] = %00000101
stepArray[2] = %00000110
stepArray[3] = %00001010
steps = steps + 1
PORTB = stepArray[steps //4]
pause 6
x = x + 1
NewArray[y] = x
if PORTA.3 = 0 then
y = y + 1
return
endif
goto le

Prepro:
y = 0
x = 0
Pre:
if PORTA.1 = 0 then
return
endif
B = OurArray[y]
if B = %00100000 then
gosub MOVELEFT
endif
if B = %00010000 then
gosub MOVERIGHT
endif
y = y + 1
x = x + 1
goto Pre

MOVELEFT:
A = 0
A = NewArray[y]
move:
if A = 0 then
return
endif
stepArray[0] = %00001010
stepArray[1] = %00000110
stepArray[2] = %00000101
stepArray[3] = %00001001
steps = steps + 1
PORTB = stepArray[steps //4]
pause 6
A = A - 1
goto move

MOVERIGHT:
A = 0
A = NewArray[y]
moved:
if A = 0 then
return
endif
stepArray[0] = %00001001
stepArray[1] = %00000101
stepArray[2] = %00000110
stepArray[3] = %00001010
steps = steps + 1
PORTB = stepArray[steps //4]
pause 6
A = A - 1
goto moved
end


if anyone can give us any assistant please help
thanks