Powered by Invision Power Board


Forum Rules Forum Rules (Please read before posting)
  Reply to this topicStart new topicStart Poll

> Measuring Resistance With A Pic Microcontroller?
nigelmercier
Posted: November 03, 2009 06:25 pm
Reply to this postQuote Post


Member
****

Group: Trusted Members
Posts: 216
Member No.: 6,542
Joined: September 29, 2006




I want to make a replacement fuel gauge display for a boat, using a PIC microcontroller.

The sensor is a variable resistor activated by a float in the fuel tank; one terminal is connected to the 0V rail (although it may be possible to isolate it if necessary). The resistance of the sensor is to to be verified, but is likely to be either 0 Ohm to 180 Ohm, or 0 Ohm to 300 Ohm.

The existing display is a moving coil meter in series with the sensor and the 12V rail.

What would be the best way to use the existing sensor?



--------------------
--

Nigel
PM
Top
kellys_eye
Posted: November 03, 2009 07:16 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 10,659
Member No.: 2,735
Joined: June 21, 2005




What kind of display? Digital or analog?

Check also the the fuel level sensor isn't actually a 'stepped' sensor (magnet running up/down a tube having reed switches in it).

Assuming it's a vairable analog signal it's a matter of making a voltage divider and measuring the resultant volatge and making up your own scaling factor.



--------------------
May contain nuts
PMEmail PosterYahoo
Top
Roccivic
Posted: November 03, 2009 07:59 pm
Reply to this postQuote Post


Moderator
Group Icon

Group: Moderators
Posts: 7,503
Member No.: 7,882
Joined: January 19, 2007




QUOTE (Big_Nige @ November 03, 2009 05:25 pm)
I want to make a replacement fuel gauge display for a boat, using a PIC microcontroller.

Why do you want to use a PIC for such a dumb task? What a waste of thousands of transistors...
As Dave correctly pointed out we can't really help if we don't know what you want to do...
PM
Top
telomere
Posted: November 03, 2009 08:04 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 4,300
Member No.: 9,502
Joined: May 18, 2007




QUOTE (Roccivic @ November 03, 2009 11:59 am)
QUOTE (Big_Nige @ November 03, 2009 05:25 pm)
I want to make a replacement fuel gauge display for a boat, using a PIC microcontroller.

Why do you want to use a PIC for such a dumb task? What a waste of thousands of transistors...

Why, are those transistors in a scarcity or something? With that crazy Moore guy making twice as many every 18 months, we need to do SOMETHING with them, or they're going to pile up all over the place, we'll be buried in them.


--------------------
"Sometimes I can't tell the difference between thinking and being quiet, but I'll try."
PMEmail Poster
Top
kl27x
Posted: November 03, 2009 09:22 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 4,054
Member No.: 4,223
Joined: February 06, 2006




+1. Each additional transistor is just a few more nanograms of silicon.

When you consider the potential for additional IC packaging of a multi-IC analog solution as well as potential inefficiencies (vs a microcontroller with smart power management), you might find the analog solution to be the wasteful one.

PMEmail Poster
Top
nigelmercier
Posted: November 04, 2009 12:00 am
Reply to this postQuote Post


Member
****

Group: Trusted Members
Posts: 216
Member No.: 6,542
Joined: September 29, 2006




I'm not sure it is relevant, but I'll answer your questions ...

The new display is to be both digital and analogue, showing percentage of fuel remaining as a bar, approx number of litres, trip fuel used, current engine running time, perhaps even rate of fuel use.

The tank is shaped like an elephant (or any similar irregular shape), so the current display is very non-linear. It stays at FULL for days, then drops like a stone. I want to make the device both as an exercise, and so I can have a more relevant display. Obliviously it will need to be manually calibrated.

Is a simple voltage divider sufficient? I figured it would need some sort of bridge - or am I showing my age?


--------------------
--

Nigel
PM
Top
kl27x
Posted: November 04, 2009 09:49 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 4,054
Member No.: 4,223
Joined: February 06, 2006




An ADC pin has a maximum recommended impedance, specified in the datasheet. For a typical PIC, 10k is the max recommended impedance. Any higher, and the results will be skewed. There is no minimum. The lower, the better. So you could hook the ADC pin up directly to a strong power source, so long as the max voltage isn't exceeded.

Just make sure your fixed resistor goes on the top side of the divider. Then your max voltage will be limited to where you want it to be. For instance, if your sensor has a max resistance of 300 ohms, you could remove the coil and replace it with a 600 ohm resistor. Then you'd have a voltage output of 0-4V, with a relatively low impedance.

If there is any noise in the voltage source, you can put a small bypass cap between ADC pin and ground rail.
PMEmail Poster
Top
millwood
Posted: November 08, 2009 01:12 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 1,823
Member No.: 25,377
Joined: July 26, 2009




yeah, using a fixed resistor in serial with the fuel sensor would be the way to go.

I would choose a pic with internal voltage reference so you can also measure the Vdd to the mcu.
PMEmail Poster
Top
kellys_eye
Posted: November 08, 2009 02:07 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 10,659
Member No.: 2,735
Joined: June 21, 2005




The non-linearity of the current readout is usually becasue the wrong type of pick up sensor is fitted. In your case I suspect a 'lever arm' device is installed. That, or the sliding magnet/tube version is using a tube that is too short.

To do the measurements you describe though, you'll need to know the actual flow rate which will mean sensors on the fuel feed and return pipes.



--------------------
May contain nuts
PMEmail PosterYahoo
Top
millwood
Posted: November 08, 2009 02:14 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 1,823
Member No.: 25,377
Joined: July 26, 2009




QUOTE
I figured it would need some sort of bridge -


you can always calibrate the software to show the correct "volume", through a look-up table for example.

for example, you can pre-measure the relationship between volume and sensor value,

sensor volume
0ohm 1L
10ohm 2L
20ohm 30L
30ohm 50L
............
300ohm 934L

once you do the adc, you can figure out the true sensor resistance. then all you need to do is to look up that table and interpolate the volume.

that should be a piece of cake for the software.
PMEmail Poster
Top
millwood
Posted: November 08, 2009 02:16 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 1,823
Member No.: 25,377
Joined: July 26, 2009




for flow rate, you will need to measure time (easy) and change in volume (more difficult but doable).

likely some kind of smoothing has to be done as well.

but having a flowmeter will be more accurate / easier / faster.
PMEmail Poster
Top
millwood
Posted: November 08, 2009 07:07 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 1,823
Member No.: 25,377
Joined: July 26, 2009




I took this exercise to see how much of the old code i can reuse, smile.gif.

here is something I put together in half an hour. It consists of basically three modules:

1) a hd44780 driver that I wrote for a lcf meter I am working on right now. it acts as the display for the unit;
2) an interrupt based timer: based on a frequency generator I wrote earlier. it uses timer1.
3) an adc module that I had.

every pre-determined time (specified by the user), the timer sets up a flag to trigger the adc module, which measures the resistance, converts it into volumic information to be displayed on the LCD. the calculation uses floating point library and does exponential smoothing.

all of that done in 30 minutes, smile.gif.

user posted image

it does not implement a calibration / look-up function to translate ohmic readings into volumic figures - now it is simply a linear function.

also, since it uses Vdd for adc reference (vs. a fixed reference voltage), the readings are subject to Vdd fluctuations.

I am happy to upload the source file if you want to see.
PMEmail Poster
Top
Village Idiot
Posted: November 09, 2009 12:07 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 1,586
Member No.: 11,398
Joined: October 08, 2007




Unless the tank sending unit has some kind of mechanical damping, you will need to include a low pass filter on your fuel level signal (implemented in PIC code of course) to prevent the fuel level display from bouncing all over the place as the fuel sloshes around in the tank.

For fuel flow measurement, if your engine has electronic fuel injection, then the easy way is to monitor the signal to one of the injectors. It will be a PWM signal proportional to fuel flow.
PM
Top
millwood
Posted: November 09, 2009 02:02 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 1,823
Member No.: 25,377
Joined: July 26, 2009




exponential smoothing is a digital low pass filter.
PMEmail Poster
Top
Village Idiot
Posted: November 09, 2009 03:15 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 1,586
Member No.: 11,398
Joined: October 08, 2007




QUOTE (millwood @ November 08, 2009 07:02 pm)
exponential smoothing is a digital low pass filter.

I missed that part of your post.
PM
Top
NGinuity
Posted: October 27, 2010 07:35 pm
Reply to this postQuote Post


Newbie
*

Group: Members+
Posts: 1
Member No.: 33,082
Joined: October 27, 2010




Hi, I was wondering if you still had this code lying around? I'm looking to do something a little simpler, with a 10 segment LED bar and this would save me a ton of time.

Thanks in advance :-)

-Eric
PMEmail Poster
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 


:: support us ::




ElectronicsSkin by DutchDork & The-Force