I'm building a robot with 9 servos on it; each servo is controlled by a potentiometer. However, the potentiometers' analog signals are leaking into each other. As servos need a control pulse every 20ms, adding a 10ms or so delay between reading each potentiometer is not an option. Is there another way that I can stop the potentiometer signals from leaking into each other?
The servo library does the re-pulsing anyway, so if the pot hasn't been re-read it will keep sending the previous value.
See attached scope trace...
Are you saying that in each 20ms period, I should read 2 of the potentiometers, and keep the servos on the other potentiometers the same until I read those potentiometers? I can do that if I have to, but is there another way to read multiple analog ports in quick succession?
The way I read your original post, it sounded like you wanted to make sure each servo got its reminder, and it seemed to me you hadn't realised that was happening anyway, by the servo library.
Incidentally, you can change the value of REFRESH_INTERVAL in servo.h. Attached 'scope trace shows it at 10ms.
But that all said, it's very possible I haven't actually understood what you're getting at.....
Basically, what I'm asking is whether there's a way to to read 9 analog ports in 20ms, without the ports influencing each others' signals. Everywhere I looked online, it said to put a 10ms delay between reading each analog port to let the ADC reset, but I'd ideally like to read each potentiometer within the 20ms period.
I ended up finding a solution. If anyone else has the same problem, all you have to do is throw in a null analogRead before your real one without any delay. For example, here's a (working) segment of my code:
A=analogRead(A0);
A=analogRead(A0);
B=analogRead(A1);
B=analogRead(A1);
C=analogRead(A2);
C=analogRead(A2);
D=analogRead(A3);
D=analogRead(A3);