A lot of the top end Microchip PICs have integrated ADC and PWM hardware for this sort of job...
I would like to discuss the posibility to build a microcontroller based stepper motor driver able to drive bipolar motors in microstepping mode.
Specs of driver :
- cost effective solution composed by a microcontroller and 2 Fet based H-Bridges
- PWM driving (not current chopping)
- start point schematic is Mariss's schematic from thread http://www.cnczone.com/forums/showth...=24699&page=54 (New Allegro Bipolar Stepper Driver A3986)
- How to set up the fill factor of of PWM ? Would be suitable a PID function in this case ? Usually PID function thakes as input the error (defined as difference between desired value and measured value ) and sets the drive value. In this case when desired coil current it is evaluated trough a simple comparator I think that it is not applicable. Would be necessary a very fast ADC.
- It is mandatory PID on PWM ?
- What microcontroller would be suitable for this job ? (only cost effective solution that comes to my mind is at90PWM2/3 has integrated PowerStageController - pwm with programable deadtime )
A lot of the top end Microchip PICs have integrated ADC and PWM hardware for this sort of job...
Irvin, thank you for pointing me to that direction (I don't know why I'm staked on Atmel products).
Looking trough their list of motor control dedicated products (http://www.microchip.com/ParamChartS...g=en&pageId=75) I tooked as example : dsPIC33FJ32MC202 .
From datasheet results that ADC can do :I wonder if 1Msps ADC on coil current would be enough to drive a stepper motor.10-bit, 1.1 Msps or 12-bit, 500 ksps conversion:
- Two and four simultaneous samples (10-bit ADC)
If 2000 steps per second would be an acceptable performance then the ADC would have 500 samples per each step + time needed for calling PID function and changing fill factor of PWM.
The dsPIC33FJ32MC202 is an overkill for this task.
Mariss does not use PI or PID to control phase current, for the simple reason that there is no A/D conversion and the CPLD he uses does not have the resources to implement PID or PI control. He uses a fixed frequency chopper, although he does not want to call it a chopper, all choppers are PWM (even when some of them have variable frequency).
How are you planning to deal with current decay?, Mosfet turn on and reverse recovery switching transients affecting the results of A/d current measurements?
It would be a good learning experience.
IR2104 does not have separated high and Low side input signals, and has fixed dead-time. Using the Atmel At90PWM2/3 controller is going to be a waste of resources unless you change the Mosfet half bridge driver.
I think that controller will be very busy doing only 20Khz PI control of current, what kind of math are you planning to implement? fixed point, floating point, integer only?.
Last edited by kreutz; 01-09-2009 at 12:33 PM.
1. Microchip says that dsPIC33FJ32MC202 is $2.59 for volume - so it's god for our purpose
2. Chopper's freq is depending also on supply voltage ... Chopper=PWM ? debatable . I think that Mariss want's to have fixed frequency on both windings and variable fill factor. Also he already explained that because of chopper's different freq in windings, motor starts to "sing".
3. BEMF ! - good quetion ! in this moment I don't know what to answer to this. Anyway if it can be found a way to analyze the BEMF we can find out some informations about the load of motor and the point where it is about to stall or to enter on resonance.
4. Procesor load : processor load it is big when the error (diference between desired and measured value) it is big. I intend to implement the following procedure : at the very first time after board power, when it is made a first complete cycle of microsteps i intend to have an array where to store values found by PID function for each coil + each microstep. At the next steps those values will be send from begining to pwm - this way the error will be smaller and load of cpu also smaller.
I would be tempted to try integer only math (thinking that we need as much speed as possible).
I still need advices if it is feasible to implement pid over adc from coil's current. 1Msps ADC would be enough ?
Beautiful part here is that if such a board would be made, would be possible to drive stepper motor or servomtor.
I think that we need Mariss advice on this ideea.
I have started to read the Application Note AN532 . Until now it confuses me : says that contol loop can go up to 2khz and the time needed for pid calculation it's 200ms. that's huge and it cannot be used to make pid pwm stepper driver
I implemented a complete translator with multiple micro-step modes on a 2K of Flash, 128 bits of RAM, $1.00 Attiny2313-20. It is used on a 48V 5Amps bipolar Micro-stepper drive, as well as on an 80V 8Amps unipolar micro-stepper drive with ZERO Noise, both work at 100K steps/sec. Both designs are discussed on the respective threads and blogs, even provided the source code, PCB designs and schematics.
I don't intend you to follow on the same path, but maybe my implementation could give you some ideas. The PIC DSC is more than enough to do what you intend to do, a DC motor controller is something completely different from a stepper controller, so that AN will not help much.
About the chopper versus PWM debate. If you don't understand what they are and what the similitude (or difference) is, it is difficult to use any of them on your design. PWM is a pulse modulation technique, it does not have anything to do with PID, except that some PID controllers employ PWM as control output, the same way other PID controllers could give you +/-10v output.
About PID controller load, it does not depend at all on the error size. The error is only one variable on the chosen PID algorithm. It does depend on the math employed (fixed point, floating point, integer) and the number bits assigned to the variables and coefficients (precision), as well as the capabilities and speed of the processor itself. The DSPIC is fast enough for a fixed point (Q15) PI loop running at 20 Khz.
I've played with a dsPic some time ago, but I was verry dissapointed by the ADC module. Allthrough can be configured to 1Msps, I couldn't use-it for signals faster than 10kHz (ADC values were wrong...)
Fast and accurate ADC with Microchip is not for beginners. You must learn wery well how pic is working, and what can you disable while reading analog values.
But if you want to try, will give a help, if we can
Kreutz, first of all thank you for giving feedback on this idea, I look on your 2313 design immediately. (comparing myself with you or Mariss I'm weak in stepper driving so, I have a lot of things to learn).
Also I have to comment a little / or better said to add some more details :
.DC motor controller is something completely different from a stepper controller, so that AN will not help much
Very basically a stepper driver consist in 2 synchronized regulators who take care to have an amount of current trough windings.
When I say regulator I mean :
1. one device to measure the resulted output value, value which will be used as feedback
2. decision mechanism which: a) take in account desired value and measured result from point 1 ; b) decides about action that should be made and send this decision to no 3
3. Power Stage
Everywhere where is a regulator should be a PID function in no 2 - Decision Mechanism.
All designs that I have seen for driving stepper motors are based on a simple comparator. I consider this as the point where improvement has to be made.
Indeed PWM it's the working mode of power stage.PWM is a pulse modulation technique, it does not have anything to do with PID
That's correct. What I was willing to say is :About PID controller load, it does not depend at all on the error size.
1. in the first on pwm cycles error will be big and PID procedure will be called.
2. after few iterations will be found the correct fill factor of PWM. when all pwm values coresponding to desired winding current are known , error will be small enough to avoid calling PID function.
Yes, the majority of the stepper drives use "bang-bang" or chopper control, which is the term applied to a Proportional controller with infinite gain. The system works fine because of the L/R time constant of the Motor coil. The coil current could not have sudden changes due to the inductive nature of the winding.
In this way the stepper coil regulator is equivalent to a DC/DC Buck regulator, and the same general techniques are applied for current control. There are nevertheless some differences when taking into account current decay modes.
The currently employed current regulation technique does a wonderful job and is simple (and fast) enough, main factor here is: You setup a reference value for the current, it does not matter which motor or power supply dc voltage. The proportional control (chopper) will try to regulate the current and will do a great job modulating the duty cycle value in order to regulate the coil current while the drive acts as a current source (below 100% duty cycle). The problems start when the drive begins to act as a voltage source after certain speed due to the L/R time constant and BEMF (with constant DC voltage).
If you were to design a PI type of control, it will behave about the same, because you are not acting against the limiting factor, that is the L/R and the effect of the BEMF. PID is not required because the controlled variable changes relatively slow vs time (due to the inductive nature of the motor winding). Now you have a big problem: PI loop tuning for different motors and different power supply voltages, hence the competitive dis-advantage. Here goes the No, regarding to "improvements could be made".
If what you are trying to accomplish is only to eliminate the sub-harmonic instability, there are other simpler ways employed in the DC/DC controller's industry for quite some time: The use of a "Blanking time" and Slope-compensation, which by the way was not invented by Mariss or Me, it has been there for a long time, just not used on stepper drives.
A well calculated or adjustable Slope-compensation will take care of another disadvantage of the chopper technique, it will compensate against the change of average current value vs duty cycle, which is inherent to the Peak limit current regulation mechanism, so the regulator circuit becomes an effective average current regulator when properly employed (adjusted for 50% duty cycle).
If you want to go deeper into solving the problems of the L/R and BEMF effects at high speed, then there are also other techniques that have been developed, between others: Dual voltage drives and Field Oriented Control (flux vector) drives (including field weakening), that is what Mariss working on now.
Last edited by kreutz; 01-10-2009 at 02:59 PM.