(you are viewing a thread; or go back to
list of threads)
Conversion help (by Frank Mc Alinden)
Hi Guys
Im hoping someone can help me out...
I have interfaced a pic16f876 to the circuit linked below...
http://www.piclist.com/techref/microchip/aout.htm
I have it working using relays to replace the links...Im displaying the selected Range ie 4 to 20mA on a sparkfun serlcd
but would like to also display the actual command as well ie show the command current or voltage..
Im currently displaying what the analog input reads in raw data ie 0 to 1023...Im not sure how to convert....Have attached my ld file...I have a pot connected to the 0 to 5v command input and i also read this signal via analog 0 on the pic...
Any help would be much appreciated
Frank
(no subject) (by Jonathan Westhues)
Did you read the section in the manual about integer math?
If the ADC code x goes from 0 to 1023 as the current I goes from 4 to 20 mA, for example, then
I = 4 + (x*16)/1023 .
So you can code that equation directly, with the specified order of operations. We perform the multiplication first, then the division; so we don't lose precision due to rounding error, and since 16*1023 = 16368 is less than 2^15-1 = 32767, there's no risk of integer overflow.
(no subject) (by Samukelo Shezi)
Hi Frank
See if you like this:
(no subject) (by Samukelo Shezi)
Franky
How about using a circular counter for your positions, then you only use one input switch for selection? Check the attached:
(no subject) (by Frank Mc Alinden)
Hi Guys
Sorry about the delay in replying...
Jonathon thanks for your sample , have got the 4 to 20 displaying ok....
Samukelo Shezi
Thanks for your help.. I,ll use your examples for the others that i have not converted as yet....
I like the idea of using a counter ,you only need to use one input ...neat idea ;-)
Thanks again
Frank
(no subject) (by Samukelo Shezi)
You are welcome, Frank. It's my pleasure treasure!
(no subject) (by Samukelo Shezi)
Hi Jonathan
I am curious as to why the UP/DOWN counters do not seem to be affected by the 32767 limit?
(no subject) (by Jonathan Westhues)
The same limits apply to counters, though only the latest development version generates a warning if the limits are exceeded.
(no subject) (by Samukelo Shezi)
Ok. Thank you very much, Jonathan!
(no subject) (by Frank Mc Alinden)
Hi Guys
Could someone please tell me how to convert the 0 to 5v and 0 to 10v to display in mV...
Thanks
Frank
(no subject) (by Jonathan Westhues)
If you want to be lazy, then just v = 5*x (for 0 to 5000 mV), or v = 10*x (for 0 to 10 000 mV), where x is the A/D code.
That's about (1023/1000 - 1) = 2% error, but it's likely that the total error in your resistors and voltage reference makes that negligible.
(no subject) (by Frank Mc Alinden)
Thanks very much Jonathan
Frank
Post a reply to this comment:
|