Hi.I got several 28BY J-48 bibolar stepper motors cheap on ebay and they are popular cos they are cheap
but they need pulsing with 4 phases every 2ms to rotate at max torque.
So this is a mega328p UNO solution.
I got the 1ms timer 0 demo and the timer calculator and got the values for 2ms,easy.
It uses vars forward,stop,reverse to control the motors.
The demo shows the motors running while wait command.
It is just a handler for these cheap geared stepper motors. https://www.youtube.com/watch?v=0eZFZsmpvR4&feature=youtu.be
;28BY J-48 bibolar stepper driver full wave at every 2ms;this uses portD for 2 motors
#chipmega328p,16
#optionExplicitdiml_mot_pos,r_mot_posasbytediml_mot_dir,r_mot_dirasbyte
#defineforward1;|
#definereverse255;|--motor direction
#definestop0;|l_mot_pos=1:r_mot_pos=1l_mot_dir=forward:r_mot_dir=forward;;setup stepper motor interrupts step every 2msOnInterruptTimer0Match1CallmotorsDimOCR0ASbytealiasOCR0ADimTCCR0ASbytealiasTCCR0BWGM01=1'Timer in CTC mode - required'Timer0 Prescaler = 64OCR0=124;2msTCCR0=0x28TCCR0=TCCR0or0x04;dol_mot_dir=forward:r_mot_dir=forwardwait5sl_mot_dir=reverse:r_mot_dir=reversewait5sl_mot_dir=reverse:r_mot_dir=forwardwait5sl_mot_dir=forward:r_mot_dir=reversewait5sloopsubmotorsifl_mot_dir=stopthensetportd.0off:setportd.1off:setportd.2off:setportd.3offelseifl_mot_dir=forwardthenl_mot_pos++ifl_mot_pos=5thenl_mot_pos=1endifelsel_mot_pos---ifl_mot_pos=0thenl_mot_pos=4endifendif;selectcasel_mot_poscase1setportd.0on:setportd.1on:setportd.2off:setportd.3offcase2setportd.0off:setportd.1on:setportd.2on:setportd.3offcase3setportd.0off:setportd.1off:setportd.2on:setportd.3oncase4setportd.0on:setportd.1off:setportd.2off:setportd.3onendselect;ifr_mot_dir=stopthensetportd.4off:setportd.5off:setportd.6off:setportd.7offelseifr_mot_dir=forwardthenr_mot_pos++ifr_mot_pos=5thenr_mot_pos=1endifelser_mot_pos---ifr_mot_pos=0thenr_mot_pos=4endifendif;selectcaser_mot_poscase1setportd.4on:setportd.5off:setportd.6off:setportd.7oncase2setportd.4off:setportd.5off:setportd.6on:setportd.7oncase3setportd.4off:setportd.5on:setportd.6on:setportd.7offcase4setportd.4on:setportd.5on:setportd.6off:setportd.7offendselectendsub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'28BYJ_48_12F683_ver092.gcb'2017/ 1/ 3'A program to Run a 4096 step geared step motor 28BYJ-48'actually this is doing full step mode in which 2 coils are active at a Time' so it only has 2048 steps/turn (seems like a couple less)'Another array could be built to do eight half steps'The outputs run a ULN2003 like supplied by so many chinese suppliers'The input Port GPIO.4 has a pushbutton'Setup: routine allows the operator to align the shaft on start up'MainLoop: routine rotates the motor one full turn'If you change the MainLoop in line 44 to MainLoop2 then it'will demo a 5 station/position pattern'by Mike Otte'2013'Chip model
#chip12F683, 8dimFull(5)Full(0)=b'00000110'Full(1)=b'00000011'Full(2)=b'00001001'Full(3)=b'00001100''Set the pin directionsdirGPIO.0out'These are wired to the uln2003 inputsdirGPIO.1outdirGPIO.2outdirGPIO.5outdirGPIO.4IN'pushbutton inputDimpositionasWord'Could be integer if we go below 0 positionposition=0'Initialize position routineSetup:
' let motor turn until operator Pushes Button at home PositionIfGPIO.4=1ThenStepCW'wait for button pushIfGPIO.4=0Thenposition=0wait500msgotoMainLoop2' to demo 5 positionendifgotoSetup'One turn MainLoop ,get here from 3 lines above ,line44?MainLoop:
'wait for button pushIfGPIO.4=1ThengotoMainLoopStepTo(2040)'one turnposition=0'resets position counter for next movewait500ms'Gives time for button release if only a few stepsgotoMainLoop' Example2: of going to 5 different positions and waiting for the button to be pushed'Button is a pull downMainLoop2:
IfGPIO.4=1ThengotoMainLoop2IfGPIO.4=0Thenstation++Ifstation>5thenstation=1wait500msgotonewstationendifgotoMainLoop2newstation:
Selectcasestationcase1StepTo(500)'station position 1wait500ms'Gives time for button release if only a few stepscase2StepTo(1500)'station position 2wait500ms'Gives time for button release if only a few stepscase3StepTo(2500)'station position 3wait500ms'Gives time for button release if only a few stepscase4StepTo(3000)'station position 4wait500ms'Gives time for button release if only a few stepscase5StepTo(3100)'station position 5wait500ms'Gives time for button release if only a few stepsendSelectgotoMainLoop2SubStepTo(newposasword)EnMotorDountilPosition=newposIfnewpos<positionthenStepCCWIfnewpos>positionthenStepCWloopDisEnMotorendsubSubEnMotordirGPIO.0outdirGPIO.1outdirGPIO.2outdirGPIO.5outendsubSubDisEnMotordirGPIO.0in'disables motor so it converves energy and don'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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Mike. These geared steppers and drivers seem popular,loads of youtube and guides.
I posted code for running them before but used a i2c port expander. I think running that and a i2c rangefinder would do my head.
As before I used an interrupt so the motors run at a constant most efficient speed.
Seems they can be run with halfwave,fullwave or a combo of both. Fullwave is simple and faster. Before I used the combo mode which is 8 different phases, more steps so slower rotation.
2ms is optimum rotation time. Any faster and they don't turn.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
SubDisEnMotordirGPIO.0in'disables motor so it converves energy and don'theatupdirGPIO.1indirGPIO.2indirGPIO.5inendsub
does gcb have portx=255 so you can set all bit in one go?
I don't think so or it would be easy to control these motors by just rotating the phase pattern left/right.
only 4 bits so 1 byte does 2 motors ie the port.
it would be portd= left phase + right phase * 8
if using 4 bits for each motor,
Hi Stan,
Here's another.
Astro photography require to move the camera as the Earth turns so you do not get "star trails". So a "Barn Door" tracker was built. Hinge on one end of two boards and a threaded rod turned by a motor on the other end. Mount the camera on the top board and screw the bottom board to a tripod. Then align the hinge pivot to the north star thus making a primative "equatorial mount". I did this with my Cannon 1000 and a 300 mm lens. Took some great pictures.
'A program to Run a 4096 step geared step motor on a 10-32 threaded rod ' for a "barn Door" tracker to hold a camera and track the stars'by Mike Otte'2013'Chip model
#chip16F886, 8dimFull(5)Full(0)=b'00000110'Full(1)=b'00000011'Full(2)=b'00001001'Full(3)=b'00001100'dimRFull(5)RFull(3)=b'00000110'RFull(2)=b'00000011'RFull(1)=b'00001001'RFull(0)=b'00001100'' momentary switches
#defineHomePORTC.0
#defineRAstopPORTC.1
#defineRAplusPORTC.2
#definelimitPORTC.3'define PORTC upper 4 bits for adjusting the time in additional millisec / step'Set the pin directionsdirPORTBoutdirPORTCIN' i am not using interrupt because this steps fast 'On Interrupt PORTBChange Call buttonswttm=17'wait time was 25 msecwtmodify=PORTCwtmodify=wtmodifyAND0xf0' mask off the upper four bitsrotatewtmodifyrightsimple'shift them to the lower four bitsrotatewtmodifyrightsimple' i put pullups and board jumper pins to act as switchesrotatewtmodifyrightsimplerotatewtmodifyrightsimplewttm=wttm+wtmodify' add or subtract for tuning delay from portc upper four bits' wttm (wait time) now has the total valuePortB=0'initializemyj=0wait1s'Main routineStart:
myStep=myjmod4thisStep=Full(myStep)PortB=thisStepwaitwttmmsmyj++gosubbuttonsgotoStartsubbuttonsifRAplus=0then' these were going to make it go faster or slower DOUNTILRAplus=1myStep=myjmod4PortB=Full(myStep)wait7msmyj++loopendififRAstop=0then' but i don'tusethesetwoswitchesDOUNTILRAstop=1myStep=myjmod4PortB=RFull(myStep)wait7msmyj++loopendififhome=0then'I really only use these two switches'"home" switch sends the barn door towards home (closed limit)DOUNTILlimit=0' the "limit" stops it when it get home myStep=myjmod4'and returns it to going forward againPortB=RFull(myStep)wait2msmyj++loopendifEndSub
Pretty much only used the Battery switch, run switch and the limit switch.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi.I got several 28BY J-48 bibolar stepper motors cheap on ebay and they are popular cos they are cheap
but they need pulsing with 4 phases every 2ms to rotate at max torque.
So this is a mega328p UNO solution.
I got the 1ms timer 0 demo and the timer calculator and got the values for 2ms,easy.
It uses vars forward,stop,reverse to control the motors.
The demo shows the motors running while wait command.
It is just a handler for these cheap geared stepper motors.
https://www.youtube.com/watch?v=0eZFZsmpvR4&feature=youtu.be
Hi Stan,
Here's mine.
Hi Mike. These geared steppers and drivers seem popular,loads of youtube and guides.
I posted code for running them before but used a i2c port expander. I think running that and a i2c rangefinder would do my head.
As before I used an interrupt so the motors run at a constant most efficient speed.
Seems they can be run with halfwave,fullwave or a combo of both. Fullwave is simple and faster. Before I used the combo mode which is 8 different phases, more steps so slower rotation.
2ms is optimum rotation time. Any faster and they don't turn.
mike
I send off to each port
does gcb have portx=255 so you can set all bit in one go?
I don't think so or it would be easy to control these motors by just rotating the phase pattern left/right.
only 4 bits so 1 byte does 2 motors ie the port.
it would be portd= left phase + right phase * 8
if using 4 bits for each motor,
Last edit: stan cartwright 2020-06-14
Hi Stan,
Here's another.
Astro photography require to move the camera as the Earth turns so you do not get "star trails". So a "Barn Door" tracker was built. Hinge on one end of two boards and a threaded rod turned by a motor on the other end. Mount the camera on the top board and screw the bottom board to a tripod. Then align the hinge pivot to the north star thus making a primative "equatorial mount". I did this with my Cannon 1000 and a 300 mm lens. Took some great pictures.
Pretty much only used the Battery switch, run switch and the limit switch.
New to me. https://nyxtech.us/products/nyx-tracker
That's it. mine is less refined and inexpensive.
That's it. mine is less refined and inexpensive.