Hi All!
I would like to ask how, is it possible to solve that if there is 1.6V on an analog input, then the value of the register should be 0, and if it is 3V then 255? This is the temperature sensor voltage range. So, the lower voltage limit should not be 0V but 1.6V, and the upper limit should be 3V.
Thank you in advance for your help!
There are limits on how far you can adjust the A2D reference limits, the usual answer is to simply use an opamp to move the analogue voltage to the correct range. The A2D is also 10 bit, not 8 bit - and 'may' even be 12 bit (some 18F devices are).
Consult the datasheet, it tells you all the specs.
Because the ADC is 10 bit you have some options.
1) Connect Vref- to 0V and Vref+ to 3.3V. Read in 10 bit mode and subtract off 1.6V. You will have more that 8 bit accuracy. If you need 8 bits, then shift twice to lose two LSBs.
2) Connect Vref- to a 1.6V source and hope it is good. Hope that 1.6V from the sensor matches the 1.6V reference you made.
I see, thank you. I will make it 10 bits, I only wrote 255 so that it fits in 1 register. I don't think it's possible to produce a very stable, reliable 1.6V reference voltage, but it's a good idea.
Nigel, thank you. This is the amplified voltage. The original is 0 Celsius -> 290 mV, 280 Celsius -> 540 mV.
Then I'll stick with the traditional method. GND and the supply voltage. Maybe I'll amplify it to a higher voltage range.
I see, thank you. I will make it 10 bits, I only wrote 255 so that it fits in 1 register. I don't think it's possible to produce a very stable, reliable 1.6V reference voltage, but it's a good idea.
Nigel, thank you. This is the amplified voltage. The original is 0 Celsius -> 290 mV, 280 Celsius -> 540 mV.
Then I'll stick with the traditional method. GND and the supply voltage. Maybe I'll amplify it to a higher voltage range.
Hi Danadak, thank's. rjenkisgb: Do not fully understand. That's how I calculated it.
In the case of 0 - 5V in 10-bit resolution, the value of the register increases by 1 if there is a change of 5 / 1024 = 4.88mV.
Thus, at 1.6V, the value of the register will be 1.6 / 4.88*10-3 = 327.
and at 3V it will be 3 / 4.88*10-3 = 614.
So the total range will be 614 - 327 = 287.
Since I measure from 0 to 280 degrees Celsius, the value of the range is just right. 1 degree change = by increasing the value of the register.
What do I multiply by 228?
That's if you wanted to scale it to 0-255 rather than 0-287
Multiplying (for that value) by 228 then using the high byte is a quick way of re-scaling it to 0-255, without any floating point calculations, if you wanted the 0-255 result you mentioned in the first post.
Certainly it is possible to create a stable 1.6 volt reference. Or any other voltage for that matter.
Check "The Art of Electonics" In the third edition, they're in chapter 9, section 10.