acc dec stepper, why it is so difficult ?

Go To Last Post
27 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello,

 

i'm trying to make a stepper motor acc & dec.

i'm busy now for 2-3 weeks to make it working, but it still don,t work angry

wat is the wright way to do this,

 

my problem is that the motor moves a axle like in a CNC machine. so i have to count the pulse who is given during the acceleration.

 

have anybody a good example for me in C

 

thanksin advance.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lots of Arduino examples, examine the stepper code there for ideas or use one of the libs.
Jim

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

i'm trying to make a stepper motor acc & dec

First, does the motor even move (take steps) at all?...worry about that first before trying accell/decel

 

What do you already have working? 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Oct 4, 2019 - 03:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
Lots of Arduino examples, 

Even before Arduino was a twinkle in  Massimo Banzi's eye, getting a stepper motor working was one of the standard beginner microcontroller projects.

 

So there really should be no shortage of examples to be found ...

 

Atmel have an App Note:

 

https://www.microchip.com/wwwproducts/en/ATmega328 -->  https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en591185

 

dated 2006!

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Getting a stepper to move, let alone accelerate or decelerate, is fairly tricky. Did it 20+ years ago in asm on 8051, before there were libraries.

 

One of the crucial pieces of the puzzle is how you drive the motor, electrically. Thus, the first question: how are you driving the phase windings? This includes supply voltage, motor characteristics (e.g. winding voltage rating, inductance, etc). And what load is connected to the motor shaft?

 

The second piece of the puzzle is the pattern that is used to drive the windings. Thus, the question: what does your excitation waveform look like for basic motion?

 

The third question: how does the motor behave when you apply the basic motion waveform (from question 2) through the electrical driver (from question 1)?

 

The final question: are you using any sort of library? If so, which one?

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the stepper is already making steps. i made a program that acc with 10 steps, but i want more steps (that is no problem) but the code is gonna be much longer.

so i was making it shorter, then i have a problem that i could not solve. and i was thinking,...do i it on the right way ????

later i gonna post the code which was not working.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0



but i want more steps (that is no problem) but the code is gonna be much longer. so i was making it shorter,

Well, hopefully, you are  using some form of a loop to ramp up the step rate...the code itself should essentially remain the same regardless of how may steps or what rate you accell/decel

Acceleration is controlling how many steps you take per second.  Sometimes you do have to be careful about hitting a resonance condition or exceeding available dynamic torque, or dealing with load inertias.

A good reference is Leenhouts book, referenced here:   http://www.multimechatronics.com/wp-content/uploads/2017/04/course-notes/Step-Motors-Introduction.pdf

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The app note and its code posted back in #5 works perfectly.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Stepper Motors have micro stepping

200 steps per revolution in full steps  is typical

To ramp up the speed from zero you combine micro stepping with your ramp up logic

 

so to move say 5 steps starting at a dead stop you switch to micro steps

and smoothly transition to full stepping at a faster speep

 

Here is some information:  https://www.linearmotiontips.com/microstepping-basics/

 

The Geko Drivers I use on my home brew CNC do it automatically based on settings on the driver.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i tried to make this working, but it go wrong on: _delay_us(acc_stepper_speed [temp2]);

how can i make there a wait moment with the dat out of the array ?

 

#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>

#define F_CPU 1000000UL // 1 MHz int osc

int count;

ISR(TIMER0_OVF_vect)
{
	count = count + 1; // = 256 uS
}

int acc_stepper_time [10] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 3600, 4000,}; // every step = about 100 mS
int acc_stepper_speed  [10] = {10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000}; // just numbers for example
int acc_stepper = 0;

int pulse = 0;
int temp1 = 0;
int temp2 = 0;

int main(void)
{		
	DDRF = 0b00000111;
	PORTF = 0b00000000;
	
	PORTF |= (1 << PINF0); // DM556 = 1 = disable
		
	sei();
				
	while(1)
	{				
			PORTF &= ~(1 << PINF0); // DM556 = 0 = enable			

			TCCR0 |=  1<<(CS00); // prescaler = 1
			TIMSK |= 1<<(TOIE0); // over flow interrupt enable
						
			for (pulse = 0; pulse < 1000; pulse ++) // number of pulses i need
			{
				if (count < acc_stepper_time [temp1]) 
				{
					PORTB |= (1 << PINB5); // pulse to stepper driver = 1
					PORTB &= ~(1 << PINB5);	// pulse to stepper driver = 0
					_delay_us(acc_stepper_speed [temp2]);
				}
				else
				{
				temp1 = temp1 + 1;
				temp2 = temp2 + 1;	
				}
								
			}				
	}	
} 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dont you need to set up the interrupt registers once and then use SEI;

You are writing the TCCR0 and TIMSK inside the while loop.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i think you right, but that is for the fine tuning, when the method works.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used to write code for fruit machines/slot machines. Amongst other things.

Getting the reels to start and stop in a desirable fashion was very, very tricky. Probably because the stepper motors were not really big enough for the task, or becuase the idea was to emulate the old fashioned mechanical reels. However, the timings were critical, and stopping suddenly often required a step or a half step in the opposite direction. Real black magic stuff - simple ramp up, ramp down was no use at all. Basically, once you had a working timing sequence, you didn't screw with it.

 

Four legs good, two legs bad, three legs stable.

Last Edited: Fri. Oct 4, 2019 - 07:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

trixo wrote:

_delay_us(acc_stepper_speed [temp2]);

Doesn't _delay_us() need a fixed value at compile time, rather then a variable in the call?

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

but what is the best way to create a delay, on that place ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

trixo wrote:

but what is the best way to create a delay, on that place ?

 

Timer that triggers an interrupt or just returns from a call after time expired.

If you use a timer interrupt then you can call the next motor move while computing other stuff for a smooth ride.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

but i like to use a array. edit: but maybe its possible.

 

edit: i see now that i never make count == 0

Last Edited: Fri. Oct 4, 2019 - 08:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unless you need fast-changing speeds, accel & decel are quite simple.  First, get your routines to step at any desired commanded speed, say 5 rpm, 22 rpm, 80 rpm, whatever. 

Once that is working, instead of a fixed speed you can vary the commanded speed over time...say from 2 rpm to 20 rpm over the course of 5 seconds, as though you were simply turning up the speed control "knob".  It gets more difficult if you need to change speed faster than within a few steps.   Start simple & work your way up! 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Oct 4, 2019 - 09:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Why are you reinventing the wheel when working code exists?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is one I worked on a while ago.  It came with my arduino kit.  The pins drive ULN2003 then to the motor windings.

I don't remember what PIN5 is for, maybe an LED.  You should be able to accelerate and decelerate by changing the _delay_ms() call which requires constant to your own delay which can vary to provide acceleration.

 

/* stepper motor demo */
#include <avr/io.h>
#include <util/delay.h>

#define BLU_DDR DDRB
#define PIK_DDR DDRB
#define YEL_DDR DDRB
#define ORG_DDR DDRB

#define BLU_PORT PORTB
#define PIK_PORT PORTB
#define YEL_PORT PORTB
#define ORG_PORT PORTB

#define BLU_PIN PORTB0
#define PIK_PIN PORTB1
#define YEL_PIN PORTB2
#define ORG_PIN PORTB3

volatile uint8_t pos;

/* motor: 28BYJ-48
 *
 *   BLU PIK YEL ORG 
 * 0  0   0   0   1
 * 1  0   0   1   1
 * 2  0   0   1   0
 * 3  0   1   1   0
 * 4  0   1   0   0
 * 5  1   1   0   0
 * 6  1   0   0   0
 * 7  1   0   0   1
 */
void step_fwd(void) {
  switch (pos) {
  case 0: YEL_PORT |= _BV(YEL_PIN); break;
  case 1: ORG_PORT &= ~_BV(ORG_PIN); break;
  case 2: PIK_PORT |= _BV(PIK_PIN); break;
  case 3: YEL_PORT &= ~_BV(YEL_PIN); break;
  case 4: BLU_PORT |= _BV(BLU_PIN); break;
  case 5: PIK_PORT &= ~_BV(PIK_PIN); break;
  case 6: ORG_PORT |= _BV(ORG_PIN); break;
  case 7: BLU_PORT &= ~_BV(BLU_PIN); break;
  }
  pos = (pos + 1) & 0x07;
}

void step_rev(void) {
  switch (pos) {
  case 0: BLU_PORT |= _BV(BLU_PIN); break;
  case 1: YEL_PORT &= ~_BV(YEL_PIN); break;
  case 2: ORG_PORT |= _BV(ORG_PIN); break;
  case 3: PIK_PORT &= ~_BV(PIK_PIN); break;
  case 4: YEL_PORT |= _BV(YEL_PIN); break;
  case 5: BLU_PORT &= ~_BV(BLU_PIN); break;
  case 6: PIK_PORT |= _BV(PIK_PIN); break;
  case 7: ORG_PORT &= ~_BV(ORG_PIN); break;
  }
  pos = (pos + 7) & 0x07;
}

int main(void) {
  uint8_t cnt = 0;
  
  DDRB |= _BV(DDB5);
  
  BLU_DDR |= _BV(BLU_PIN);
  PIK_DDR |= _BV(PIK_PIN);
  YEL_DDR |= _BV(YEL_PIN);
  ORG_DDR |= _BV(ORG_PIN);
  
  for (;;) {
    _delay_ms(20);

    cnt = (cnt + 1) & 0x07;
    if (cnt == 0) PINB = _BV(PINB5);
    
    step_fwd();
  }
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John_A_Brown wrote:

I used to write code for fruit machines/slot machines. ... and stopping suddenly often required a step or a half step in the opposite direction.

 

I thought that was sort of the point.  The idea being that it might, accidentally, pay off, so you throw in another step or two one way or the other to bring up a lemon...  cheeky

 

But yeah, nice trapezoidal velocity profiles are a little more tricky than some.  Regularly decrementing an inter-step delay will lead to highly non-linear velocity profiles (at the ends, anyhow).  Of course, with steppers, few care.   Matters more when you get into real servo motors.  S.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
Why are you reinventing the wheel when working code exists?

 

where can i find these ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go on - have you not been reading the posts in this thread?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i realize now that i didn't mention that i use a stepper driver the DM556 (leadshine) sorry for that (you could see this in my code smiley)

 

the AVR446 is for stepper directly connected to the atmega (no driver).

Last Edited: Sat. Oct 5, 2019 - 05:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

trixo wrote:

the AVR446 is for stepper directly connected to the atmega (no driver).

 

The code which drives the motor is split into a separate file so it is trivial to modify it to use a separate driver chip. In my case I use it to drive a chip which has STEP and DIR inputs.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you already have a full stepper motor control system, then what is the problem?  They already give you several ways to take steps. Your description is rather lacking.

 

The driver you have uses a full DSP control system and has sophisticated adjustments ready for use:

 

By implementing the latest motion control technologies, Leadshine's DM series DSP-based stepper drives deliver excellent performance not available before. Unique features of extra smoothness and excellent high speed performance make DM stepper drives deliver servo-like performance at the cost of stepper drives. They are capable of delivering high performance without damages to your machines or the materials. Leadshine DM series stepper drives are able to drive 2-phase or 3-phase stepper motors from NEMA8 to NEMA42.

Electronic damping coefficient setting,

Anti-resonance parameter settings for 3 resonance area,

Parameter settings for self motion test or a simple application,

Read the latest 10 failure events and clear these events

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!