Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - Conversion help

(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
Sun Jun 20 2010, 04:29:36, download attachment Portable_Simulator.ld
(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.
Sun Jun 20 2010, 23:27:58
(no subject) (by Samukelo Shezi)
Hi Frank

See if you like this:
Wed Jun 23 2010, 13:06:18, download attachment Portable_Simulator[1].ld
(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:
Wed Jun 23 2010, 22:28:17, download attachment Portable_Simulator1[2].ld
(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
Sat Jun 26 2010, 03:06:04
(no subject) (by Samukelo Shezi)
You are welcome, Frank. It's my pleasure treasure!
Sat Jun 26 2010, 09:18:22
(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?
Sat Jun 26 2010, 09:39:58
(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.
Sat Jun 26 2010, 12:05:15
(no subject) (by Samukelo Shezi)
Ok. Thank you very much, Jonathan!
Sat Jun 26 2010, 17:41:15
(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
Sat Jul 10 2010, 04:30:22
(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.
Sat Jul 10 2010, 16:34:53
(no subject) (by Frank Mc Alinden)
Thanks very much Jonathan

Frank
Sun Jul 11 2010, 02:51:35
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):