Monday, January 18, 2010

Can anybody write c programming in order to control a motor?

I need a c program that with control a motor through an ADuC 832 Analog Devices board converter with High Voltage (8051 microcontroller). This motor has to be able to do 90 degree turns as well as being bi-directional. It also has to do a full 360 degree turn without stopping if thats possible. If any of this is possible that would be great, I just need a startCan anybody write c programming in order to control a motor?
It sounds like you want to control a robot arm or similar. The motor would use a gearbox to get more torque and reduce the speed. I assume you are talking about a DC permanent magnet motor. You need a motor driver. Typically this would be a H Bridge with 4 Power MOSFETs and catch diodes rated at the motor's maximum current, and voltage. You also need a potentiometer or other angle sensor for position of the output shaft. Most potentiometers are 270 degrees, but there are continuous rotating types that go close to 360 degrees. There is a small gap between 360 and 0 degrees, usually about 5 degrees. This needs to be biased to 360 or 0 degrees. Another possibility is a multiturn potentiometer, like a three or 10 turn model. You need to consider the lifetime ratings (number of operations).





Interface the potentiometer...


The potentiometer is supplied with a precision (stable) voltage, perhaps 5V and its wiper is interfaced through a non inverting buffer (op-amp) to the A/D converter input of your board. It can have a gain to adjust the scale, and an offset if that is required, applied to the inverting input.





Interface to the H Bridge...


Two logic level digital outputs drive the H Bridge, one for forward, one for reverse.





Software...


The software implements a position servo. The software driver is a loop that reads the ADC for the position of the output shaft. The reading from the ADC is perhaps 0-4095 counts, representing the angle. The setpoint (in the same units as the ADC) is stored as a variable. Subtract the setpoint from the position. Branch if - to the reverse motor routine, if plus to the forward motor routine, and if close to 0 to the stop routine. This can be refined by having a branch to slow down when getting close.





Pulse Width Modulation...


The digital control for the motor speed is by varying the ration of ON to OFF time of the port at a few hundred Hz to a few KHz. This depends a bit on the motor. The direction depends on which arms of the H-bridge are activated. The best way to do this is with an I/O device called a PWM port, but the chip you mentioned doesn't have one. You can use timer interrupts, or just count the times around the loop previously mentioned to get these ratios.





Other motor drivers...


You can use the analogue output (DAC) on your board with a driver amplifier. This is something like an Audio Amplifier with DC coupling. Thus its output can be positive or negative from the common rail, to reverse the motor.





You can buy motor servo drivers that just need the set point to be sent to them (using the DAC), or a serial port. Similarly you can make a complete proportional analogue servo driver yourself with a driver amplifier and a couple of op-amps. This has the advantage that the servo control does not take up microprocessor resources. Tell it where to go, and that is all. Maybe monitor to see when it gets there.





Other solutions...


If it is a larger motor, you can but a 3 phase motor and gearbox and drive them with a suitable VFD (variable frequency drive) from single or 3 phase mains. You need one that can do the position servo function.





You can use a stepper motor. There are numerous tutorials about these on the internet. Be aware that the torque tends to be low, so you need that gearbox, and a reference home position as the software just counts steps. The position feedback is no longer necessary. The motor drivers are a little different. The motor themselves tend to need to be bigger than a DC motor, which is probably the best way to go.





You can buy radio control servos of various sizes which have a 90 degree rotation. Position angle is controlled by a pulse period of 1-2ms. This is updated/repeated every 20ms or so. Very easy to use. The 90 degree angle can be increased by lever arms (pushrods, horns).





If you give more details (the big picture, what you want to do, your resources) you will get better advice. You can search for most of the things I mentioned using the key words mentioned. After a while it will become clearer. You can find C code for stepper motors (try PIC stepper motor software), but not clear whether that will suit your needs. Once you have a clearer picture you can probably find snippets of code to read the ADC, use interrupts etc. Feel free to email me if you need better explanations.

No comments:

Post a Comment