ADC ?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

ADC ?

Post by Ondra »

lam working with the ADC component. I have a device that is out-putting
.460mv as read by my multimeter. When I program the PIC to sample, read and then output, the value out of the RS232 port what I get is the number 23. What should I be seeing and why am I not getting the value as measured with my multimeter.

Thanks in advance

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Post by Sean »

Hello Ondra,

When you read the ADC value as a byte (8-bit conversion), the converter divides the reference voltage (5v) by 256, giving a resolution of approximately 20mV (19.53mV). The value returned by the component is the input voltage divided by the resolution (460mV / 20mV = 23).

If you read the ADC value as an integer (10-bit conversion), the converter divides the reference voltage by 1024, giving a resolution of approximately 4.9mV

In your example, if you multiply the ADC component return value by 20(mV), the result will be the value in milliVolts, correct to approximately 2.5%.

If you multiply the ADC result by 5000 (the reference voltage in milliVolts) and divide by 256, your answer will have the full accuracy of the ADC (0.4%). Unfortunately, the intermediate result of this calculation would be too large for an integer value (65535 max.), but multiplication by 625 and division by 32 gives the same result, without the danger of overflow for ADC values lower than 104.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Post by Ondra »

Thanks Sean

echase
Posts: 429
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times
Contact:

Post by echase »

I am using the A/D reading into a Byte variable (8bit). So are you saying that if I change that variable to an Integer in Flowcode it automatically changes the input to 10 bit without any other Flowcode changes?

Excellent if it does as I was avoiding 10 bit inputs as I thought it was too complicated to set up, like have to read 2 Bytes for upper and lower bits of the reading and combining them. Can’t remember the help files covering 10 bit inputs.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello

To get the full 10 bit ADC value you must use the ReadAsInt function instead of the ReadAsByte function. You must also use an Int variable. This will load all 10 bits into the variable without any other messing around.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Post by Sean »

Hello,

Reading a 10-bit A/D conversion is as easy as reading an 8-bit conversion. The double register read, bit shifting and integer assembly is all handled by Flowcode. The variable receiving the conversion value must be declared as an integer and will be set to a value between 0 and 1023.

There is no connection between the variable declaration and A/D conversion resolution. An integer variable can be used to receive either a byte or integer conversion. The only option to be avoided is reading an integer conversion into a byte variable.

Post Reply