Go Down

Topic: MAX 31865 pines a usar (PT100)[SOLUCIONADO] (Read 296 times) previous topic - next topic

BrewGold

Aug 03, 2019, 04:01 am Last Edit: Aug 03, 2019, 09:21 pm by BrewGold
Buenas noches,

Una consulta si voy a usar 5 MAX31865 en un arduino mega, los pines SPI son 53, 51 y 50  para CS, DI, DO y CLK respectivamente, se puede usar para CS el pin 22, 23, 24 y 25, ya que son el control switch?

Gracias,

surbyte

Si claro!!,
Esa es la forma de controlar muchos dispositivos SPI, con diferentes CS y todos esos pines con pull-up de 10k.
Verifica que lo tengan, deben quedar inhibidos cuando no esten activos.

BrewGold

#2
Aug 03, 2019, 04:53 am Last Edit: Aug 03, 2019, 05:57 am by BrewGold
Una consulta la medida de la RTD me un error
00000RTD value: 0
Ratio = 0.00000000
Resistance = 0.00000000
Temperature = -242.02
Fault 0x40
RTD Low Threshold

si desconecto la RTD mide un valor de ruido, la RTD es de 3 hilos y mide  108 Ohms. He usado ele ejemplo que da Adafruit  para PT100 3 hilos.

Gracias

surbyte

Estas corriendo algun ejemplo de la librería?

BrewGold

Si este
Code: [Select]
#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>
#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31865 max = Adafruit_MAX31865(25,51,50,52);
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 max = Adafruit_MAX31865(25);
// The value of the Rref resistor. Use 430.0!
#define RREF 430.0// The value of the
#define RNOMINAL  100.0
//Modbus Registers Offsets (0-9999)

const int LAMP_COILS = 0; // Registro de lectura/escritura para 16 COILS
const int SWITCH_ISTS = 1; // Registro de lectura para 16 SWITCHS
// Salidas
const int SERVO1_HREG = 2; // Registro para salida PWM
const int SERVO2_HREG = 3; // Registro para Cargar analog1
const int SERVO3_HREG = 4; // Registro para Cargar analog2
const int SERVO4_HREG = 5; // Registro para Cargar analog3
// Entradas
const int SENSOR1_IREG = 6; // Temperatura 1
const int SENSOR2_IREG = 7; // Temperatura 2
const int SENSOR3_IREG = 8; // Temperatura 3
const int SENSOR4_IREG = 9; // Temperatura 4
const int SENSOR5_IREG =10; // Temperatura 5

// Variables
int COILS = 0;
// variables discretas de entrada
bool coil1 = false;
bool coil2 = false;
bool coil3 = false;
bool coil4 = false;
bool coil5 = false;
bool coil6 = false;
bool coil7 = false;
bool coil8 = false;
bool coil9 = false;
bool coil10 = false;
int SWITCHS = 0;
// variables discretas de salida
bool switch5 = false;
bool switch6 = false;
bool switch7 = false;
bool switch8 = false;

//Used Pins
// Pines de salida
const int coilPin1 = 40; //Mosfet 1
const int coilPin2 = 42; //Mosfet 2
const int coilPin3 = 44; //Mosfet 3
const int coilPin4 = 46; //Mosfet 4
const int coilPin5 = 39; //Mosfet 5
const int coilPin6 = 41; //Mosfet 6
const int coilPin7 = 43; //Mosfet 7
const int coilPin8 = 45; //Mosfet 8
const int coilPin9  = 35; //Rele  1
const int coilPin10 = 37; //Rele  2
// Pines de entrada
const int switchPin1 = 3;
const int switchPin2 = 2;
const int switchPin3 = A1;
const int switchPin4 = A2;
// Pin salida PWM
const int servoPin = 9;
// Pin entrada analógica
const int sensorPin = A0;

//ModbusIP object
ModbusIP mb;
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte deviceAddress[] = {};

IPAddress ip(192,168,1, 230);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);

// Modbus defaults to port 502
//EthernetServer server(502);

boolean alreadyConnected = false; // whether or not the client was connected previously

float temp1c, temp2c, tempLc;
float temp1r, temp2r, tempLr;


int sensor1, sensor2, sensor3, sensor4, sensor5;

void setup() {
 
  Ethernet.begin(mac, ip);
 
  Serial.begin(9600);
 
  max.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
  // initialize the ethernet device

  mb.config(mac, ip, gateway, gateway, subnet);

  //Set ledPin mode

  pinMode(coilPin1, OUTPUT);
  digitalWrite(coilPin1, HIGH);
  pinMode(coilPin2, OUTPUT);
  digitalWrite(coilPin2, HIGH);
  pinMode(coilPin3, OUTPUT);
  digitalWrite(coilPin3, HIGH);
  pinMode(coilPin4, OUTPUT);
  digitalWrite(coilPin4, HIGH);
  pinMode(coilPin5, OUTPUT);
  digitalWrite(coilPin5, HIGH);
  pinMode(coilPin6, OUTPUT);
  digitalWrite(coilPin6, HIGH);
  pinMode(coilPin7, OUTPUT);
  digitalWrite(coilPin7, HIGH);
  pinMode(coilPin8, OUTPUT);
  digitalWrite(coilPin8, HIGH);
  pinMode(coilPin9, OUTPUT);
  digitalWrite(coilPin9, HIGH);
  pinMode(coilPin10, OUTPUT);
  digitalWrite(coilPin10, HIGH);

  pinMode(servoPin, OUTPUT);
  pinMode(switchPin1, INPUT);
  pinMode(switchPin2, INPUT);
 
  // Add LAMP_COILS register - UP to 16 COILS
 
  bitWrite(COILS,0,digitalRead(coilPin1)); // COIL1
  bitWrite(COILS,1,digitalRead(coilPin2)); // COIL2
  bitWrite(COILS,2,digitalRead(coilPin3)); // COIL3
  bitWrite(COILS,3,digitalRead(coilPin4)); // COIL4
  bitWrite(COILS,4,digitalRead(coilPin5)); // COIL5
  bitWrite(COILS,5,digitalRead(coilPin6)); // COIL6
  bitWrite(COILS,6,digitalRead(coilPin7)); // COIL7
  bitWrite(COILS,7,digitalRead(coilPin8)); // COIL8 
  bitWrite(COILS,8,digitalRead(coilPin9)); // COIL9
  bitWrite(COILS,9,digitalRead(coilPin10)); // COIL10
  bitWrite(COILS,4,coil5); // COIL5
  bitWrite(COILS,5,coil6); // COIL6
  bitWrite(COILS,6,coil7); // COIL7
  bitWrite(COILS,7,coil8); // COIL8
  mb.addHreg(LAMP_COILS,COILS);
 
  // Add SWITCH_ISTS register - UP to 16 SWITCHS
 
  mb.addHreg(SWITCH_ISTS, SWITCHS);

 
  // Add SERVO_HREG register - Use addHreg() for analog outpus or to store values in device
  mb.addHreg(SERVO1_HREG, 0);
  mb.addHreg(SERVO2_HREG, 0);
  mb.addHreg(SERVO3_HREG, 0);
  mb.addHreg(SERVO4_HREG, 0);

  // Add SENSOR_IREG register - Use addIreg() for analog Inputs
  mb.addHreg(SENSOR1_IREG);
  mb.addHreg(SENSOR2_IREG);
  mb.addHreg(SENSOR3_IREG);
  mb.addHreg(SENSOR4_IREG);
  mb.addHreg(SENSOR5_IREG);
}

void loop() {
uint16_t rtd = max.readRTD();
Serial.print("RTD value: "); Serial.println(rtd);
float ratio = rtd;
ratio /= 32768;
Serial.print("Ratio = "); Serial.println(ratio,8);
Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
Serial.print("Temperature = "); Serial.println(max.temperature(100,
RREF));
// Check and print any faults
uint8_t fault = max.readFault();
if (fault) {
 Serial.print("Fault 0x"); Serial.println(fault, HEX);
 if (fault & MAX31865_FAULT_HIGHTHRESH) {
 Serial.println("RTD High Threshold");
 }
 if (fault & MAX31865_FAULT_LOWTHRESH) {
 Serial.println("RTD Low Threshold");
 }
 if (fault & MAX31865_FAULT_REFINLOW) {
 Serial.println("REFIN- > 0.85 x Bias");
 }
 if (fault & MAX31865_FAULT_REFINHIGH) {
 Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
 }
 if (fault & MAX31865_FAULT_RTDINLOW) {
 Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
 }
 if (fault & MAX31865_FAULT_OVUV) {
 Serial.println("Under/Over voltage");
 }
 max.clearFault();
}
Serial.println();
delay(1000);
sensor1=0;
Serial.print (sensor1);
delay (100);
sensor2=0;
Serial.print (sensor2);
delay (100);
sensor3=0;
Serial.print (sensor3);
delay (100);
sensor4=0;
Serial.print (sensor4);
delay (100);
sensor5=0;
Serial.print (sensor5);
delay (100);
digitalWrite (coilPin1,coil1);
digitalWrite (coilPin2,coil2);
digitalWrite (coilPin3,coil3);
digitalWrite (coilPin4,coil4);
digitalWrite (coilPin5,coil5);
digitalWrite (coilPin6,coil6);
digitalWrite (coilPin7,coil7);
digitalWrite (coilPin8,coil8);
digitalWrite (coilPin9,coil9);
digitalWrite (coilPin10,coil10);
TCP_Modbus ();
   
}

//////////////////////////Subrutina MODBUS/////////////////////////////

void TCP_Modbus () {
 
  //Call once inside loop() - all magic here
  mb.task();

  //Attach coilPin to LAMP_COIL register
 
  digitalWrite(coilPin4, bitRead(mb.Hreg(LAMP_COILS),3));
  coil1 = bitRead(mb.Hreg(LAMP_COILS),0);
  coil2 = bitRead(mb.Hreg(LAMP_COILS),1);
  coil3 = bitRead(mb.Hreg(LAMP_COILS),2);
  coil4 = bitRead(mb.Hreg(LAMP_COILS),3);
  coil5 = bitRead(mb.Hreg(LAMP_COILS),4);
  coil6 = bitRead(mb.Hreg(LAMP_COILS),5);
  coil7 = bitRead(mb.Hreg(LAMP_COILS),6);
  coil8 = bitRead(mb.Hreg(LAMP_COILS),7);
  coil9 = bitRead(mb.Hreg(LAMP_COILS),8);
  coil10= bitRead(mb.Hreg(LAMP_COILS),9);

   //Attach switchPin to SWITCH_ISTS register
   bitWrite(SWITCHS,0,digitalRead(coilPin1)); // Mosfet1
   bitWrite(SWITCHS,1,digitalRead(coilPin2)); // Mosfet2
   bitWrite(SWITCHS,2,digitalRead(coilPin3)); // Mosfet3
   bitWrite(SWITCHS,3,digitalRead(coilPin4)); // Mosfet4
   bitWrite(SWITCHS,4,digitalRead(coilPin5)); // Mosfet5
   bitWrite(SWITCHS,5,digitalRead(coilPin6)); // Mosfet6
   bitWrite(SWITCHS,6,digitalRead(coilPin7)); // Mosfet7
   bitWrite(SWITCHS,7,digitalRead(coilPin8)); // Mosfet8
   bitWrite(SWITCHS,8,digitalRead(coilPin9)); // Rele1
   bitWrite(SWITCHS,9,digitalRead(coilPin10));// Rele2

   mb.Hreg(SWITCH_ISTS, SWITCHS);
   
  // Add SERVO_HREG register - Use addHreg() for analog outpus or to store values in device
  analogWrite(servoPin, mb.Hreg(SERVO1_HREG));

     
  //Setting raw value (0-1024)
  mb.Hreg(SENSOR1_IREG,sensor1);
  mb.Hreg(SENSOR2_IREG,sensor2);
  mb.Hreg(SENSOR3_IREG,sensor3);
  mb.Hreg(SENSOR4_IREG,sensor4);
  mb.Hreg(SENSOR5_IREG,sensor5); 

}

Estuve trabajando con termocuplas k, iba bien hasta que interactuaron 2 variadores de velocidad y metió un ruido que no pude apantallar de ninguna forma.

surbyte

A ver.. te diré lo que les digo a todos. Separa las cosas.

El MAX 31865 lee la PT100 solo, lo hace correctamente?

BrewGold

Solo esa parte de programa mantiene el error
Code: [Select]
#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31865 max = Adafruit_MAX31865(25,51,50,52);
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 max = Adafruit_MAX31865(25);
// The value of the Rref resistor. Use 430.0!
#define RREF 430.0// The value of the
#define RNOMINAL  100.0



void setup() {
 

  Serial.begin(9600);
 
  max.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
  // initialize the ethernet device

}

void loop() {
uint16_t rtd = max.readRTD();
Serial.print("RTD value: "); Serial.println(rtd);
float ratio = rtd;
ratio /= 32768;
Serial.print("Ratio = "); Serial.println(ratio,8);
Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
Serial.print("Temperature = "); Serial.println(max.temperature(100,
RREF));
// Check and print any faults
uint8_t fault = max.readFault();
if (fault) {
 Serial.print("Fault 0x"); Serial.println(fault, HEX);
 if (fault & MAX31865_FAULT_HIGHTHRESH) {
 Serial.println("RTD High Threshold");
 }
 if (fault & MAX31865_FAULT_LOWTHRESH) {
 Serial.println("RTD Low Threshold");
 }
 if (fault & MAX31865_FAULT_REFINLOW) {
 Serial.println("REFIN- > 0.85 x Bias");
 }
 if (fault & MAX31865_FAULT_REFINHIGH) {
 Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
 }
 if (fault & MAX31865_FAULT_RTDINLOW) {
 Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
 }
 if (fault & MAX31865_FAULT_OVUV) {
 Serial.println("Under/Over voltage");
 }
 max.clearFault();
}}

surbyte

Tienes que referirte a la hoja de datos del MAX31865 para encontrarte con esto:

Quote
Fault Threshold Registers (03h-06h)
The High Fault Threshold and Low Fault Threshold registers select the trip thresholds for RTD fault detection.
The results of RTD conversions are compared with the values in these registers to generate the "Fault" (D[7:6]) bits in the Fault Status register. The RTD Data Registers, High Fault Threshold Registers, and Low Fault Threshold Registers all have the same format.
The RTD High bit in the Fault Status Register is set if the RTD resistance register value is greater than or equal to the value in the High Fault Threshold register. The POR value of the High Fault Threshold register is FFFFh.
The RTD Low bit in the Fault Status Register is set if the RTD resistance value is less than or equal to the value in
the Low Fault Threshold register. The POR value of the Low Fault Threshold register is 0000h.
O sea que tu valor de resistencia RTD es menor o igual al valor BAJO y por eso recibes la indicación de FALLA

Si has seguido la guia de Adafruit, me llama la atención que falle.


tauro0221

Hi,
Otra cosa que tienes que tener en consideracion es que tienes que soldar unos puntos en la tarjeta dependiendo de los cables que usas. Hay unos jumpers para seleccional cuantos cables usas sin son  2,3 4 cables.  El sensor viene alambrado para 4 cables. Creo que tu sensor usa 2 cables.

BrewGold


Go Up