Stepper help

GBlair

Member
Hi folks

Need to see if I can get a little help on a stepper project I am working on.
Here is the code I have right now,

Code:
main: 			‘ make a label called ‘main’

if pin3 = 0 then rstep 		‘ If high turn right
if pin3 = 1 then lstep		‘ If high turn left		
goto main 			‘ else loop back around

rstep:				‘ start a for...next loop
toggle 1 				‘ Toggle pin 1
high 4				‘ direction indicator right on	
pause 1				‘ Wait 1ms
toggle 2				‘ Toggle pin 2
pause 1 				‘ Wait 1ms
goto main	 		‘ goto main

lstep:
toggle 2 				‘ Toggle pin 1
low 4				‘ direction indicator left off
pause 1				‘ Wait 1ms
toggle 1				‘ Toggle pin 2
pause 1 				‘ Wait 1ms
goto main	 		‘ goto main
It works alright as is but I would like to be able to count the steps or give it a command to go x number of steps then stop. Is this possible to do with a 08M?
I am using a 08M with a ULN2003 to drive the stepper and it is 1.8° per stepper.

I am not very good a writing code but am trying to learn you know old dog new tricks.
Any help will be appreciated.
Thanks
GBlair
KD8ENK
 

eclectic

Moderator
GBlair.

You could start by experimenting with something like this
Code:
Main

for b0 = 1 to 100  ' 100 steps (half turn)
gosub rstep
next

for b0 = 1 to 100  ' 100 steps (half turn)
gosub lstep
next
	
goto main 			‘ else loop back around

rstep:				‘ start a for...next loop
toggle 1 				‘ Toggle pin 1
high 4				‘ direction indicator right on	
pause 1				‘ Wait 1ms
toggle 2				‘ Toggle pin 2
pause 1 				‘ Wait 1ms
return    ' *** changed


lstep:
toggle 2 				‘ Toggle pin 1
low 4				‘ direction indicator left off
pause 1				‘ Wait 1ms
toggle 1				‘ Toggle pin 2
pause 1 				‘ Wait 1ms
return     '*** changed
For counting, inside the gosub, have a variable which increases.
Something like W0 = W0 + 1
Then Sertxd the values.


Then attach an IR receiver to input 3 (see Man 2, page 82 ...)
and control via a Sony style remote.


e
 

GBlair

Member
OK Let me get this straight, I could use a TV remote and make the stepper motor move.
Is that correct? If so that would be great. I tried the code suggestion and it would only go 250 steps not sure why but I will need 1000 or more.
 

Peter M

Senior Member
Hi GBlair,
The code that eclectic gave you will only go up to 255 because it only uses a byte variable "b0" (8 bits = 0 to 255) to go beyond this you either need to nest the loop inside another ie get mutiples of b0, or use a Word variable (16 bits = 0 to 65535) ie w0 instead of b0. w0 uses b0 and b1 combined to form a "word" variable.
hope this helps
 

Peter M

Senior Member
infrared remote control should be fairly strait forward using a combo of electic code and somethng like this
Code:
#picaxe08m
'remote control stepper driver
main:
   infrain2
    if b13<5 then
          goto rightstep 'remote buttons from 1 to 5 = right
    else  
          goto leftstep 'remote buttons above 5 = left
    endif
 
numstep:
     select b13  'this is infrain is stored
     case 0 :w0=100 '1/2 a turn right button 1
     case=1 :w0=200 '1 turn button 2
     case=2 :w0=400 '2 turns button 3
     'etc
     case=5 :w0=100 '1/2 a turn left button 6
     endselect
 
   goto main
 
leftstep:
     'code to set left stepping
     goto numstep
rightstep:
     'code to set right stepping
     goto numstep
 

GBlair

Member
That is super.
I have found a detector in town and will go pick it up after church today. I will give an update later.
Thanks
GBlair
 

GBlair

Member
Well I got the 38kHz Infrared (IR) Receiver Module and got this baby wired in. here is the code
Code:
#picaxe08m
					'remote control stepper driver
main:
   infrain2
    if b13<5 then
          goto rightstep 	'remote buttons from 1 to 5 = right
    else  
          goto leftstep 	'remote buttons above 5 = left
    endif
 
numstep:
     select b13  			'this is infrain is stored
     case=0 :w0=100 		'1/2 a turn right button 1
     case=1 :w0=200 		'1 turn button 2
     case=2 :w0=400 		'2 turns button 3
     					'etc
     case=5 :w0=400 		'1/2 a turn left button 6
     endselect
 
   goto main
 
leftstep:
	toggle 1 				‘ Toggle pin 1
	high 4				‘ direction indicator right on	
	pause 1				‘ Wait 1ms
	toggle 2				‘ Toggle pin 2
	pause 1				‘ Wait 1ms
     					'code to set left stepping
     goto numstep
rightstep:
	toggle 2				‘ Toggle pin 1
	low 4					‘ direction indicator left off
	pause 1				‘ Wait 1ms
	toggle 1				‘ Toggle pin 2
	pause 1				‘ Wait 1ms
     					'code to set right stepping
     goto numstep
I am using the remote and it will turn right with buttons 1-5 and left with buttons 6-0. It will only move a step or two or it will move as long as you hold down the button. Please be patient with me on this because I just don't know what I am doing basically but what I want to do is by pushing button number 1 make the motor turn 100 steps to the right and button 6 steps 400 steps to the left and so on. I know it is something wrong that I am doing but just don't know what it is. Thanks for the previous help and it is almost there and the best part is I am learning a lot as we go.
 

BCJKiwi

Senior Member
It seems that you are most of the way there.

The first thing I'd do is move the block of code from numstep: thru goto main to the end of the code because that is logically what seems to be required.

Secondly, while w0 is getting the number of steps you want, They do not seem to be going to the motor as the only code working the pins (which presumably are connected to the motor) is a toggle. The toggle will reverse the state of the pin.

So a loop is required to keep toggling (or pulsout or whatever) w0 times, or, do I not understand what it's all about?
 

eclectic

Moderator
Gerald.
Your question prompted me to dig out an old circuit,
with IR and a Unipolar stepper.
I've re-hashed the program, in line with your setup.

It's working.

I deliberately won't post it,
in case you want the fun of finding out yourself. :)

However, if you need any more "hints" or the full setup, then please ask.

e
 

GBlair

Member
Eclectic
Some hints would be deeply appreciated. I have been driving myself crazy trying this and trying that. I have made a temperature data logger just to give my head a break. There is a whole lot I need to learn and unfortunately I can learn more by doing than reading. Right now I have all of this on 3 separate boards so I will try and incorporate it all onto one board and build it this week. Any help from anyone will be appreciated.
Thanks
GBlair
 

eclectic

Moderator
Only if you promise you won't open it until Christmas. :)

It ain't perfect, but, I hope it will help.

Signing off for the night. e

Code:
; Unipolar stepper control 24/11/08
;refer to Manual 3, pages 14 / 15
;and Manual 2 page 82
;My wiring = 1 Blk/ 2 Brn / 3 Yel / 4 Ora   V+ = reds
;written for a 7.5' 48 step motor
;
;for a 1.8' 200 step motor, use the alternative lookup line
;or change the values
;

;
;Uses Infrain values 0-5 (keypresses 1-6)
;Rejects other presses.
;Lookup value of steps from 6 choices ( 0 - 5 )
;If infra = 0/1/2 then spins right
;if infra = 3-5 then spins left
;
; NB.  If the servo rotates in the "wrong" direction
; then exchange the labels  leftstep:  and rightstep:

#picaxe08m
					
   Main:
   infrain2
   
    if infra >5 then goto main
    
   lookup Infra,(12,24,48,12,24,48),w0 
   ;lookup Infra,(50,100,200,50,100,200),w0 
   ; OR whatever you need
    
       
    if Infra<=2 then
    
    high 4 &#8216; direction indicator light on
    for w1 = 1 to w0
          gosub rightstep : next
          
    else 
     
    low 4	&#8216; direction indicator light off
    for w1 = 1 to w0
          gosub leftstep : next
          	
    endif
    
 goto main
 
 
leftstep:
	toggle 1 				&#8216; Toggle pin 1		
	pause 10				&#8216; Wait 10ms
	toggle 2				&#8216; Toggle pin 2
	pause 10				&#8216; Wait 10ms
     					
     return 
     
rightstep:
	toggle 2				&#8216; Toggle pin 1
	pause 10				&#8216; Wait 10ms
	toggle 1				&#8216; Toggle pin 2
	pause 10				&#8216; Wait 10ms
     					
     return
Any problems are my fault.

I'll resume tomorrow morning.

e
 

GBlair

Member
I will do my best not to peak but I don't think I can promise anything. Here on my website are some photos of what I have been working with and a photo of the board that I will try and build this week. http://www.projectgm.com/html/picaxe.html Go down to the bottom of the page.
Thanks for the code and I might have some questions for you still if you don't mind. Oh wait I was not supposed to look darn!
Thanks
GBlair
 

eclectic

Moderator
Gerald.
Thanks for the reply.
(And I see that it's still an hour before dawn where you are).

I'm using a much smaller motor, but the principles are still the same.
Later on today, I'll make a few small modifications.

Happy to try and help with the questions.

e
 

GBlair

Member
Eclectic Thanks it is working GREAT. Busy tonight and had to work today but will get back on some questions I have. I do appreciate the help
Thanks
GBlair
 

eclectic

Moderator
Gerald.
Thanks for the feedback.

I've now added another indicator LED to pin0.
I've then added a little to the original code,
Marked with ****
Code:
  if Infra<=2 then
    
    low 0: high 4 ‘ direction indicator light off/on ' ******
    
    for w1 = 1 to w0
          gosub rightstep : next
          low 0,4 ; indicators off' ****
          
    else 
     
    high 0:low 4	‘ direction indicator light on/off '*******
    for w1 = 1 to w0
          gosub leftstep : next
          low 0,4 ; indicators off ,******
There are lots of other modifications possible,
including single stepping to”zero” the spindle.
However, I'll leave the fun to you.

e
 

GBlair

Member
Hey Eclectic did you realize you almost have 1000 post. I built the new board today and have tested it and it works fine. It is a lot cleaner than all 3 of the others with all of the wire running everywhere. I have added a photo too my website http://www.projectgm.com/html/picaxe.html they are down toward the bottom of the page with the photo of the setup that I was using. The new board also has a few expansion ports. One has line voltage, ground and + 5, one is for use with opto isolator (not in the socket yet) and one for connection to pins 1-4. OK enough about that. I will try the new addition to the code and I will get with you on the questions. I need to get time and set down and try and figure out exactly how the code is working and hopefully you will fill in the blanks for me.
Thanks again
GBlair
 
Top