ADC issues...

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
saakis
Posts: 44
Joined: Sat Dec 11, 2010 8:50 pm
Has thanked: 8 times
Been thanked: 3 times
Contact:

ADC issues...

Post by saakis »

Hello Flowcode people,
I have an issue with a program I'm trying to do, which measure a voltage in the input -1000mV in the input corespond to 1000mA- and also measure the time that voltage applied in ms. The problem is when in simulation it is fine but when I programm the 16F88 and put it on the HP-480 evaluation board, I have negative values for the product mAs=(mA*time)/1000 because time is in ms. Also when I tranfer the circuit on a test board I made, the value of mA never going more than 99;it supposed could measure 5000mV. Does anybody has an idea what is going wrong? And could you help me in the multiplication to have one decimal poind to be more accurate?
Thank you
Sakis
mAs_meter16F88.fcf
(8.5 KiB) Downloaded 298 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC issues...

Post by medelec35 »

Hi saakis,
Reason your number is going negative on your hardware but appears OK on simulator is because they calculate in different ways. Hardware is using singed integers whereas simulator is using 16bit maths, then converting the result into signed integer. (well I think I read that some where :P )

In reality this means on real hardware you cannot multiply numbers together if the result will exceed 32767 even if you divide after to reduce total (as in your formula). If you do the variable will roll over and a negative number will be produced.

Difference with simulator, it will allow formula to go over 32767 and divide down again.

Try this:
mAs = mA*(time/1000)

Martin
Martin

saakis
Posts: 44
Joined: Sat Dec 11, 2010 8:50 pm
Has thanked: 8 times
Been thanked: 3 times
Contact:

Re: ADC issues...

Post by saakis »

Hello Martin,
thank you for your advice, I tested but a new problem came up...If the ms are less than 1000 the result of mAs is zero...is it possible to work with strings?
Sakis

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC issues...

Post by medelec35 »

saakis wrote:If the ms are less than 1000 the result of mAs is zero...is it possible to work with strings?
Sakis
Perhaps floating point for mAs would be the answer?
When I get a chance, Will see what I can come up with.
You may get someone else posting answer before I do.
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: ADC issues...

Post by Spanish_dude »

Multiply your ADC value by 10, this will give you a 0.1 precision.

An integer can't have point numbers: 5 / 2 = 2 (for an integer)
So multiplying it by 10 would give : (5 * 10) / 2 = 25

Next thing you'll need to do is put a '.' between '2' and '5'

saakis
Posts: 44
Joined: Sat Dec 11, 2010 8:50 pm
Has thanked: 8 times
Been thanked: 3 times
Contact:

Re: ADC issues...

Post by saakis »

Hi,
The problem with that is that the product mAs=(mA*time)/1000 goes to high and I have negative numbers when it gets more than 32767...One way is to increase the delay to 10 ms but in that way I have redused resolution...
Sakis

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC issues...

Post by medelec35 »

Hi Sakis,

Try attached flowchart.
It's the simplest solution I can think of.
Hopefully will work OK?
Not had chance to test it properly.
If values are low, there will be rounding issues

As said previously, floating point is probably give the best results, but I'm not that good with manipulating just a single floating point variable.
If I suss it out, then will post another flowchart.

Martin
Attachments
mAs_meter16F88_modified.fcf
(13 KiB) Downloaded 271 times
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC issues...

Post by medelec35 »

I have tried with the float version (on a 18F4455) as it is really accurate.
However there is a catch.
It will not fit onto a 16F88.
If you want to use the float version then you will have to use a chip with more memory.

Martin
Attachments
mAs_meter16F88_modified2.fcf
Float variable Version
(13 KiB) Downloaded 284 times
Martin

saakis
Posts: 44
Joined: Sat Dec 11, 2010 8:50 pm
Has thanked: 8 times
Been thanked: 3 times
Contact:

Re: ADC issues...

Post by saakis »

Good morning Martin,
I tried to compile the secont Flowcode to 16F88 but it wasn't possible due to limits(?) of the programm version I have. Any way I compile it to 18F4450 but I don't know why the programm didn't run at all...What I did
wrong?
Sakis
mAs_meter18F4450.fcf
(9.5 KiB) Downloaded 317 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC issues...

Post by medelec35 »

Hi Sakis,
medelec35 wrote: It will not fit onto a 16F88.
If you want to use the float version then you will have to use a chip with more memory.

Martin
Float takes up a lot of room, especially when involved with calculations. You can get chips with much smaller pin count.
(see http://www.matrixmultimedia.com/mmforum ... 40&p=22201 )
E.g 16F1827 that will work, but the catch with that chip is, until next planned update, you will need to use the hitec compiler


Reason your program did not run is down to the configuration settings.
LCD is connected to portB, yet the low voltage programming was enabled, which makes pin RB4 unusable (only available for low voltage programming).
LCD on port B requires the use of RB4, Therefore you would have no display.
I personally leave port B as the last resort for connecting LCD's or LED's etc. That way I can leave RB6/RB7 free for ICD debugging.
That has helped me loads.

If you wanted to time how long current is detected and do other things at the same time, e.g flash LED, have something different displayed e.g value of detected current etc.
Instead of a loop while current>1, you could have a timer interrupt for timing.
This would not effect the accuracy, no matter what the rest of program was doing during the timing period.

See if attached program works OK.


Martin
Attachments
mAs_meter18F4450.fcf
changed config.
(9.5 KiB) Downloaded 272 times
Martin

saakis
Posts: 44
Joined: Sat Dec 11, 2010 8:50 pm
Has thanked: 8 times
Been thanked: 3 times
Contact:

Re: ADC issues...

Post by saakis »

Good morning Martin,
now it works!!! Thank you.Later today I connect it to the analog section to test the whole thing! You will have news soon...
Sakis

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC issues...

Post by medelec35 »

saakis wrote:Later today I connect it to the analog section to test the whole thing! You will have news soon...
Sakis
Your welcome.
Lets hope it works the way you want it to :)

If not, I'm sure we can help you further.
Martin

Post Reply