It doesn't really matter as long as you make sure that you don't overflow the pid_Error variable. And remember that pid_Error is a two's complement variable so anything above 32767 is considered negative.Henrik, I just had a thought. How is the fact that I changed my temperature value to a long going to affect your PID routine? Specifically, pid_error and my set point are words, the actual temperature is a long.
Yes, a LONG minus a LONG can still fit a WORD or even a BYTE. There MAY be some differences when it comes to multiplications because LONGs are signed while WORDS and BYTES are not - I'd take a look at the manual in case it's mentioned there.I've never used longs before, can you mix them with words?
The general rule is to have the PID routine work with your raw numbers as long as the raw numbers aren't big enough to risk overflowing. There's no need for "empty resolution". The PID routine is just crunching numbers, it doesn't know what the numbers mean or represent so there's no need to have the values scaled to degrees C or whatever. As long as YOU remember to have the setpoint and actual temp variable scaled equally when you calculate pid_Error it'll be fine - then you can scale those value up or down all you want for humans to be able to make sense out of them ;-)And I guess that I will have to use C_TEMP / 10 to get the integer portion in the equation: pid_error = setpoint - temperature?
/Henrik.




Bookmarks