CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ADC Averaging Recommendation?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
djpark



Joined: 02 Mar 2004
Posts: 49

View user's profile Send private message

ADC Averaging Recommendation?
PostPosted: Sat Jun 19, 2004 8:44 am     Reply with quote

I made a small adc unit to measure the light intensity using 12F675 reading voltage output from TI OPT101 monolithic photodiode with built-in amplifier. It gives upto about 4V output and it is good.

The problem is, the light output from a boost circuit is apparently in the pulse form (1.4MHz) and I get different values all the time.

I presume reading multiple times and getting average value to be needed, then how many samples do I need to get a reasonable value?

-- dj
Steve H
Guest







PostPosted: Sat Jun 19, 2004 9:01 am     Reply with quote

I checked the TI data sheet and this device has a DC output. What is happening is the ADC is injecting charge back out it's input terminal and causing the TI device to be unstable, or perhaps you have a capacitor on the output of the TI device (a cable, etc?). Add a 1 k resistor right at the output of the TI device then hook the other end of this resistor to the ADC input or cable, etc. The ADC sampling input really upsets many of the slower OPAMP circuits so they usually must be resistor isolated.

I've learned that if you are getting 'oscillating' values from a linear device, it's unstable and the real solution is to fix the instability - not by averaging. I once saw a temperature sensor doing this on a $1,000,000 dollar system - and they tried to fix the problem by averaging! ;-)

School of hard knocks!

Happy programming....

Steve H
djpark



Joined: 02 Mar 2004
Posts: 49

View user's profile Send private message

ADC Averaging Recommendation?
PostPosted: Sat Jun 19, 2004 9:44 am     Reply with quote

Thanks for the advice.

For simplicity, I connect the voltage output of the TI OPT101 directly to 12F675 AN3/GP4 and the program goes though all for ADC ports 16 times a second by the flag set by timer1, then pump the value string to PC via GP5 at 19200 baud.

There may be charge back from AN3 to TI, but there is other thing.

With light source is an led powered by a oscillating boost circuit, I get the random values. But when the light source is powered by a constant supply such as directly from battery or incandescent bulb, I get very stable reading.

So I still suspect the readings from the TI are actually changing. But I am going to give a try on your suggestion as I love to learn.

-- dj
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Sat Jun 19, 2004 10:22 am     Reply with quote

So if you disconnect the TI from the PIC and use the TI chip to drive the input to an oscilloscope you still see the modulation?

Depending on how far down the prototyping road you are, you could buffer the TI's output with a single-supply op-amp (lots to choose from, choose wisely).

Your TI chip could be oscillating if you are asking it to drive too much capacitance but unless you have a real mess on your board it shouldn't exceede the 10nF limit they imply. One trick you can do it take about a 10 to 100 Ohm resistor and instead of shorting pins 5 & 4, you can put the small value resisor in series with the amplifier output, then pick off the feedback on the other side of the resistor. You then make your measurements at the same node as the feedback pick-off.

Also check that you have a stable power supply, good grounds (no loops) and proper bypass caps. Are you possibly picking up the clock frequency of your PIC (or a subharmonic) and coupling it in through the power supply?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
djpark



Joined: 02 Mar 2004
Posts: 49

View user's profile Send private message

PostPosted: Sat Jun 19, 2004 9:40 pm     Reply with quote

Without a scope, I can't determine the output of TI without adc input connection.

I tried suggestions using a series register to input, a different feedback combinations and different chips. Good power and bypass cap, minimum cable legnth and I get the same result.

I see the variation is within 5-10% of value when the light source is powered by DC stepup converter and I suspect it could be caused by the ripple to the led of the light. No variation of reading from the led driven by a battery.

I wish to get a scope to confirm...
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Sat Jun 19, 2004 11:58 pm     Reply with quote

I think you just answered your own question. A resistor between the sensor's output and the PIC's ADC (or any ADC) is always good practice (just remember to keep it less than 10kohms, per the PIC's datasheet). But if I read correctly you have:
  1. The light source powered by a DC/DC converter (or is it a charge-pump device).
  2. Its switching frequency is something in the 1.4MHz region (you posted this number in your original post).
  3. The readings are very stable when the light source is powered by battery, but vary when it's powered by the switcher.

If this is correct your problem lies in the source and not the sensor. So if you want to correct it, you should be looking at the source.
  • Do you have enough bypassing (0.1uF ceramic, and 10uF electrolytic or tantalum)? A series element (small value resistor between switcher and source) may help.
  • Do you have to use a switcher?
  • Can you use a switcher followed by an LDO?

You can always add more filtering at the sensor to minimize the effect if you know there will be some (known) unwanted modulation on the incoming signal. A simple RC network might do the trick. If you look in the "CHANGING RESPONSIVITY" and the "DYNAMIC RESPONSE" sections of the sensor's datasheet you could also improve the unwanted modulation rejection there by applying the proper feedback. Finally, averaging could also work if you have previous knowledge (and it looks like you probably do) of the unwanted modulation. After all, averaging is another word for filtering (or the other way around).

Hopes this helps.
djpark



Joined: 02 Mar 2004
Posts: 49

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 12:35 am     Reply with quote

The logger is actually to measure the performance of the light source (flashlight) against time including battery voltage, current flow, led Vf and brightness. So the having to use rh switcher or not is not relavent. Many lights use such circuit.

After trying the modified input circuit, I tried averaging 16 adc readings each time, and also applied a simple filtering suggested by Neutone (http://www.ccsinfo.com/forum/viewtopic.php?t=4362#4455). But I still get about 5% ripple when the led output powered by a switching booster is used.

I am no expert on the statistics, so I am not sure how many times averaging is required to remove such ripple.

Since the overall light output doesn't change within a few second, I think your suggestion of having a RC filter at the sensor output could be a good idea and certainly I will try. Do you have any suggestions on the RC value?

I did try changing a few different combinations of feedback register and capacitor value, but didn't get much smoother output value. Perhaps, I shall try it again with more careful attention to the values and I may find some nice combination.

Thanks a lot.

-- dj
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

RC Filter Values
PostPosted: Mon Jun 21, 2004 3:04 am     Reply with quote

I did not try to say you should not use the switcher, I've yet to see a new light source that does not use one.

As for the RC filter, you can try something like 2kohm in series with the output of the sensor, and 1nF in shunt with the PIC's ADC input. That should give you better than 20dB rejection on 1.4MHz (if this is truly your modulating frequency), should drop the variation below 1%.

Also have you look at the supply filtering at the source. As I mentioned before, any series element at the source's supply (between switcher and light source) will also help.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 7:16 am     Reply with quote

If your measuring battery performance over time you can expect slow changes. You could put a 10K resistor between the PIC and the sensor and then drop a 1uF ceramic from the PIC input to ground. That will provide a very stable input voltage. 10K * .000001 gives a time constant of 10mS. You don't expect the light brightness to change measurably in that amount of time so the TC is ok.
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 7:53 am     Reply with quote

I agree with trying to solve the problem in hardware, but if you want an overview of digital filtering - look in the code section of this forum.

- SteveS
djpark



Joined: 02 Mar 2004
Posts: 49

View user's profile Send private message

PostPosted: Mon Jun 21, 2004 1:31 pm     Reply with quote

Thanks everyone for the great help.

I settled down with 2K + 0.1uF RC LPF. It gives 0.5-1% ripple from the switching powered light still, but I wanted some fast response and the variation is well accepted over few hours of logging.

As for the digital filtering, it sounds very interesting and I shall study the detail. I have a project which needs to measure river water level near sea and I am doing 60 running average over 30 seconds to dampen the effect of the wave. I hope the digital filtering can provide a better way to deal with such situation.

-- dj
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group