Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Unstable ADC result

Status
Not open for further replies.

swapan

Member
Friends,
I am going ahead with a project which uses the ADC module of PIC16F676. Sorry to say, the ADC result is unstable. I like to employ the ADC averaging technique. I have no idea of the averaging technique. Need help from any of my friends with code in Assembly for averaging.

Swapan
 
Friends,
I am going ahead with a project which uses the ADC module of PIC16F676. Sorry to say, the ADC result is unstable. I like to employ the ADC averaging technique. I have no idea of the averaging technique. Need help from any of my friends with code in Assembly for averaging.

Swapan

hi,:)
A simple method is to average a number of samples over a time period, another is a 'rolling' average, where the 'oldist' reading is dropped from the average list and a 'new' one added, before averaging.

Are you using any hardware filters before the PIC's adc input.?
 
Thanks Mr. Gayan. You may please recall your post on 24th September 2009 at 9.36 A.M. in response to my post "16F676 programming problem". I took effort to make a add-on circuit that will switch on a gadget to battery position if the AC main supply is beyond the permissible limit, say 250V (upper limit) and 190V (lower limit). For sensing the Main supply I have used a 220V/12V transformer. After rectification and filtration with a 220uF, 25V capacitor the supply has been scaled down with potential divider network. Finally the signal is fed to ADC module through a low pass RC filter (R=1k, C=.1uF). I have varied the Main supply with a variac. The circuit works well. But at some crucial point, say 190V the Relay (as you have called Sensor) turns on and off frequently. The same condition is present in the higher side (250V) also. If the input Main supply is set to 180 or 200, the operation of the Relay is stable. Hence I have guessed that the ADC result is not stable due to noise factor. I shall expect any suggestion on this point. The averaging technique with a small Assembly code is solicited.
 
You could average it but I suspect you will still get the same problem. What you need to do is introduce some software hysteresis. If you post your current code I may be able to suggest how to add hysteresis.

Mike.
 
Thats what exactly you want to do what Pommie mentioned.

Let say your lower cut off point is 2.2V that is decimal 450 - b’111000010’.

What you have to do is compare your new AD result is lower than this value. If lower you turn off the relay.

Now add 0.5V to the lower cutoff point. That is decimal 102 – b’1100110’.so the new lower cut off point will be decimal 552 – b’1000101000’.

Now compare your new AD with this point (d’552’) & see the result if greater if so turn on the relay.

Do the same thing to the upper cut off limit also.

For example purpose the hysteresis value I’ just pulled out from air. It may be a vary depending upon the transformer ratio & the voltage dividers.

In this way you don’t have to worry about the over sampling & timing.
 
Last edited:
You need data on just how "unstable" this is (noisy?).

There is nothing wrong with the 16F676 ADC, it should perform as specified. Read the specs and the errata. IIRC, noise is only like one or two codes unless you reduce Vref.

Noise reduction is most effective when your sampling meets the Nyquist criteria of the noise, that is, it is sampled at twice the noise frequency. Then you can write a lowpass FIR filter. If your sampling does not meet Nyquist criteria, lumping a lot of values together and averaging still carries a random component and the results will be inconsistent. After all, pull out a calculator and average sin(x) 16 times, making up 16 totally random numbers for x. The result won't average to 0. It could in theory be very high too, up to 16. If you meet the Nyquist criteria with the sampling period, with enough samples and a digital lowpass filter, it WILL be close to 0.

1. You need a better signal filter. An RC filter of 1K, 0.1uF has a cutoff of 1.6KHz and a pretty gradual rolloff too. In short this cannot filter the 120Hz of rectified/filtered 60Hz ripple at all, you need a far bigger cap. Go for 10uF at least. Don't increase R above 2.5Kohms or the ADC will become less accurate.
2. Your analog reference voltages may be unstable.
3. You've written in a math error somewhere, perhaps causing a Divide by Zero or overflowing an integer if certain ADC values are encountered.
4. You're not meeting the required Sample/Hold times of the PIC ADC. I don't know how much control the 16F676 gives you there.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top