Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Why is better to ramp up a stepper motor, rather than PWM?

Status
Not open for further replies.

kidi3

Full Member level 1
Joined
Mar 31, 2013
Messages
98
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,350
I am the moment trying to move a stepper motor.

It moves, but makes a lot of noise while moving, so I must be doing something wrong.

I was told to ramp up the stepper motor, which in my head seems simple enough. I mean its basically a signal frequency being increased by a constant slope or what?..

I am not sure it's just so simple, google seem to provide me with a lot intimidating formulas, and the ramp up signals are more staircase shaped than linear..??


I am basically asking how do i ramp up and ramp down a stepper motor?
Why is it benefiting the stepper motor, and why isn't it the same a linear slope?
 

Hi,

"Ramp up" and "PWM" are two different things.

Ramp up is related to step frequency wich leads to a proportional rotaton speed (RPM)

PWM is used to control winding voltag and current. But winding voltage and winding current is independent of RPM.

***
Ramp up means increasing step frrequency. With a microcontroller - wich is a digital system - you cant increase it lineaerly. You need to use steps. But the step size can be small, so small that you can´r decide whether it is linear acceleration or small step acceleraton.

Constant acceleration means linear increase of RPM = linear increase in step frequency.
With timer you don´t control step frequency directely you rather control period time T. But T = 1/f or f = 1/T.
--> Linear decrease in T will not linear increase f.

Because T is not linear you need a tbale or some calculations in your software.

Klaus
 
Thanks for the explanation.

There is one thing i don't quite understand...

Linear decrease in T will not linear increase f.

Would f increase linearly with T decreasing linearly?

- - - Updated - - -

Do have any literature, that explains the the calculation, or the usage of tbale?
 

Hi,

Would f increase linearly with T decreasing linearly?
For sure not. As said before, it will follow: f = 1/T.

Table: for a general solution quite difficult. For a particular solution quite simple.

Lets say 0..600 RPM, Motor: 200 steps per revolution. Ramp: 0 to full speed in 10s, 16 bit timer, 8MHz clock source
* Now draw a chart: X axis time 0 to 10s, y axis RPM 0 to 600RPM
* Draw the line from (0, 0) to (10s, 600RPM)
* 600RPM at 200 steps per rev means 600 x 200 steps = 120000 steps per min. means 120000 / 60 = 2000 steps per second = 2000Hz. Max step frequency. Means = 0.5ms per step
* because RPM and step frequency is proportional you can write the frequency at your y axis: 600RPM = 2000Hz, 300RPM = 1000Hz, 150RPM = 500Hz, 30RPM = 100Hz and so on

Lets say you increase the RPM every second (Just for the example, indeed you need much more steps)
* 0s = 0RPM = 0Hz
* 1s = 60RPM = 200Hz
* 2s = 120RPM = 400Hz
* 3s = 360RPM = 600Hz
...
* 10s = 600RPM = 2000Hz

Now the problem with the timer. The problem is the frequency resolution at high frequencies. Let´s say you want a resolution of 5% at 2000Hz.
* 1 / 5% = 1 / 0.05 = 20 (means you need a count value of at least 20 at 2000Hz.)
* this gives a counter input value of 20 x 2000Hz = 40kHz. (desired)
* Counter prescaler: max prescaler = 8MHz / 40kHz = 200. Use the next lower prescaler you have: maybe 128 or 64. Use 128 if you have. I calculate with 64.
* Now you have the true counter input frequency of 8MHz / 64 = 125kHz

Now use the table above and go back from 2000Hz
* to generate 2000Hz from 125kHz you need an overflow every 125000Hz / 2000Hz = 62.5 --> integer rounded = 63 ticks
* 1800Hz: 125000/1800 = 69.4 --> 69
* 1600Hz --> 78
...
* 200Hz --> 625
* 0 Hz --> infinite. The lowest frequency (and RPM) you can generate is with 65536 ticks to overflow: 125000Hz/65536 = 1.9Hz = 0.57 RPM

Mind that 78 ticks to overflow means counting 0 ...77. So your timer_compare register should contain 77 instead of 78. I reecommend to write the table with "1" subtracted from each calculated value.

****************
If you are experienced with programming and interrupts:
The smarter solution: Program an NCO. The output should be the step frequency.
benfits:
* exact frequency (RPM) generation with better resolution, especially at higher frequencies.(the jitter usually doesn´t harm)
* no table necessary
* simple +/- mathematics during runtime
* linear. (No 1/x characteristic)
* simpler and better accelaration / deceleration timing
* smooth step frequency change (no fixed step size. more analog like) all within the ISR
* easy adjustable acceleration / deceleraton adjust

Klaus
 
Could you elaborate on the NCO?


The table you refer to, seems simple, but how do do you ensure that at the given time you have given frequency?

Using 2 timers?
 

I guess i would go with the simple method, as it seem simpler an easier to comprehend than the NCO.

So.. I am microstepping my stepper motor, so archieve a smoother motion.

I decided within 10 second should the motor go from 0 to hz 48000 hz => 900 rpm.

Which means that for each 0.5 s should the there be an increase in frequency of 2666 hz.

Does this seem right or? am i misunderstanding something?
 

Hi,

Microstepping...new information.

48000Hz, 900RPM. 900 RPM means 15 rev/s
48000Hz / 15rev/s = 3200 steps/rev. I assume 16 microsteps.

10s ... and 0.5s per step, obviously means 20 steps.
48000Hz / 20 steps means 2400 Hz/step. Why 2666?

Klaus
 

you are right.. i made a mistake.
 

would something like this work?

this is written on a arduino uno

Code:
int timestep = 1;
    while(1)
    {
      unsigned long startTime = millis();
      while(startTime != 500)
      {  
        digitalWrite(step_pin,LOW);
        delayMicroseconds(208/timestep);
        digitalWrite(step_pin,HIGH);
        delayMicroseconds(208/timestep);
      }  

      timestep++;
    }
 
Last edited:

Hi,

I´m not sure.

In either case it uses 100% of processor power. It can´t react on inputs. And if you program to poll inputs it causes nasty jitter.

--> Generate the pulses with timer/counter hardware (PWM, wave generation..). It needs 0% processing power. Only if you want to change the parameter.

The 500ms (I think you need a smaller step size. maybe 50ms) may be generated by a (another) timer/counter.

***
Microsteps: I don´t think you need it.
Microsteps are good to improve angular resolution. But for high angular resolution you additionally need high timing precision. Both values must meet.
High angular resolution without high timing precision is useless.
High timing resolution without high angular precision is useless.

***
If you are not familiar with interrupts now, then I recommend to learn it.
Once you understood the concept you never want to miss interrupts.

Klaus
 

So.. I am microstepping my stepper motor, so archieve a smoother motion.

Microstepping will not solve the ramp up /down problem unless:

1. at constant clock microstepping will reduce the speed and hence appear to work as ramp up/down;

2. If you use sine wave tables for microstepping, noise may reduce but it will still not be ramp up/down;

3. If the motor is small and the power is low and if you do not mind missing a few periods, then you need not bother too much about ramp up/down;

4. Ramp up means that you start with a low frequency and slowly increase the frequency to the operating level (reverse for ramp down).
 

I do understand the concepts of interrupt... but aren't sure why i should use a timer.
if the problem is that I aren't able to do a analog read within the while loop, (which I have to do anyway), could I just not do it within the while loop?
 

if the problem is that I aren't able to do a analog read within the while loop, (which I have to do anyway), could I just not do it within the while loop?

Presume the processor has enough computing power to perform multiple actions virtually parallel, e.g. reading analog values and generating an accelerated step motor control sequence. Question is how to schedule individual actions.

A delay function is "burning" processor time with no benefit, of course you may use it if no other actions are pending at the moment. But they don't achieve stable timing if other actions are performed intermediately. To time motor steps precisely without being affected by other processor activities, e.g. reading analog inputs, serial communication, whatsoever, you better use a hardware timer. It can be either polled or trigger an interrupt.

Once your step motor has been accelerated to a speed above the start/stop frequency, it's not permitted to perform a step "now or later" without possibly loosing position. Every step must be performed precisely at the pre-calculated time.
 

Hi,

You don´t give informations about your hardware like microcontroller, stepper controller, conections, ...

*****
you may use one timer/counter as frequency generator.
* you just need to setup the registers.
* then you/the program don´t need to do anything. It will send out pulses with the desired (adjusted by setup) frequency.

example: you want to start the motor at low RPM = low frequency.
* let´s say you want to start it with a step frequency of 10Hz
* do all the calculations for the register values.
* Write the reigister values
* immediately it will output 10Hz.
* without interrupts.

You may stop your program now, but the frequency still continues.
You may run a program to update the display.. but the frequency continues.
You may run a communication program...but the frequency continues.

****
Now you want to accelerate the motor.
Linear acceleration means linear increase of step frequency.
Lets say 2Hz every 50ms.
Now you need a timer to generate interrupts every 50ms.
The datasheet tells you how to setup yor timer.
Now you have two programs running: The main loop. And the ISR. Every 50ms the main loop is stopped and the ISR runs. After ISR finished the main loop starts to run from the position it was stopped.
It seems as both programs running at the same time.
Within the ISR just fetch the new "frequency value" from a table (=12Hz) and store the value to the frequency generator register. This maybe takes 20us. Then it returns to the main loop
... main loop is processed. doing whatever you want.
after 50ms the ISR runs again: fetching the next value (14 Hz) from the table and sets the new frequency.
... main loop
ISR
...main loop
ISR
and so on

*******************
Indeed it´s
* a bit of setup for the periferals
* a very short ISR
* and the main loop as you like (with the 50ms interrupt i guess you have at least 99% of processing power available for the main loop)

****************************
****************************
I´d like to give you a simple example for the NCO solution:
Max speed 900 RPM. 200 steps per rev. Full step.
One "speed" variable. 0...255. 0 = stop, 255=900RPM, RPM = n * 900/255 RPM, slowest speed = 3.53 RPM
calculated: max step frequency: 3000Hz
A full period is = 2 x toggeling: Therefore you need 6000Hz interrupt frequency. = 167us
ISR:
* counter = counter + speed
* if counter > 254 then: counter = counter - 255; toggle output
(that´s all)
The ISR is very short. (It has to be very short)
Counter, speed = uint16
Although it is executed 6000 times per second, it maybe uses less than 3% of processing time (with overhead) on a 8MHz clocked microcontroller.

Klaus
 

I can see I have a lot of information that need to be processed..

But I can say that the stepper motor I am using is a pk244-01a 2-phase.
the controlboard is a st330-v3.
 

But I can say that the stepper motor I am using is a pk244-01a 2-phase.
the controlboard is a st330-v3.

I do not understand what we all are discussing if you already have a controller board. The controller board is supposed to take care of all these mundane activities. Most likely your controller board needs some basic signals like pulses, direction, brake etc. By the way, I am not familiar with this particular controller board.
 

It has a dir, en and step signal. en = enable (high when motor is being used), dir the direction. and step is a pwm, where the frequency determines the speed
 

I doubt the step signal is a PWM.

You ramp up the motor by slowly increasing the frequency of the step signal (and the opposite for ramp down).
 

step is a pwm, where the frequency determines the speed
Popular confusion of terms. PWM is pulse width modulation, in most cases with constant frequency. The step input is controlled by a variable frequency pulse signal.

The pulse signal might be generated by a microcontroller's PWM unit, but it carries no pulse width information. Respectively you don't vary the pulse width setting of the PWM module, only the frequency. The frequency need to perform a ramp, as previously discussed.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top