stepper motor logic

It's all about the code!
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

stepper motor logic

Post by AndreyB »

Just got another request for a stepper motor IAT so I am planning to write some code today and/or tomorrow. First order of business is an abstract stepper class which would later be used by IAT and probably for external needle gauges via CAN by a separate chip.

In my understanding I am controlling the motor by sending out a number of pulses into one of the control wires while tracking the expected position of the motor.

Question one: initialization. Do I understand it right that on start-up I would need to move a complete turn say to the left just to know that I am in the zero position? Is that the way a needle or IAC would be initialized? It's not like there is an IAC position sensor.

Question two: pulse timing. How long should the pulses be and how long should the gap be? Should that be configurable or are these all exactly the same? I guess some stepper motors should be different so probably configurable? What would be a good default value?

Status update: it works!
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: stepper motor logic

Post by kb1gtt »

Stepper motor board found here for under $25 usd http://www.gadgetfactory.net/papilio-wings/ It uses the typical step and direction TTL signals.

Steppers generally do not have feedback. You pulse the motor and hope it made it. If it does not, then you can have a control algo that will send additional pulses. The feed back would be something like O2 reading claims the mixture is rich or lean. The stepper circuit generally does not have direct electrical feedback.
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

kb1gtt wrote:It uses the typical step and direction TTL signals.
Which datasheet should I look into for more info on the typical TTL signal? I really do not want to end up sending the signals too fast.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

the frequency depends upon the stepper, so it better be ajustable.
what are the benefits of those drivers? just saving few pins? we don't have 4 spare pins on discovery for the simplest implementation?
i didn't getabout can - you want to get a diy cluster panel?
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: stepper motor logic

Post by kb1gtt »

Looks like my link didn't work as expected. This one should be more direct.

http://papilio.gadgetfactory.net/index.php?n=Papilio.1-AxisStepperMotorControllerWing

It uses an allegro A3979 or TI's drv8811. Typically the speed isn't determined by the driver ship, but by the stepper, and the current it can handle. My shot from the hip guess would be that you want steps that range from 10 pulses per second to 1000 pulses per second, with the typical pulses per second being around 200.

I would suggest using a driver chip, as direct driving can get complicated when you start dealing with micro-stepping, and when you start dealing with preventing transistor overlap. Remember your Ton and Toff times vary, and you can't have the Toff time overlap the Ton time of the other transistor. That would end up in dead short for short periods of time. For a small amount of $ in hardware, you can prevent the need for hours of software labor.
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

puff wrote:i didn't getabout can - you want to get a diy cluster panel?
I personally do not, but the stepper API should be useable not only for IAC I believe, maybe FSIO. Actually ye, it would be cool to allow FSIO to control a stepper one day!
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

i don't get that idea - what's the use of it and what's the fun? guy carpenter made an arduino code for cluster steppermotors with accel-deccel, etc. but i don't see any sense in incorporating this stuff in rusefi.
anyway, i got a simple chip with four inputs and four outputs for driving stepper motor. initially the plan was to make a simple device with adc ( your solenoi pwm as input) and simple stepper control. for some reason jared doesnt like those cheap soluions and suggests some pricey board. there were some 5$ chips of the same family with step-dir contol anyway... (the pile of unused chips is growing :-)
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

Haldex, from what I understand, uses a stepper motor to control how much power is sent to the rear wheels.
Yep, definitely FSIO stepper control.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

so, now the most interesting part - will it be implemented in two-wire or four-wire logic? :-)
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

puff wrote:so, now the most interesting part - will it be implemented in two-wire or four-wire logic? :-)
Right now I am implementing a two-wire setup simply because someone has donated the hardware and I can focus of the software.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

that's great! then, i'd look for the available step-dir drivers (any recommendations?)
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

[video][/video]
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

what are those boards you are using? have you checked the outputs with logic analyzer? might be the motor of a different type?
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: stepper motor logic

Post by kb1gtt »

That's http://www.pololu.com/product/2976 with a Pacific something or another stepper motor. I'm assuming MS1 to 3 are disconnected, which I believe floats low, so full step configuration.

Have you set the current limit via that POT? If we don't know the motors ratings, we can guess at .5A to 1A.

Can you take the wire connected to 2A and connect it to 2B, also take 2B and connect to 2A. AKA flip one winding at a time.

Also can you start with very slow steps, say something like 1 pulse per second, or perhaps one pulse per .5 seconds. Once you get it working very slowly, you can start to speed up the pulses to see how fast you can get it to go. You'll find that at some pulse rate you'll stall the motor.
Welcome to the friendlier side of internet crazy :)
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

btw, what is the code you are using? loos as if you are changing direction once a second. no jittering on video. jareds suggestion on decresing the frequency could also help.
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

https://svn.code.sf.net/p/rusefi/code/trunk/firmware/hw_layer/stepper.cpp

200ms pulses, there is no direction control whatsoever - DIR pin is ground. It would help if you can compile this (you would need to uncomment a line in hardware.cpp) and publish a screenshot of logic analyzer - maybe the code does not work, but I doubt that.

I've played with the potentiometer and it made not difference.

There was a suggestion about flipping the wires, I just did that. Same crazy jerking but no movement. The control board gets REALLY hot REALLY fast.

I am putting this on hold until someone figures out a reliable test platform - I am sick of doing hardware troubleshooting, I am a software guy actually. I've implemented the pulses, the pulses do not control this stepper.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

you are speaking of this one?

Code: Select all

	iacMotor.initialize(GPIOD_11, GPIOD_10);
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

Typical case of http://rusefi.com/wiki/index.php?title=40 (todo: need to translate this joke into English)
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Number-One
contributor
contributor
Posts: 101
Joined: Sun Jan 05, 2014 2:59 pm

Re: stepper motor logic

Post by Number-One »

russian wrote:
puff wrote:so, now the most interesting part - will it be implemented in two-wire or four-wire logic? :-)
Right now I am implementing a two-wire setup simply because someone has donated the hardware and I can focus of the software.

4 wires please :P
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

4 wires shouldn't be any more complex, but that would require 4 pins instead of 2 on the micro controller side, which could pose sort of a problem.
I'd also love to have 4 wires implementation (I got l293 and a stepper to check if it works right now ;-)
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

Same board, but different motor - this one is five wire (four wires go to the board and goes to power supply)

[video][/video]

Who wants to donate a real car stepper idle body?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

PS: the original stepper motor is now also function. I am a lazy idiot, that was the problem.

On the old vider @ http://rusefi.com/forum/viewtopic.php?f=5&t=767&start=10#p13226 at 0:14 you can see that I only got two wires connected - I've assumed that having one coil would be enough to turn the stepper into one direction. Apparently that's not right, once I got four wires connected as should the issue got resolved.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: stepper motor logic

Post by kb1gtt »

A day when you burn oxygen and learn something is a good day :) At least it didn't smoke something. Those learning experiences are more expensive.
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14325
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: stepper motor logic

Post by AndreyB »

russian wrote:Who wants to donate a real car stepper idle body?
Got a donation - just placed an order for a GM stepper IAC and pigtail.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

Once again, what are the cons of directing drivers directly from the discovery board?

http://www.ti.com/product/sn754410
http://www.ti.com/lit/ds/symlink/sn754410.pdf

I got L293, but this seems to have some limitations in terms of operating temperature.
This would simplify the board, save some space and money.
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: stepper motor logic

Post by kb1gtt »

What are the pro's? The A4988 is basically a H-bridge, but with some internal logic that implements features including micro stepping, current limiting, overlap prevention, ect. If we direct drive, many features will need to be built and software debugged. If we buy the chip, we can spend the limited software development time on other features.
Welcome to the friendlier side of internet crazy :)
DaWaN
Posts: 51
Joined: Sat Sep 20, 2014 6:54 pm
Location: Benschop, Netherlands

Re: stepper motor logic

Post by DaWaN »

kb1gtt wrote:What are the pro's? The A4988 is basically a H-bridge, but with some internal logic that implements features including micro stepping, current limiting, overlap prevention, ect. If we direct drive, many features will need to be built and software debugged. If we buy the chip, we can spend the limited software development time on other features.
The pro's of using the SN754410:
-Really very cheap part and easy to source
-Outputs of the SN754410 can be easily repurposed

Both points are a big plus if building a fully integrated universal ECU. The SN754410 can be used to drive a high side relay (I recall the MX-5 has one) or something like a VTEC solenoid (altough it is a bit to weak for actual VTEC) and I also remember a weird Toyota IACV which needed some H-bridge-like driving (4A-GE has this thing I think) and the SN754410 can drive that too.

For the time being I agree with kb1gtt, but if RusEFI gains traction and there is a need for universal cheap ECU hardware instead of the many-board-DIY style being used now then the SN754410 makes sense. However, at the moment that is not the focus of rusEFI I think :)
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

A4988 datasheet says:
Operating Ambient Temperature TA Range S –20 to 85 ºC
as for pros, the support of four-pin stepper control in the firmware would allow people to build their own boards with various chips: STA508, STA509A, SN104690, TPIC2601, or even using discrete components, such as IRLML2502, IRLML0060 or IRLL024.

which exactly features you are talking about? i hardly imagine micro stepping is ever needed in automotive applications (I guess it's more of a cnc domain)
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: stepper motor logic

Post by puff »

one more idea. what if we make a line in engine config, which would determine if it it would be 4-pin or step-dir control?
Post Reply