I have stepper motor code that works using case but not reading from a table.
When I use case the program works and the motors do as told but when using a table they just go in one direction.
The motor control is 100Hz interrupt. Is reading table too slow for interrupt or is there an error in my prog.
This snip works but uncomment ReadTable lmot,lmotor,lmotval and comment select case lmotor to End select doesn't. They should do the same but is the 100Hz interrupt to short?
For some reason it works now. I rebuilt the mcp23017 stepper driver and it's fine, instead of case I read from a table..looks neater. Can't work out why
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I take it back! Using a table for 28BYJ-48 Stepper Motor with ULN2003a driver is iffy.
This code works and moves the motors but if I uncomment the readtable and comment select case to end select, the motors just go in one direction.(there's a band called that)
annoying me. read table should do the same as case.
Using one table makes both motors just go in one direction.
Working using case https://youtu.be/jxKymWoiZ2k
So was I about a year ago. It needed to be minature so i used a 12f683. This worked real slick for positioning a magic trick. Maybe you can get some ideas off of this?
'A program to Run a 4096 step geared step motor 28BYJ-48'actuallythisisdoingfullstepmodeinwhich2coilsareactiveataTime' so it only has 2048 steps/turn (seems like a couple less)'Anotherarraycouldbebuilttodoeighthalfsteps'The outputs run a ULN2003 like supplied by so many chinese suppliers'TheinputPortGPIO.4hasapushbutton'Setup: routine allows the operator to align the shaft on start up'MainLoop:routinerotatesthemotoronefullturn'If you change the MainLoop in line 41 to MainLoop2 then it'willdemoa5station/positionpattern'by Mike Otte'2013,,,upgraded2016'Chip model#chip 12F683, 8 dim Full(5) Full(0) = b'00000110' Full(1) = b'00000011' Full(2) = b'00001001' Full(3) = b'00001100''SetthepindirectionsdirGPIO.0out'These are wired to the uln2003 inputsdir GPIO.1 outdir GPIO.2 outdir GPIO.5 outdir GPIO.4 IN 'pushbuttoninputDimpositionasWord'Could be integer if we go below 0 positionposition =0'MainroutineSetup:IfGPIO.4=1ThenStepCWIfGPIO.4=0Thenposition=0wait500msgotoMainLoop' to demo 5 position end if goto Setup'OneturnMainLoop,getherefrom3linesabove,line41MainLoop:IfGPIO.4=1ThengotoMainLoopStepTo(2040)'one turn position =0 'resetspositioncounterfornextmovewait500ms'Gives time for button release if only a few steps goto MainLoop'Exampleofgoingto5differentpositionsandwaitingforthebuttontobepushed'Button is a pull downMainLoop2: If GPIO.4 = 1 Then goto MainLoop2 If GPIO.4 = 0 Then station++ If station > 5 then station = 1 wait 500 ms goto newstation end if goto MainLoop2newstation: Select case station case 1 StepTo(500) 'stationposition1wait500ms'Gives time for button release if only a few steps case 2 StepTo(1500) 'stationposition2wait500ms'Gives time for button release if only a few steps case 3 StepTo(2500) 'stationposition3wait500ms'Gives time for button release if only a few steps case 4 StepTo(3000) 'stationposition4wait500ms'Gives time for button release if only a few steps case 5 StepTo(3100) 'stationposition5wait500ms'Gives time for button release if only a few steps end Select goto MainLoop2Sub StepTo(newpos as word) EnMotor Do until Position = newpos If newpos < position then StepCCW If newpos > position then StepCW loop DisEnMotorend subSub EnMotor dir GPIO.0 out dir GPIO.1 out dir GPIO.2 out dir GPIO.5 outend subSub DisEnMotor dir GPIO.0 in 'disablesmotorsoitconvervesenergyanddon'theatupdirGPIO.1indirGPIO.2indirGPIO.5inendsubSubStepCWPosition++myStep=positionmod4thisStep=Full(myStep)GPIO.0=thisStep.0GPIO.1=thisStep.1GPIO.2=thisStep.2GPIO.5=thisStep.3wait2msendsubSubStepCCWPosition--myStep=positionmod4thisStep=Full(myStep)GPIO.0=thisStep.0GPIO.1=thisStep.1GPIO.2=thisStep.2GPIO.5=thisStep.3wait2msendsubEnd
BR
73
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You turn off motor with gpio in, I just set motor lines to 0.
My code works fine using case but read table,the same values and motors don't change direction or stop. So obvious I can't see the wood for trees thing.
The motors are carp but cheap and for a "robot" cheaper than geared dc motor and h-bridge.
Data sheet says run at 100Hz but I'm rubbish at interrupt calc so used a scope to test portb.0=!portb.0 so guess frequency is half shown.
I'm using as uni-polar but there's another way I saw that doesn't use the common,the guy cut tracks on the motor but a reply said not necessary.
For a "table top robot" I can change motor speeds with interrupt freq or turn intoff and single step.
Not a "real" steppper but interesting. Cheers.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Interesting Mike you wait 2 ms between next phase. I marked the wheels and 4096 phases give one revolution. I changed it to 1 ms and it doesn't go 360 deg ??
ps I tried
Full(0) = b'00000110'
Full(1) = b'00000011'
Full(2) = b'00001001'
Full(3) = b'00001100'
but seemed familiar and didn't work ie motors buzzed not move. The phase pattern that is
Last edit: stan cartwright 2018-01-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have stepper motor code that works using case but not reading from a table.
When I use case the program works and the motors do as told but when using a table they just go in one direction.
The motor control is 100Hz interrupt. Is reading table too slow for interrupt or is there an error in my prog.
This snip works but uncomment ReadTable lmot,lmotor,lmotval and comment select case lmotor to End select doesn't. They should do the same but is the 100Hz interrupt to short?
The complete program that works as is but not if table is used.
For some reason it works now. I rebuilt the mcp23017 stepper driver and it's fine, instead of case I read from a table..looks neater. Can't work out why
I take it back! Using a table for 28BYJ-48 Stepper Motor with ULN2003a driver is iffy.
This code works and moves the motors but if I uncomment the readtable and comment select case to end select, the motors just go in one direction.(there's a band called that)
annoying me. read table should do the same as case.
Using one table makes both motors just go in one direction.
Working using case https://youtu.be/jxKymWoiZ2k
Stan,
I see your playing with a 28BYJ-48 Stepper.
So was I about a year ago. It needed to be minature so i used a 12f683. This worked real slick for positioning a magic trick. Maybe you can get some ideas off of this?
BR
73
Mike
You turn off motor with gpio in, I just set motor lines to 0.
My code works fine using case but read table,the same values and motors don't change direction or stop. So obvious I can't see the wood for trees thing.
The motors are carp but cheap and for a "robot" cheaper than geared dc motor and h-bridge.
Data sheet says run at 100Hz but I'm rubbish at interrupt calc so used a scope to test portb.0=!portb.0 so guess frequency is half shown.
I'm using as uni-polar but there's another way I saw that doesn't use the common,the guy cut tracks on the motor but a reply said not necessary.
For a "table top robot" I can change motor speeds with interrupt freq or turn intoff and single step.
Not a "real" steppper but interesting. Cheers.
Interesting Mike you wait 2 ms between next phase. I marked the wheels and 4096 phases give one revolution. I changed it to 1 ms and it doesn't go 360 deg ??
ps I tried
Full(0) = b'00000110'
Full(1) = b'00000011'
Full(2) = b'00001001'
Full(3) = b'00001100'
but seemed familiar and didn't work ie motors buzzed not move. The phase pattern that is
Last edit: stan cartwright 2018-01-03
I also tried an array but the motors didn't even move. I'll stick with case that works fine, just annoying I can't see my error.
This is getting silly. Why don't bin vals work ie use bin vals in prog instead of decimal?
These little motors work fine with case.