The bear
Senior Member
Hello Everyone,
Having just seen a post on todays forum , with a gosub/stack problem.
Would appreciate any comments/help on my program, one Hemi345 suggested for me.
I have modified it to suit my purposes, namely moving the slats on a venetian blind, triggered
by dawn & dusk light levels. Its still on the drawing board. using PE6, latest vers. bar one.
Stepper is a 28BYJ-48-ULN2003 driver.
Having just seen a post on todays forum , with a gosub/stack problem.
Would appreciate any comments/help on my program, one Hemi345 suggested for me.
I have modified it to suit my purposes, namely moving the slats on a venetian blind, triggered
by dawn & dusk light levels. Its still on the drawing board. using PE6, latest vers. bar one.
Stepper is a 28BYJ-48-ULN2003 driver.
Code:
#picaxe 14m2 ;Stepper motor,Hemi345 14M2 20.01.15 vers 1.0
#no_data ;125 Bytes PRINTED
setfreq m8
symbol mPause = b0 ; 5mS (speed of movement)
symbol mCycle = b1 ;0,1,2,3
symbol mDir = b3 ; 0 & 2 (For. & Rev)
symbol mStep = w2 ;counting up
let dirsC=%00010111 'set C.0 thru C.4 to outputs
let dirsB= %00111100 ;set B.2 thru B.5 to o/p's
let pinsC=%00000000 'put C.0 thru C.4 low
mPause = 5 ;good starting torque @ 5ms pause
main:
label_01:
gosub clockwise
pause 500
gosub anticlockwise
pause 500
clockwise:
label_02:
readadc B.1,b12
if b12 < 70 then label_03
pause 100
goto label_02
label_03:
mDir=mDir + 2 MAX 3 % 3 'motor direction 0 CW, 2 CCW
for mStep = 1 to 512 ; = about 1/4 turn. Amount of turn.& No.of cycles
mCycle=mCycle + mDir - 1 % 4
lookup mCycle,(%00000011,%00000110,%00010100,%00010001),pinsC
pause mPause 'default 5 slow but good torque, 1 fast but very little torque
next mStep
let pinsC=%0000000 'put C.0 thru C.4 low
pause 5000 ;pause between oscilliations
return ;goto main
anticlockwise:
label_04:
readadc B.1,b12 ;if pinc.3 = 0 then label_05
pause 100
if b12 > 80 then label_05
goto label_04
label_05:
mDir=mDir + 2 MAX 3 % 3 'motor direction 0 CW, 2 CCW
for mStep = 1 to 512 ; = about 1/4 turn. Amount of turn.& No.of cycles
mCycle=mCycle + mDir - 1 % 4
lookup mCycle,(%00000011,%00000110,%00010100,%00010001),pinsC
pause mPause 'default 5 slow but good torque, 1 fast but very little torque
next mStep
let pinsC=%0000000 'put C.0 thru C.4 low
pause 5000 ;pause between oscilliations
return ;Notes: Stack underflow if 'return' is used . GOTO = OK? ;