I want to control the motor using PIC24FJ512GA606.
There are two motors. Two motors have wires wound around the wheel. I want to wind the same length on both wheels. A The motor runs at constant speed, where the rotating value is read as a pulse by the photosensor. The other motor B must rotate at the same speed depending on the speed of motor A. Because it is wound on the wheel, the pie changes as the wire is wound.
I think use DSP PID.
However, I've seen example programs, but I don't know how to use the PID component.
The photosensor generates a pulse and receives it as an IOC.
Please help me.
Thank you.
two Motor control help me!
-
- Posts: 206
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 1:43 pm
- Has thanked: 5 times
- Been thanked: 7 times
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: two Motor control help me!
Hello,
A PID controller might do well to help you with this.
You would basically have the absolute encoder count of the first motor as your setpoint. The absolute encoder count from the second control motor would be your feedback value. The control value would likey be some sort of analogue output to the motor, probably PWM.
You would then need to scale P, I and D to get a stable response. Maybe start with P control only and then once this is working ok move to PI to try and elliminate any steady state errors and see how you get on the D term might not be needed.
P is propotional gain and is designed to respond quickly to error. Be fairly generous with this and if things are unstable then you're being too generous.
I is integral gain and is designed to reduce offset over time to actually get you to the setpoint. Be gentle with this and try small increments.
D is derivative gain and is used to dampen the rate of change allowing you to increase the P and I terms and get there faster, this is probably the hardest one to balance as it effects the other two terms.
Have a go and if you're struggling then post your project file so far and we can try to help.
Maybe try initial values of 10 for P and 0.001 for I.
You could substitute absolute encoder count with motor rate if that makes things easier, this is less likely to eventually roll over if you are turning the motor for a long duration but may introduce more differential error in the short term.
If you want to know the maths then this is the simplified form of the PI controller, this sum repeats everytime you call the PID control function.
Error = Setpoint - Feedback
P = PGain * Error
IAccumulator += Error
I = IGain * IAccumulator
Output = P + I
A PID controller might do well to help you with this.
You would basically have the absolute encoder count of the first motor as your setpoint. The absolute encoder count from the second control motor would be your feedback value. The control value would likey be some sort of analogue output to the motor, probably PWM.
You would then need to scale P, I and D to get a stable response. Maybe start with P control only and then once this is working ok move to PI to try and elliminate any steady state errors and see how you get on the D term might not be needed.
P is propotional gain and is designed to respond quickly to error. Be fairly generous with this and if things are unstable then you're being too generous.
I is integral gain and is designed to reduce offset over time to actually get you to the setpoint. Be gentle with this and try small increments.
D is derivative gain and is used to dampen the rate of change allowing you to increase the P and I terms and get there faster, this is probably the hardest one to balance as it effects the other two terms.
Have a go and if you're struggling then post your project file so far and we can try to help.
Maybe try initial values of 10 for P and 0.001 for I.
You could substitute absolute encoder count with motor rate if that makes things easier, this is less likely to eventually roll over if you are turning the motor for a long duration but may introduce more differential error in the short term.
If you want to know the maths then this is the simplified form of the PI controller, this sum repeats everytime you call the PID control function.
Error = Setpoint - Feedback
P = PGain * Error
IAccumulator += Error
I = IGain * IAccumulator
Output = P + I
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: two Motor control help me!
You might consider stepper motors since it moves in steps - A simple stepper will have 50 poles, and that would equate to 200 pulses per rev if you 1/4 stepped the windings.
At that point, counting and providing pulses to each motor would keep them locked in phase.
A top speed from a stepper motor is around 1200 RPM. The torque drops off after 1200 RPM, but the power is the same. Best running at the knee bend of the torque curve.
This would be a simple solution to your winder. It would remove the requirement to have a PID algorithm which can fall apart anyway!
At that point, counting and providing pulses to each motor would keep them locked in phase.
A top speed from a stepper motor is around 1200 RPM. The torque drops off after 1200 RPM, but the power is the same. Best running at the knee bend of the torque curve.
This would be a simple solution to your winder. It would remove the requirement to have a PID algorithm which can fall apart anyway!
-
- Valued Contributor
- Posts: 1003
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 191 times
- Been thanked: 217 times
Re: two Motor control help me!
Hi seokgi
Flowcode has a nice stepper component. Its working fine in the simulation even in 3D.
The component is build to control the wire direct. But for this you need a PoweDriver.
There is an another way
On the market are some Stepper driver with stepp and direction and break as input and as output connector for the Motor.
For this you need just to add 3 Port and control this pin with the PIC for each Motor.
regards
Stefan
Flowcode has a nice stepper component. Its working fine in the simulation even in 3D.
The component is build to control the wire direct. But for this you need a PoweDriver.
There is an another way
On the market are some Stepper driver with stepp and direction and break as input and as output connector for the Motor.
For this you need just to add 3 Port and control this pin with the PIC for each Motor.
regards
Stefan
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: two Motor control help me!
The stepper component should have an option in the properties for driving these external drivers tooOn the market are some Stepper driver with stepp and direction and break as input and as output connector for the Motor.
For this you need just to add 3 Port and control this pin with the PIC for each Motor.

Yes I agree steppers would make more sense, I was thinking the first DC motor was maybe part of another existing system.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel