Pages: [1]   Go Down
Author Topic: simple stepper speed control  (Read 1797 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am surprised I can't find a good library for this pre-written.  Clearly it is a solved problem based on Reprap printers everywhere using steppers. Anyways I need a bit of guidance, or better yet example code.  I need to control 2 stepper motors, speed only not elapsed steps.  I also need to be able to do serial communication and read some sensors, so the stepper control can not hold up the whole processor.  I have  pololu stepper drivers, so the electronics side is solved.

How do I get a continous pulse train coming off the arduino of variable frequency, without blocking everything else? it sounds like I need to learn to interface directly with the timers (I know I can learn it, I just want ot make sure it is the  best way of doing it before getting too carried away.)  Again I am REALLY surprised I have not turned up any pre-existing libraries for such a thing, as it seems fairly simple and EXTREMLY common.

Thanks guys.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Again I am REALLY surprised I have not turned up any pre-existing libraries for such a thing,
Why? Do you like doing things other people have done?

Quote
Clearly it is a solved problem based on Reprap printers everywhere using steppers.
There are many solutions in the RepRap world, why does everything have to be a library?

Quote
How do I get a continous pulse train coming off the arduino of variable frequency, without blocking everything else?
You use a timer to generate regular interrupts and then in the interrupt service routine you can either step every time it is entered and control the speed through altering the frequency of the timer.
OR
Increment a 16 bit counter with some value and only step when the counter overflows a certain bit, like when the most significant byte changes. That way you get to control the speed by changing the increment value.

Quote
I need to control 2 stepper motors, speed only not elapsed steps
You have no choice, it is a stepping motor, you control the steps. It sounds like you have the wrong sort of motor for your project.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No steppers are the right thing for this project (for now, it's complicated/in flux).  I guess what I meant is I don't see any examples of it that I can understand enough to copy.  I have been going thru Marlin firmware for over 3 weeks now trying to understand it or reverse engineer it, and am coming up empty handed, it is simply beyond my abilities, for now.

My original point was I dont WANT to do somethign that is already done,  I simply have yet to find somethign that someone else did that is
a) "non blocking" or effecient
b) not smarter than me (IOW, I can actually understand and implement it)

the best I have found so far is to use this hiere
http://arduino.cc/playground/Code/Timer1
since I only need two motors, I can dedicate a timer to each on my mega, but holy overkill batman, and what a waste.  atleast untill I come up w/ a brilliant other plan where I can use 1 timer for 2 or 3 steppers.

the only good exmaple I have seen is this here
http://arduino.cc/forum/index.php/topic,49959.0.html
which will slow down the motors if other things are going on between calls, and since I am doing other things, it is no good to me. 
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
atleast untill I come up w/ a brilliant other plan where I can use 1 timer for 2 or 3 steppers.
There is nothing to stop you using the technique I described for more than one motor.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand that and feel confident I will see succeess by noon tomorrow at the lastest.  At this point in my arduino career  I feel safe in that regard.  I am just still surprised I didn't find it spelt out for me somewhere online, you know? I would expect it to be like servos and making tones etc, that the whole arduino thing is plenty mature enough that this should simply already exist and I am being a dunce re-inventing the wheel.  I expected the first reply to be "there are thirty tutorials right here (link)".]

edit, I am not posting that asking you to hold my hand thru this or whatnot, just expressing surprise.  Sadly I know I am no wehre good enough to write something up myself that anyone who speaks english could follow.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

huh, this isn't playing out the way I thought it would.  I have some fuzzy psuedo code that will not work well as the lowest speed stepper gets odd step speeds, bad plan on my part.  I am trying to start over, but am stuck in my old ideas.  How can I control multiple motors with a single timer? 

I am writing code that will use 1 timer per motor, but as I said, that is a huge waste and I might as welll jsut use the Tone library.  I need something that works NOW, but want very much to completly re-write it with something better when I have a better idea.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use the code I have written here on this forum, and modify it yourself.  I have written instructions in this post how to make it work non-blocking with 2 or more motors.  It's all in here reply #24.  The code is on Gist.

http://arduino.cc/forum/index.php/topic,89159.15.html
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1024
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using 1 interrupt routine, 2 counters, and look at Direct Port Output  = http://arduino.cc/en/Reference/PortManipulation =

And you might take a look at this thread = http://arduino.cc/forum/index.php/topic,84809.0.html = It is how to code a stepper driver - the code is interrupt driven, 1 axis, goes through several stages, Starts out using digitalwrite, goes to direct port manipulation and finishes up being done completely in assembly. look at the first 2 steps and it should give you some ideas. Adding a couple of counter variables, when they hit some target number, do the next step and reset the counter.

Remeber - in an interrupt keep the code tight. Nothing unnecesary.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it's a little scary, but I have ideas.  I will flesh them out to actual code before posting again.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@permnoob- Can I help you by modifying my code for you?  Any improvements I make would be great for me too.  What is my code missing?  Did you look at it?  See how easy it is to run 1 motor non-blocking?  Try it!
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Full Member
***
Karma: 0
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am INSANLY busy and am actually using the tone library right now because I don't have time to do this right just yet.  However you really should host this on github, so I can grab it and possibly fork it.  It sounds like you have a lot of functionality I don't need, but since you were smart enough to includethem, I bet you did a good jobe w/ the core functionality. 

Put it up on github, and I'll test the hell out of it and probably fork it to make a minimalist version.  Since I will be using a stepper driver I won't need things like the current limiting etc.  I have yet to actually look at your code tho, rather than risk grabbing an old version from ur thread, I would love to see it up on github.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Stupid website keeps crashing.  It's on Gist.  Read this topic.  Scroll down.

http://arduino.cc/forum/index.php/topic,85335.30.html
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Pages: [1]   Go Up
Jump to: