ADC Component - Acquisition Time Help Please...

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Sparkoids
Posts: 267
Joined: Mon Sep 14, 2009 10:34 am
Has thanked: 30 times
Been thanked: 19 times

ADC Component - Acquisition Time Help Please...

Post by Sparkoids »

Hi guys,

On the ADC Component in Flowcode 5 I am sampling from a current monitoring IC using John Crow's code and all is good there..

...however I am trying to slow everything down without success so changed the Acquisition Time from 40 to 4000 program cycles figuring it would then take 100 times longer to acquire the voltage but Flowcode 5 won't change the value when attempting to "Apply" the changes and dividing the FOSC does nothing different either!

I am also trying to "average" the voltage by adding up the results and dividing by the number of "samples" and John has advised I should use FLOATADD but this doesn't seem to work either or does Flowcode 5 know the variable is a Float and add and divide as a Float automatically?

Everything seems to be working correctly (which regular readers of these forums will know is not the norm for me!) so any help would be gratefully received - I just need to average the samples going to the PIC and effectively have an "averaged" sample taken every 5 seconds instead of jumping about like a jackrabbit who's found a box of carrots or a chimpanzee snorting amphetamines - I need the thing to S L O W down...

Best regards,


James Dexter :-}

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times

Re: ADC Component - Acquisition Time Help Please...

Post by Creative25 »

Hi
I post an example how I used to slow down ADC reading and adding averaging it up.
If you have a known ripple frequency you can adjust the delay so the ripple will be a multiple of the frequency the ADC reads so it makes a nice average.
If I do not want to slow down the whole program I use a second counter instead of the delay. Sometimes I put the counter into a timer interrupt macro.
Attachments
Adc reading.JPG
Adc reading.JPG (19.67 KiB) Viewed 6235 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times

Re: ADC Component - Acquisition Time Help Please...

Post by Enamul »

Hi

As ULI said, that's the best option to do. I would sample ADC with normal 40 acquisition time, put the ADC value (without any processing) in an INT variable initialized to 0 outside loop. Put a delay of 100s of ms and repeat the whole process for 10 times if delay is 500ms which results to 5s delay in whole process.

Simply now ADC_Value= INT variable value/10 and clear INT variable for next time. Now you can process ADC_VALUE according to your requirement.
Enamul
University of Nottingham
enamul4mm@gmail.com

Sparkoids
Posts: 267
Joined: Mon Sep 14, 2009 10:34 am
Has thanked: 30 times
Been thanked: 19 times

Re: ADC Component - Acquisition Time Help Please...

Post by Sparkoids »

Thanks for the reply guys - I'll get onto this later and let you know how I get on!

James :-}

Sparkoids
Posts: 267
Joined: Mon Sep 14, 2009 10:34 am
Has thanked: 30 times
Been thanked: 19 times

Re: ADC Component - Acquisition Time Help Please...

Post by Sparkoids »

Works perfectly folks thank you very much!

I had two of my variables configured as bytes hence the maths wasn't working correctly but now it is!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times

Re: ADC Component - Acquisition Time Help Please...

Post by Enamul »

Glad to know that it works
Enamul
University of Nottingham
enamul4mm@gmail.com

howard123
Posts: 75
Joined: Thu May 24, 2012 1:15 pm
Location: Cape Town
Has thanked: 30 times
Been thanked: 28 times

Re: ADC Component - Acquisition Time Help Please...

Post by howard123 »

Hi James
I have found that filling a capacitor across the analog line being sampled improves the ADC stability considerably. This is only effective if the value of the analog sample changes slowly as should be the case, for example, when measuring a power supply current. The capacitor leads should be cut as short as possible and soldered with one lead to GND (Vss) and the other lead to ANx. Solder this to the underside of the board if necessary so that they connect directly to the PIC device. Connecting it to the component producing the voltage does not produce the same improvements.

A good value is 100nF ceramic or better still polypropylene. Larger values produce more averaging but if the value gets too large you may damage your PIC device where you power it down. I have seen improvements of a LSB with a maximum instability range of 7 becoming less than 0.5 with this value of capacitor.

This may be useful as you might not need to average within the code.

Changing the acquisition time to improve stability is only of importance when you have more than one ADC channel active. The reason for this is that the sampling capacitor within the PIC requires a finite time to change to a new level (with some degree of accuracy) after having sampled the previous channel. If you have only one channel active, the previous sample is the same as the one following, so the values are usually very similar and hence no (or very little) time is required to change the sampled voltage.

The conversion speed is the rate at which the conversion takes place between the analog value on the sampling capacitor and the resulting digital number. The does not happen instantaneously but requires a few sequential steps, in a short period. The conversion speed is the clock which drives this process. If it is too slow then time is wasted and if it is too fast the sample may be distorted producing inaccuracies. Instead of calculating this value you could look it up in the datasheet for your device. For example my 18F45K22 running at 16 MHz is said to need a Fosc/32 to hit the sweet spot.

Howard

Post Reply