The project I'm working on is a digital gearbox.
What that means is I am monitoring the RPM of a spindle, and then running a stepper at an exact ratio of the spindle speed in "real time". I can't tolerate any "out of sync-ness". It needs to behave like it's mechanically coupled at least for several minutes.
The trouble is, my arduino UNO is incapable (as far as I've tried), to do what I need it to do, AND run the stepper motor.
So, I've split the tasks over two arduinos. One measures the speed of the spindle and sets the gear ratio required. It sends the speed information to the other Arduino, who's only task is to take that speed and make sure the stepper runs at it.
For now I've set the gear ratio as fixed at 1:1, so that I can see how closely the stepper motor matches the spindle.
At slower speeds (<100 rpm) it's not bad. Trouble brews when there is a change of spindle speed. The stepper speed changes too but there is a lag. Maybe about a second.
At higher speeds (>200 rpm) there is a barely noticeable difference in spindle speed compared to stepper speed. It's close. It takes about 10 seconds for the spindle to overtake the stepper by one revolution. Again ,there is a lag when the spindle speed is changed. Even if the change is somewhat gradual.
Right now my code sends the speed data 4 times per spindle revolution. As an example, at 300 rpm, the "sending" arduino needs to send the "just measured" spindle speed data to the stepper arduino around 20 times per second. I honestly don't know if this is a lot or a little.
Long story short, could you look at my code and suggest ways I could make it (data transfer) more efficient?
You could also tell me that what I am trying to do is simply impossible. I honestly don't know if it's possible or not.
I'll post the code from both arduinos in the following reply.
Thanks.