Comparator function of a 28x2

ac21

Member
I'm trying to figure out how the comparator function of a 28x2 works. I want to hook up a two wire fuel sender(the type you see in older cars) to it.
One wire goes to ground with the other wire will be in a voltage divider type setup reading .5v(full) to 3.0v(empty) or so.
My question is will the input of this be connected to [COMP1+] input of picaxe and can that be setup to read a full range signal 0-255. Is the [COMP1-] used?
 

rossko57

Senior Member
What are you wanting to compare the level signal to? It may be easier and more flexible to read the value by ADC and then manipulate or compare in code. Doesn't answer the question I know!
 

inglewoodpete

Senior Member
Why don't you want to use the PICAXE's ADC capability to read the fuel sensor, possibly with an op-amp as a buffer/amplifier?

The comparator is only going to give you a digital change-of-state when the input passes a preset reference level.
 

ac21

Member
I tired to use a opamp but getting 0-5 Volts was not easy, I need 0 to 100%(0-255). Thanks for the info, I wasn't sure of its use.
 

srnet

Senior Member
In a petrol tank situation, you could set up the comparator to turn on a light when it was say, less than 10% full.

The comparator then would only tell you two things, that there was 10% or more fuel in the tank, but you would not know how much more and it could be full, or that there was less than 10% but not how much less, and the tank could be empty.
 

hippy

Ex-Staff (retired)
I tired to use a opamp but getting 0-5 Volts was not easy, I need 0 to 100%(0-255).
With READADC10 reading a 0.5V-3.0V signal it should be possible to turn that into a 0-255/0-100% indication without needing an op-amp.
 

hippy

Ex-Staff (retired)
... for a 5V system, 0.5V would read as 102, 3V would read as 619, therefore this will put a 0 to 517 value in w1 -

ReadAdc10 FUEL_SENDER, w0
w1 = w0 Min 102 Max 619 - 102

That 0 to 517 in w1 can be converted to 0 to 100 in w2 with -

w2 = w1 * 100 / 517

And because we have 100=Empty, 0=Full, we can reverse that with -

w3 = 100 - w2

So w3 is our percentage full, and in full but untested -

Code:
#Picaxe 28X2
#Terminal 9600
Symbol FUEL_SENDER = 4 ; C.3 / ADC4
Do
  ReadAdc10 FUEL_SENDER, w0
  w1 = w0 Min 102 Max 619 - 102
  w2 = w1 * 100 / 517
  w3 = 100 - w2
  SerTxd( "Fuel tank = ", #w3, "% full", CR, LF )
  Pause 1000
Loop
 

ac21

Member
What would be the problem if i were to use a vary low value resister like the diagram shows?

I would get 4.995 volts which would give me better resolution.

the only difference i see is a amperage draw of that circuit is about 50ma(from source to resister not connected to picaxe pin) and with a 22ohm resister i get about 30ma

t2.png
 

premelec

Senior Member
My experience with trying to do what you are trying is that the fuel level resistor is liable to be very non-linear and noisy - so a lot of averaging and to calibrate run the tank almost empty and take readings as you fill it. I doubt that a lot of resolution will be of much value - the reading will vary with incline, temperature etc.
 

ac21

Member
if i wanted to put a capacitor in there to dampen the signal where would i place it? and what value?

the code reads the input signal 25 times and averages that out (probably pointless )
it goes this every minute then when it gets five readings, averages that out and displays.
 

Goeytex

Senior Member
Assuming the fuel gauge is being used on some kind of motor vehicle( car, truck. tractor), the vehicle can consume only so much fuel per minute. Therefore the code can test/compare readings to "dampen" the signal digitally.

In other words, in the real world, the fuel level will never change by more than 5 percent ( for example) in 1 minute. Well done code will know this and will only allow a max rise or fall of a predetermined amount on each display refresh cycle. In practice, this will likely be 1 percent.
 
Last edited:

hippy

Ex-Staff (retired)
You can simulate a damping effect my moving the 'display' towards the 'reading' over time ...

Code:
Do
  ReadAdc ADC_CHANNEL, reading
  Select Case display
    Case > reading : display = display - 1
    Case < reading : display = display + 1
  End Select
  Pause LOOP_TIME
Loop
You can make 'display' a word variable to slow down the rate at which the value rises and then only show the MSB of 'display'.
 
Top