how wil you find the accurate 'offset' of the .75 to 1.25 volt. Do you need to know the mbar's presently at startup ?
how wil you find the accurate 'offset' of the .75 to 1.25 volt. Do you need to know the mbar's presently at startup ?
Since there are some diferencies between sensor devices, on program startup or by user intervention, the offset will be stored in a variable. At this stage no other than the atmospheric pressure is applied, so this can be measured very easy.
Then in normal operation this will be the reference level.
So say that the offset is about 1.2 volts at 0 pressure. The max say it is 5 volts. The span is 3.8 volts for a pressure range of 0-39 mbar. I'd like to normalize this as 0 to 1023 counts.
In the above example I would first take the offset of 1.2 volts that is 246 count and store it in var offset (and EEPROM).
Then in normal operation say the A/D reads more then 1.2 volts, so it subtracts from the count the offset. But I would like to expand the count to match 0-1023 and not 1023-offset only. There is where I am confused.
I can ditch the floating point and just accept integers.
Ioannis
I think I got it.
My sensor is read at channel 0. So:
the problem is how to manage the sensor*1023 since the result might be more than a word and I'd prefer not to use LONG.Code:offset var word sensor var word offset_store: 'offset processing adcin 0,offset write 0,word offset return read_pressure: adcin 0,sensor sensor=sensor-offset sensor=sensor*1023/(1023-offset) return
But the 1023/(1023-offset) ends up in a small number like 1.62 or similar. It is not known untill the offset is measured and cannot be substituted as a constant and use */ operator.
Ioannis
Last edited by Ioannis; - 13th March 2023 at 21:08.
RTFM once again.
Well, DIV32 is the magic trick.
I used a dummy var to make the sensor*1023 multiplication, saved the 1023-offset to range variable and did a div32 range.
Solved.
Ioannis
Bookmarks