Precise toy motor RPM synchronization to a GPIO PWM.

Hello,

Automatically syncing a motor to a manually-spun device
I have an unusual variable-speed persistence-of-vision experiment that intentionally generates some optical illusions (think bike wheel lights, except on a table) when two simultaneously cranked toys run at almost the same speeds. I want to electronically spin one of the two instead. So I am doing a add-on experiment that requires me to automatically synchronize a motor to a manually cranked spinning wheel.

I need accurate spin of between 10 RPS through about 60 RPS
From the manually-spun device, I have access to a processed GPIO squarewave signal that goes between 10 Hz thru about 60 Hz (photosensor connected to the hand-spun wheel). I have configured cutoff thresholds, e.g. ignored when Hz is too low and Hz is too high.

Range is flexible, but it needs to be a variable range
I've set the range from 10Hz thru 60Hz since too slow is bad flicker, and too fast is risky to equipment. I can downshift to 5Hz to 30Hz (spins per second) if motor limitations restrict range, etc. I can shift or narrow the range if need be to accomodate output motor limitations, but there needs to be a range.

How do I precisely spin a motor at an exact speed, and change the speed on the fly
I need to change speed of the motor within about a 1-2 second margin. There will always be a lag in synchronizing spin speeds, but a 1-2 second latency (maybe 3-5) in RPM speed sync is acceptable.

Basically a continuous feedback loop -- Manual cranked toy speeds up, motor speeds up (within a short while), manual cranked toy slows down, motor slows down (within a slow while). Syncing of a motor spin to a manual spin.

I've got lot more experience with digital stuff, but no experience with speed-controlled motors. I can program both computer-side (C# etc) and Arduino IDE (C), but I am new to speed-control of motors.

I'm working off only 32-bit ARM based Arduinos.

What would be the easiest way to add a programmable-speed motor to my circuit?

I believe you need to first ask how to measure the speed of your motors. You cannot control the speed unless you know the speed! Right?

Paul

I have controlled the speed of a small DC motor by having an optical detector (QRE1113) to sense when a blob of white paint on a black disk (on the motor shaft) passes the detector. My system worked fine with one pulse per revolution for speeds between about 2000 and 15,000 rpm. I also used PID to adjust the power to the based on the error between the desired speed and the actual speed. This link has a simple PID implementation.

The code for reading the detector in this link is derived from my own program

...R

If you have the same photosensor on the driven one then it is simple: count pulses from both. If the driven one has fewer total pulses, increase the PWM. If less, decrease.

This will keep them absolutely synchronized over the long term but it will be difficult to make it stable at both low and high speeds. One pulse ahead at slow speed may require a different power input to one pulse at high speed.

It may work better if you turn the pulse inputs into speeds and vary PWM based on the difference between speeds.