Running stepper motor

JPB33

Senior Member
As part of a bigger project I want to run a stepper motor via its controller for approx 1000 turns. I intend using a hall sensor on the input shaft and count the turns. I have the stepper running at around 1000 rpm using a 4046 vco to set the pulse rate to the controller. This vco works well on other projects and was hoping to use a picaxe as the counter to supply the vco and stop at 1000 turns.

The program worked fine in simulation and I thought this was asking a bit much of an 8m2 to count at 1000rpm so tried program this on a board with led's as waiting of some parts to try in the real world. I find at 32 meg it rattles through the counting to 1000 in under a 1 sec?

Is it really working at this speed or have I something badly wrong with my program?

Thanks Peter



Code:
setfreq m32


	output C.0,C.1,C.2
	input C.5,C.3,C.4
	Start:
	;readadc c.4, w0          	' read input value of pot on switch on, load value into w0 (COMMENTED OUT FOR TESTING)
	w0 = 100				'value from input pot to set number 
	w0 = w0*10               	'wo x 10 to give 1000
	high c.0    		  	'orange led
	pause 8000
	
	do 'do				'RUNNING STEPPER AND COUNTING INPUT PULSES
	;loop until pinc.4 =1		'Input trigger from Hall sensor (COMMENTED OUT FOR TESTING)
	low c.0
	high c.1    			'red led Stepper running
	w1 = w1 + 1
	loop until w1 >= w0
	w1 = 0 
	low c.1
	
	pause 1000
	high c.2         			'green finished run 
	pause 8000
	low c.2
	;goto start				(COMMENTED OUT FOR TESTING)
	end
 

hippy

Technical Support
Staff member
Is it really working at this speed or have I something badly wrong with my program?
It's not entirely clear what code you are running as a lot of what one would imagine you might be using is commented out.

It's also not clear when you are starting things or when you are stopping them, what exactly you are measuring or what results you would be expected to get.

If the "Do : Loop until pinc.4 =1" is meant to trigger the counting, at high speeds it may be that execution gets back there before the pulse has gone leading to double counting or worse. You might want a "Do : Loop until pinc.4 =0" before or after that to ensure you are only counting edges rather than levels.
 

BESQUEUT

Senior Member
As part of a bigger project I want to run a stepper motor via its controller for approx 1000 turns. I intend using a hall sensor on the input shaft and count the turns. I have the stepper running at around 1000 rpm using a 4046 vco to set the pulse rate to the controller. This vco works well on other projects and was hoping to use a picaxe as the counter to supply the vco and stop at 1000 turns.
Why approx 1000 turns ? With a stepper motor, you can reach exactly 1000 turns, and if necessary parts of a turn.

Why counting turns with a hall sensor ?
A stepper motor needs a known numbers of steps for each turn, for example 200 steps/turn.

So if you want to achieve 1000 turns, simply send 200 000 steps...

If not able to send steps :
Why not simply wait 1m as the rpm is 1000 ?

If still wanting to use Hall sensor, 1000 rpm is 17 r/s so Picaxe @32 Mhz is certainly able to handle that.
 
Last edited:

AllyCat

Senior Member
Hi,
Yes, you probably have something wrong in your program.

You either need to use a COUNT command, or must test for the input going repeatedly "High" and "Low", for example:

Code:
do
  do : loop until pinc.4 = 1
  do : loop until pinc.4 = 0
  w1 = w1 + 1
loop until w1 >= w0
1,000 rpm is only 17 Hz, which can probably be handled easily by a PICaxe even at 4 MHz. But whether any pulses are "missed" will depend on the duty cycle (or pulse width) from the Hall sensor. There are methods to "latch" each pulse (edge) if the pulses are very narrow.

Cheers, Alan.
 

JPB33

Senior Member
Thanks for the prompt replies.

Appreciate that a stepper is precise, another part of the machine uses a 4017 counter chain to generate 80,000 pulses to give 50 turns to a stepper. That works well but wanted to try what I've learned and use a picaxe also I'm not sure of the exact number I need yet.

Hippy, I left off the "Loop until pinc.4 =0" part of the input counter from C.1 so that I could try it with my LED on a board. My full code for the counter is below.

Alan. As you say its only 17Hz, what speed do you think it could handle?

loop until pinc.4 = 0 ' input pin pulse from shaft sensor
do
loop until pinc.4 =1
high c.1 'red LED
w1 = w1 + 1
loop until w1 >= w0
w1 = 0
low c.1
 

BESQUEUT

Senior Member
wanted to try what I've learned and use a picaxe also I'm not sure of the exact number I need yet.
Why not using the Picaxe to send pulses ?
You can also use it to enter the required number of turns (via USB, or Keyboard or...)
Alan. As you say its only 17Hz, what speed do you think it could handle?
IHMO, more than the stepper motor can achieve... (a stepper motor is necessary slow)
 

hippy

Technical Support
Staff member
Alan. As you say its only 17Hz, what speed do you think it could handle?
Much faster than a stepper as Alan says. Each token of executable code works out about 125us at 4MHz, say 16us at 32MHz. Say 16 tokens in a counting loop and that's 256us. That's about 4kHz sampling rate. With one pulse per revolution; 240,000 RPM.
 

JPB33

Senior Member
I was going to use the readac from a pot to supply the required number with a display to see what I'm doing when setting up---a usb keyboard or computer isnt very convenient.

The stepper is set for 8 steps and seems happy running at 1000 rpm with 9.1khz from the vco.

From previous threads I thought that a picaxe was a slow for this sort of job?
 

JPB33

Senior Member
Thanks Hippy, that's a lot faster than what I thought, It'll be interesting to see how it works out when more parts arrive and I can start building!
 
Top