Pages: [1]   Go Down
Author Topic: Shield to calibrate the internal Temperatur Sensor on an Atmel32U4 vinciDuino  (Read 721 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

after I get an Leonardo clone, the vinciduino I studies the Atmel reference and I read there is an Internal Temperatur Sensor on Chip. The bad I read was on Chapter 24.6.1, "The sensor initial tolerance is large (+/- 10°C)..."

After this i found the AVR122 Techpaper about "Calibration of the AVR's internal temperature reference"  and an nice eMail corespondance with fm, i decided to make an Shield (my first one) to calibrate the sensor.

With the use of the following librarys OneWire, DallasTemperature 3.72beta and Bounce, I have written an Sketch under looking in the wiring_analog.c to calculate the offset und k factor for me.

Needed thinks an DS18B20, an Button, Pinheader an Plate.

there are the code:

Code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Bounce.h>

// Array for the Values
float adc[2];
float temp[2];

// Data wire is plugged into port 7 on the Arduino
#define ONE_WIRE_BUS 7

// Connection of the Button
#define BUTTON 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// arrays to hold device address
DeviceAddress Thermometer_on_controller;

// Instantiate a Bounce object with a 5 millisecond debounce time
Bounce bouncer = Bounce( BUTTON,5 );
int counter = 0;
int counter_old = 0;

void setup(void){
  // start serial port
  Serial.begin(9600);

  // locate devices on the bus
  sensors.begin();

  // Search for devices on the bus and assign based on an index.
  sensors.getAddress(Thermometer_on_controller, 0);

  // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
  sensors.setResolution(Thermometer_on_controller, 9);
  
  digitalWrite(BUTTON, HIGH);
  pinMode(BUTTON,INPUT);
}

void loop(void){
  // Update the debouncer
  bouncer.update();
  
  // Get the update value
  int value = bouncer.fallingEdge();  
  
  ds18b20_temp(0);
  Serial.print("    ");
  Serial.print("ADC-Wert ");
  Serial.println(tempRead());
  
  if ( value == HIGH) {
    counter = counter + 1;
  }
 
  if ( value == HIGH && counter == 4) {
    counter = 0;
  }  
  Serial.println(counter);
  
  if (counter != 0 && counter != 3) {
    if (counter_old != counter){
      counter_old = counter;
      saving(counter);
    }
  }
  
  if (counter == 3) {
    float T_off = ((adc[1]-adc[0])/(temp[1]-temp[0]))*((-1)*temp[0])+adc[0];
    float k = (float)temp[1]/((float)adc[1] - (float)T_off);
    Keyboard.println("Berechnung");
    Keyboard.print("Toff ");
    Keyboard.println(T_off);
    Keyboard.print("K ");
    Keyboard.println(k);
    Keyboard.println();
    counter = 0;
  }
}


void ds18b20_temp(int index){
  sensors.requestTemperaturesByIndex(index);
  float tempC = sensors.getTempCByIndex(index);
  Serial.print("Temp C: ");
  Serial.print(tempC);
}

int tempRead(){
  int low, high;

  // Set the analog reference to the internal 2.56V
  ADMUX |= (1 << REFS1) | (1 << REFS0);

  // Select the Temperature sensor on the ADC-MUX
  ADMUX |= (1 << MUX0) | (1 << MUX1) | (1 << MUX2);
  ADCSRB |= 1 << MUX5;
  
  // Start the conversion
  ADCSRA |= (1<<ADSC);

  // ADSC is cleared when the conversion finishes
  while((ADCSRA & _BV(ADSC)));

  // We have to read ADCL first; doing so locks both ADCL
  // and ADCH until ADCH is read.  reading ADCL second would
  // cause the results of each conversion to be discarded,
  // as ADCL and ADCH would be locked when it completed.
  low  = ADCL;
  high = ADCH;

  // combine the two bytes
  return (high << 8) | low;
}

void saving(int pos){
  adc[pos-1] = (float)tempRead();
  temp[pos-1] = sensors.getTempCByIndex(0);
  Keyboard.print("DS18B20   ");
  Keyboard.print(temp[pos-1]);
  Keyboard.print("      ");
  Keyboard.print("32U4    ");
  Keyboard.println(adc[pos-1]);
}

You can see that there are some shots nessesary to get Values you can trust (I used coolant spray) and an filler paste would make the messurement better...

And some Pic's from the Output and the Shield:


* Terminal Fenster.JPG (49.76 KB, 720x528 - viewed 10 times.)

* Notepad fenster.JPG (49.67 KB, 484x504 - viewed 10 times.)

* IMG_4115.JPG (372.72 KB, 1600x1200 - viewed 11 times.)

* IMG_4117.JPG (575.97 KB, 1600x1200 - viewed 17 times.)
« Last Edit: February 26, 2012, 10:07:54 am by Markus_L811 » Logged

Cairns - Green Island for Winter
Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
Maybe I can help- good try at english and I hope this helps - see if this works.
after I get an Leonardo clone, the vinciduino I studies the Atmel reference and I read there is an Internal
Temperatur Sensor on Chip. The bad I read was on Chapter 24.6.1, "The sensor initial tolerance is large (+/- 10°C)..."

I got a Vinciduino , a Leonardo clone . I studied the Atmel reference sheet and noticed there is an internal Temperature sensor on the chip. It can be up to +/- 10 degrees C out though.

After this i found the AVR122 Techpaper about "Calibration of the AVR's internal temperature reference"  and an nice eMail corespondance with fm, i decided to make an Shield (my first one) to calibrate the sensor.
With the use of the following librarys OneWire, DallasTemperature 3.72beta and Bounce, I have written an Sketch under looking in the wiring_analog.c to calculate the offset und k factor for me.

Needed thinks an DS18B20, an Button, Pinheader an Plate.
I don't get this one but perhaps its header pins ,button,DS18B20 chip and some sort of plate?I don't know what "fenster" means ,perhaps output or window?
there are the code:
Here is the code:-
« Last Edit: February 27, 2012, 05:48:34 am by tytower » Logged

Governments should do what they were designed to do only.
Manage the larger issues best done by Government.
My Family and my Property are no

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I should work on english writing I don't need it often!
Logged

Pages: [1]   Go Up
Jump to: