kf2qd:
Not real sure what you mean...
Analogread is going to convert the voltage on its pin to a number from 0 to 1023. You need to know what this number means - voltage, degrees, velocity... and how to scale it for the PID routine. Perhaps you can use this raw number, perhaps you will convert it to a number that means more to you when you look at it. Does the PID work with reals or ints? That will have the biggest influence as to what you do with that number. The more range you have to work with the better results you will get from the PID. You then will have to scale the output from the PID to 0-255 for analog write.
Hi, thanks for your reply!
To expand on my original question, I am controlling a motor, and I will be controlling both the velocity and the position. I understand that the motor's tachometer gives an output proportional to the 'speed', and the potentiometer connected to the shaft maps 0 - 360 to -10 - +10 volts. So in both cases, the output is volts. In-between the motor and the Arduino, I have some circuits that scale [-10,+10]V to [0,5]V (and the other way round for the Arduino output). So when the Arduino reads the values of the analog pins that the vel. and pos. feedback are connected to, it will give a value from 0 to 1023, depending on the voltage.
Since I will be entering the desired speed or angle as a number, I could either convert it into a value from 0 to 1023, or to volts, in which case I would also need to convert the feedback readings to volts as well.
I'm just not sure whether I should convert everything to [0,1023] or volts (using value/1023 x 5) and then letting the controller do its thing. I will then have to convert the control signal to [0,255], either by dividing by ~4, or using another formula for the voltage.
I haven't finished reading all the documentation for the PID library, unfortunately, so I'm not sure whether it uses the AnalogRead value, or if it needs volts, but I have spoken to a couple of people who are doing similar projects using pseudo-code (not the library) who said they converted values to volts.
Thank you,
+-