![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
mka879
Joined: 30 Oct 2015 Posts: 34
|
Fluctuating Sensor Readings |
Posted: Tue May 17, 2016 12:28 am |
|
|
I have a fuel level sensor that varies its resistance from 9.5 ohm(empty) to 155ohm(full). The sensor is powered using 12V battery connected to a 30kVA Generator.
The problem is that the level that I get fluctuates, i.e, 47.57% for 30s and then 48.4 for 30s or so. The level is calculated using the equation level(%)=187.41 * V(adc port) - 7.38. The fuel level sensor forms a voltage divider with a 1.2k resistance. The voltage at the ADC pin does change but very little about +-1mV.
I have two more analog signals connected to ADC of 16f877a. The other two signals namely battery voltage and temperature are fairly stable.
I using 7805 to power up the controller circuit and a separate 7805 to power up the SIM900 module. I am using PCWHD compiler 5.015. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue May 17, 2016 1:19 am |
|
|
Calculate back. The 47.57 corresponds to an input of 0.2928v. 48.4 to 0.2976v. 4.8mV difference. Now with a 5v Vref, your ADC gives 4.8mV/step. You are seeing just _one_ count change on the ADC.....
Honestly to do any better, you need to use a better Vref, which is lower (depends on what range your other signals are), but if (for instance) you used a 2.5v Vref, the recorded signal would be more stable (because the Vref would be more stable), but also the actual step size would be only half the size.
With your current hardware, basically forget about trying to be this accurate. For 100%, your formula needs 0.572v in. Then 'zero' is 0.039v in. With 5v Vref, just 119 'steps' for 100%. So displaying anything even as accurate as 1% is pointless. Much better (and faster) to work in integer.
If you take (ADC reading-9)*92, and print this with %4.2LW, you will see your code size reduce massively, and the speed go up.
Then use damping on the ADC. Fuel is not going to change quickly.
So:
Code: |
static int16 adc_sum=0;
int16 adc_rdg;
int16 percenttimes100;
adc_rdg=read_adc(); //obviously with the required channel selected
adc_sum+=adc_rdg;
adc_rdg=adc_sum/4;
adc_sum-=adc_rdg;
//This now gives you a damped ADC reading
percenttimes100=((adc_sum-8)*92);
//Then to display or output this
printf("%04.2LW",percenttimes100;
//Or (honestly more believable),
printf("%02LD",(percenttimes100+50)/100);
//which will just give integer percent.
|
adcsum is used to generate a rolling 'sum'. The actual damping will be more the larger the divisor (use binary divisors for speed). Minimum /2, then /4, /8 etc.. Response will get successively slower the larger the divisor.
Even with a super reference, and everything smooth, you _will_ see single count changes on the ADC. If a signal is sitting at what is effectively 59.5 counts on the ADC, you will see a 'random' stream of values with half at 59 counts, and half at 60. If the signal is at 59.75, the ratio of 60's to 59's, will become 3/4 of the values reading 60. You are never going to see stable single count readings from any normal signal..... |
|
![](templates/subSilver/images/spacer.gif) |
mka879
Joined: 30 Oct 2015 Posts: 34
|
|
Posted: Tue May 17, 2016 3:30 am |
|
|
@Ttelmah: I agree that with this resolution of ADC I cannot get to accuracy of 1% but the question is there has to be a change of 4.8mV on ADC pin for 1 unit change in ADC reading. If this is true, then it follows that either the sensor resistance is changing or the 1.2k resistance is changing because I am not getting stable values.
The sensor is firmly fixed so the level is constant at a given time. I believe the sensor temperature co-efficient should be fairly low, then is it the 1.2k resistor that is causing the problem? The resistor have tolerance of 5%. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Tue May 17, 2016 5:27 am |
|
|
Given Vin of +12, Rtop=1200, Rsens=9.5 I get a Vout( to ADC) 0f .095 volts
With Rsens = 155 , Vout is 1.37.
So change from 'full' to 'empty' is only 1.27 volts.
So if my math is right( only 1 coffee so far...) I'd put a X4 ampllifier between sensor output and PIC ADC input allowing full range operation.
You also need to 'dampen' the sensor signal.I'd add a 10mfd cap across it to start. You need to remember that DMM or DVMs only sample every 3-4 times per second,so you 'see' a stable reading. Put an oscilloscope on it....it'll be all over the place ! Also the level won't be stable in the real world..vibration will 'jiggle' the tank,move the float,sensor reading will change. The gauges used for fuel level are very,very slow response units,some take 30 seconds to show a minor change in level.
Fuel sensor pots are not linear either, so you'll need to fill tank, slowly empty it and record level vs sensor value.
As Mr. T says level won't go down fast ,so having a slow STABLE reading is far more important than super accurate reading.
As for the 1200r 5%. it should be stable. While a 1% will give 'better' results more importantly is the +12 source.ANY change there has massive 'errors' in the calculations. Ideally it'd be a 'precision' reference source or a real good regulator,something like 2% of better AND it needs to be well filtered ! Any noise on the supply will be transferred to the reading.
Hopefully you have access to an oscilloscope to 'see' the signals. It will show you what's going on.
AFE ( Analog Front End ) design can be a nightmare but you MUST start with a stable,clean input signal as NO amount of 'fancy' math will correct for it.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue May 17, 2016 7:09 am |
|
|
Quote: |
@Ttelmah: I agree that with this resolution of ADC I cannot get to accuracy of 1% but the question is there has to be a change of 4.8mV on ADC pin for 1 unit change in ADC reading. If this is true, then it follows that either the sensor resistance is changing or the 1.2k resistance is changing because I am not getting stable values.
|
No. You are misunderstanding.
You are getting a change of one _count_.
A 'perfect' voltage that is sitting 'between' counts, on a 'perfect' ADC will give the counts each side of the reading, with the probability of each count shifting as the value changes.
But, even if your voltage is absolutely stable (it isn't you say it changed by a couple of mV), is the actual Vref just as stable (it too will change as things are occurring)..... A single count is remarkably good. |
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue May 17, 2016 1:12 pm |
|
|
Resistive fuel sensor, 12V battery, Generator.... is this a boat?
either way level changes in your tank are going to be reasonably slow.
I would use a low pass filter, and/or rolling average with a large delay/damping.
(especially if on a moving boat)
There are several examples in this forum.
As Ttelmah has said, that 1 count change is really good and its not gonna stop.
a low pass will help make it look "pretty" on your screen. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
![](templates/subSilver/images/spacer.gif) |
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Fri May 20, 2016 4:11 am |
|
|
Not steal this thread. Are you sure it's good solution to use a 7805 to power the SIM900?
From my knowledge, VBat<4,8 and the current peak can be >2amp for about 0,6 ms. VBat drop must be <300mv. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|