Go Down

Topic: Mental block: trying to work out range for calibration formulae (Read 584 times) previous topic - next topic

theMusicMan

It's always nice to have a clear, digital readout of temperature, but for my latest project I am going all retro, and am building an analogue temperature indicator using a 0-5V voltmeter.

I'm having a blond moment and need some clarification on how I figure out the calibration formulae for the sensor I am using on my Arduino.  Hoping someone can help!

So, I am going to use a DS18B20 temperature sensor, with my Arduino and a 0-5V analogue voltmeter.  I am trying to work out the calibration factor.  Here's my assumptions and calculations that I need some assistance on please...

The temperature sensor has a range of -55 to +125 °C and can be programmed to output a 9 bit through 12 bit resolution.  I will use the 12 bit resolution, so -55°C = 0, 125°C = 4096.

-55°C - 0 and 125°C = 4095

The range of temperatures I want to display for my location on the analogue voltmeter (0-5V) is -5°C to +35°C and so I want to calibrate a Digital PWM out on my Arduino to output 0V when the temperature is -5°C, and 5V when the temperature is +35°C.

The range of the sensor is 180 degrees across 12 bits, and I want to use a range of 40 degrees which is 

40/180*4096 = 910 bits of the 4096 bits in total, which is almost enough to use with the 10-bit range of the Arduino analogue input.

So, on the 0-4096 bits of temperature sensor output, I only want to use from bit 1365 to bit 1980 as my 0-1024 analogue input, then mapped to the 0-255 on the PWM 0-5V output.

Phew... :o

Is this possible?
How do I map it please?

It's a Friday evening after all :)
John

AWOL

Quote
So, on the 0-4096 bits
I hope you mean 12 bits. (0 to 4095)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

theMusicMan

John

AWOL

Do I really need to correct that??

*sigh
Yes, please, go ahead.

(Interesting point: 24096 is an uncomfortably larger number than the number of fundamental particles in the observable universe)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

theMusicMan

Yes, please, go ahead.
We are in a pedantic mood this evening, eh!  :)

Given earlier in my post I mentioned  "-55°C - 0 and 125°C = 4095" - which suggests I am fully aware of the range of 12-bits. But thanks for pointing it out this minor indescretion which would yield in a 0.0244% error.

And surely you have more important and significantly less inane things to be getting on with? 
John

AWOL

You say "pedantic", I say "realistic".

Let's call the whole thing off.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

GoForSmoke

PWM does not make analog voltage output. It makes pulses of VCC output.

You could probably wire an LM35 into a circuit that would give the VM 0-5V analog.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

theMusicMan

PWM does not make analog voltage output. It makes pulses of VCC output.

You could probably wire an LM35 into a circuit that would give the VM 0-5V analog.
Sure, I am just playing around really in my efforts to learn coding and electronics etc, and the 0-5V analogue type meter I have does display PWM 0-5V output.

What I am wanting to do is simply read the relevant range of the the 12-bits of the sensor using the 10-bit anaolgue input of the Arduino, and then output that on one of the digital pins as a PWM 0-5V output. 

This gives me the greatest accuracy in temperature readings on the scale of temperatures I want to read as instead of having the dial move in increments of 1°C, it will use the 0-255 across the entire -5 to +35 temp scale.
John

DVDdoug

Quote
40/180*4096 = 910 bits of the 4096 bits in total, which is almost enough to use with the 10-bit range of the Arduino analogue input.
Since the DS18B20 is digital, the 10-bit Arduino ADC has nothing to do with this...

Quote
So, on the 0-4096 bits of temperature sensor output, I only want to use from bit 1365 to bit 1980 as my 0-1024 analogue input, then mapped to the 0-255 on the PWM 0-5V output.
Try this -

map(X, 1365, 1980, 0, 255);  //Not tested or verified!!!

...But first, read the raw temperature sensor and "look at" it with the serial monitor to make sure room temperature (or whatever) looks reasonable.    

theMusicMan

Since the DS18B20 is digital, the 10-bit Arduino ADC has nothing to do with this...
I thought it would because I am trying to map the 910 bits of the sensor from bits 1365 to 1980 as bits 0-1024 of the analogue input?
Try this - 

map(X, 1365, 1980, 0, 255);  //Not tested or verified!!!

...But first, read the raw temperature sensor and "look at" it with the serial monitor to make sure room temperature (or whatever) looks reasonable.    
I shall... thanks for the pointers.
John

GoForSmoke

10 bits can be 0 to 1023.  Not 1023 bits, MAX VALUE is 1023.

12 bits can be 0 to 4095. Divide that by 4 and get 10 bit values.

And regular PWM outputs 0 to 100% as 0 to 255 which is 8 bits.

You need to map a range from the 12 bit DIGITAL input to the 8 bit PWM, not the 10 bit ADC.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

theMusicMan

10 bits can be 0 to 1023.  Not 1023 bits, MAX VALUE is 1023.

12 bits can be 0 to 4095. Divide that by 4 and get 10 bit values.

And regular PWM outputs 0 to 100% as 0 to 255 which is 8 bits.

You need to map a range from the 12 bit DIGITAL input to the 8 bit PWM, not the 10 bit ADC.


Yep, I get that MAX VALUE thing, just didn't type it correctly.

However, what I don't get is that the Arduino input is not capable of reading the resolution of a 12-bit sensor, as it is only 10-bit, and in addition I only want to map a range of the temp sensors 0-4095 values to the full Arduino PWM 0-255, which will yield greater accuracy.

I am still having a blond moment!  :)
John

AWOL

It's only the ADC which is ten bit, but with a twelve bit digital sensor, you're not using the ADC.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

theMusicMan

It's only the ADC which is ten bit, but with a twelve bit digital sensor, you're not using the ADC.

Ok, I understand that bit.

But... I still have to feed the output of the 12-bit sensor into the 10-bits of the Arduino analogue in, and what I want to try to do for greater accuracy in temperature measurement is to have the range of values of 1365 to 1980 from the temperature sensor mapped through to the full 0-255 PWM output - not the full 4096 values .
John

AWOL

No, sorry, I really don't see what the problem is here.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up