Go Down

Topic: RTD / PT100 1000 measurement: Library for MCP 3551 22bit ADC. (Read 12 times) previous topic - next topic

k4ktus

May 05, 2013, 11:05 am Last Edit: Sep 08, 2013, 10:10 pm by k4ktus Reason: 1
Hey guys,

I want to contribute my library for communication with one or more ADC devices over SPI in single conversion mode. This is part of my project under
http://simons-holzvergaser.blogspot.sg/

and the recent library can be fetched here:
https://github.com/Seimen/CtrlHV

direct link to arduino lib:

https://github.com/Seimen/CtrlHV/tree/master/Libraries%20for%20Arduino

With it you'll easily be able to read a PT100 ... PT1000 with only one IC and two resistors. Nothing to worry about stable reference voltage and so on. One channel may cost about 3 Euro.

For more Information look at the AN1154 from Microchip. There is also a shematic for wiring.

robtillaart

thanks for sharing!

maybe one or two sample sketches?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

k4ktus

I'm gonna do that whenever my RTD measurement circuit is complete.

k4ktus

Hey Guys,

the library with example is now online and works with every PT100...PT1000. You'll need a MCP3551 AD and only two 0.1% resistors with 6.8k. All about 3 Euro!!!

For more information you can read AN1154 from MCP.

Here is the example

Code: [Select]
/*
This example demonstrate the usage of the A/D Converter with MCP3551 library.
A good explanation on the code can be found in application note AN1154 by MCP.

Copyright (c) 2013 Simon Bauer.  All rights reserved.

This example code is in the public domain.
*/
#include <MCP3551.h>
#include <SPI.h>


// digital pin 2 has a pushbutton attached to it. Give it a name:
const int pushButton = 2;

// Slave select pin:
const int MCPPin = 30;

//Some variables we need:
float calRAdevice1 = 13607; //stores the series resistor value
float RTD; //resistor of RTD
const int RZero = 100; //resistance at 0°C

//create a instance with IC connect to SCK, MOSI and SS (MCPPin):
MCP3551 myRTD(MCPPin);

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);

}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);

  bool rtdReady = myRTD.getCode();
  if(rtdReady)
  {
    // Serial.println(getRTD1.byteCode);
   
    //calculate RTD acc. MCP AN1154:
    RTD = calRAdevice1 * (float(myRTD.byteCode) / ( 2097152.0 - float(myRTD.byteCode)));
   
    //This is part of a calculation for T(RTD)
    RTD = (RTD / RZero) - 1;
    float temperature = (RTD * (255.8723 + RTD * (9.6 + RTD * 0.878)));
   
    Serial.print("Temperature: "); Serial.println(temperature);
  }

  // A simple method for calibration at 0°C with iced water:
  if (buttonState)
  {
    char n=0;
    float temp=0;
    do
    {
      if (myRTD.getCode());
      {
        temp+= float(myRTD.byteCode);
        n++;
      }

    } while (n<10);
 
    temp /= 10;
    calRAdevice1 = RZero;
    calRAdevice1 /= ( temp /( 2097152.0 - temp));
   
    delay(2000);
    Serial.print("Ra: "); Serial.println(calRAdevice1);
    delay(2000);
      }

}

arduinofankerala

Hi,
I successfully setup a PT100 -MCP3551 with the help of your sketch and digrams. Thanks a lot. But I am facing some problems. Please help me..
1) My LCD is not working when I use your sketch. I pinpointed that this is happening once the MCP3551.h is inserted in the program. If I remove the same LCD is working but what the use without MCP3551.h :(
2) Can you explain how you find out the values in
Code: [Select]
float temperature = (RTD * (255.8723 + RTD * (9.6 + RTD * 0.878)));  
3) Can you explain the calibration procedure a little... When I click on the push button after replacing the PT100 with a 100R resistor, the temperature is showing zero. But after restarting arduino, the value is changing to older one. I noted a -5 degree C difference in the actual and theoretical reading. I want to correct this and save this value permanently. Any ideas for that??
Please find my sketch below..

Code: [Select]
#include <LiquidCrystal.h>
#include <MCP3551.h>
#include <SPI.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int pushButton = 7;
const int MCPPin = 10;
float calRAdevice1 = 13340;
float RTD;
const int RZero = 100;
MCP3551 myRTD(MCPPin);
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2); 
  lcd.setCursor(0, 0);                                           
  lcd.print("MCP3551& PT100");   
  delay (1000);
  pinMode(pushButton, INPUT);
}
void loop() { 
  int buttonState = digitalRead(pushButton);
  bool rtdReady = myRTD.getCode();
  if(rtdReady)
  { // Serial.println(getRTD1.byteCode);   
    //calculate RTD acc. MCP AN1154:
    RTD = calRAdevice1 * (float(myRTD.byteCode) / ( 2097152.0 - float(myRTD.byteCode)));   
    //This is part of a calculation for T(RTD)
    RTD = (RTD / RZero) - 1;
    float temperature = (RTD * (255.8723 + RTD * (9.6 + RTD * 0.878)));   
    Serial.println("Temperature: ");
    Serial.println(temperature);
    Serial.println("code ");
    Serial.println((float(myRTD.byteCode)));
    Serial.println("RTD ");
    Serial.println(RTD);   
    lcd.setCursor(0, 0);                                         
    lcd.print("TEMPERATURE ");                                   
    lcd.setCursor(0, 1);                                         
    lcd.print(temperature);
    delay (1000);
    // A simple method for calibration at 0°C with iced water:
    if (buttonState){
      char n=0;
      float temp=0;
      do
      {
        if (myRTD.getCode());
        {
          temp+= float(myRTD.byteCode);
          n++;
        }
      }
      while (n<10);
      temp /= 10;
      calRAdevice1 = RZero;
      calRAdevice1 /= ( temp /( 2097152.0 - temp));
      delay(2000);
      Serial.print("Ra: ");
      Serial.println(calRAdevice1);
    }
  }
}






robtillaart

I think you must assign other pins to the LCD, 11 and 12 are SPI pins. see - http://arduino.cc/en/Reference/SPI -


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

arduinofankerala

#6
Aug 05, 2013, 05:43 pm Last Edit: Aug 05, 2013, 08:04 pm by arduinofankerala Reason: 1
Hi robtillaart,
I connected MCP3551 to ICSP MISO and SCK. In this case I need to change pin 11 and 12 as well? Because in the SPI table i have seen for Uno   MOSI - 11 or ICSP-4   MISO -12 or ICSP-1   SCK -13 or ICSP-3   SS (slave)   - 10.
I think I can't connect LCD 11 and 12 to any other pins. Infact I tried it... So there is no chance that I can't connect MCP3551 and LCD togother? :(

robtillaart

#7
Aug 05, 2013, 09:06 pm Last Edit: Apr 29, 2014, 11:13 am by robtillaart Reason: 1

Hi robtillaart,
I connected MCP3551 to ICSP MISO and SCK. In this case I need to change pin 11 and 12 as well? Because in the SPI table i have seen for Uno   MOSI - 11 or ICSP-4   MISO -12 or ICSP-1   SCK -13 or ICSP-3   SS (slave)   - 10.

Yes you need to change pin 11 and 12 .

Quote

I think I can't connect LCD 11 and 12 to any other pins. Infact I tried it... So there is no chance that I can't connect MCP3551 and LCD togother? :(

Why can't you connect the LCD

Code: [Select]
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
??
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

arduinofankerala

Oh! Thank you. There was some connection problem earlier and it worked fine on pins 8 and 9.

jabami

Hi there,

I'd like to try your code and principle of measurement. Could you provide a schematic on how to setup the MCP3551, the two resistors and the PT100? That would be great.
Thanks for your efforts.

Greetings,
J.

arduinofankerala


jabami

Hi there,

how did you manage to set the reference voltage (VREF) to 2V? Wouldn't that effect any other analog reading on the Arduino? Did you use a separate LDO? If so, which, and what Capacitors did you choose?

Thanks again,
J.

arduinofankerala

I used an LM7805(common 5v regulator) as vref and worked fine. But it's better to use an LM2940( capacitors as per datasheet).

jabami

Hi there,

but you massively loose resoution when using a 5V reference. Thats why in AN1154 a 2V regulator is used. I just thought that maybe the Vref from the Arduino was used to implement the suggested design. Anyhow, I'm trying to fetch a 2V regulator as one should be enough for a 2 Channel application.
But Im curious, did you measure the accuracy of your setup?

Greetings,
Jan

arduinofankerala

Past one week my setup under test and I got .1C accuracy. I used a 10 k pot as RA and adjusted the temperature by putting pt100 in ice. Also cross checked with another thermometer and it was perfect. Vref don't have any relation with arduino. You habe to give any external reference voltage to MCP3551( I suppose!)

Go Up