Add support for multiple thermistor tables.
DEFINE_TEMP_SENSOR takes one additional argument. For TT_THERMISOR you can specify there which thermistor table to use.
This commit is contained in:
parent
8856dd9908
commit
e937b052af
|
|
@ -1,4 +1,11 @@
|
|||
// default thermistor lookup table
|
||||
|
||||
// How many thermistor tables we have
|
||||
#define NUMTABLES 1
|
||||
|
||||
#define THERMISTOR_EXTRUDER 0
|
||||
// #define THERMISTOR_BED 1
|
||||
|
||||
// Thermistor lookup table, generated with --num-temps=50 and trimmed in lower temperature ranges.
|
||||
// You may be able to improve the accuracy of this table in various ways.
|
||||
// 1. Measure the actual resistance of the resistor. It's "nominally" 4.7K, but that's ± 5%.
|
||||
|
|
@ -17,7 +24,8 @@
|
|||
// max adc: 1023
|
||||
#define NUMTEMPS 20
|
||||
// {ADC, temp*4 }, // temp
|
||||
uint16_t temptable[NUMTEMPS][2] PROGMEM = {
|
||||
uint16_t temptable[NUMTABLES][NUMTEMPS][2] PROGMEM = {
|
||||
{
|
||||
{1, 3364}, // 841.027617469 C
|
||||
{21, 1329}, // 332.486789769 C
|
||||
{41, 1104}, // 276.102666373 C
|
||||
|
|
@ -38,4 +46,5 @@ uint16_t temptable[NUMTEMPS][2] PROGMEM = {
|
|||
{881, 219}, // 54.8051659223 C
|
||||
{981, 93}, // 23.4825243529 C
|
||||
{1010, 1} // 0.498606463441 C
|
||||
}
|
||||
};
|
||||
|
|
|
|||
2
analog.c
2
analog.c
|
|
@ -11,7 +11,7 @@
|
|||
/* OR-combined mask of all channels */
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
//! automagically generate analog_mask from DEFINE_TEMP_SENSOR entries in config.h
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin) | (((type == TT_THERMISTOR) || (type == TT_AD595)) ? 1 << (pin) : 0)
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) | (((type == TT_THERMISTOR) || (type == TT_AD595)) ? 1 << (pin) : 0)
|
||||
static const uint8_t analog_mask = 0
|
||||
#include "config.h"
|
||||
;
|
||||
|
|
|
|||
|
|
@ -254,9 +254,9 @@
|
|||
#define DEFINE_TEMP_SENSOR(...)
|
||||
#endif
|
||||
|
||||
// name type pin
|
||||
DEFINE_TEMP_SENSOR(noheater, TT_INTERCOM, 0)
|
||||
// DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, 1)
|
||||
// name type pin additional
|
||||
DEFINE_TEMP_SENSOR(noheater, TT_INTERCOM, 0, 0)
|
||||
// DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, 1, 0)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -247,8 +247,8 @@
|
|||
#define DEFINE_TEMP_SENSOR(...)
|
||||
#endif
|
||||
|
||||
// name type pin
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, PINA5)
|
||||
// name type pin additional
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, PINA5, THERMISTOR_EXTRUDER)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -247,12 +247,12 @@
|
|||
#define DEFINE_TEMP_SENSOR(...)
|
||||
#endif
|
||||
|
||||
// name type pin
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, 0)
|
||||
// DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, 1)
|
||||
// name type pin additional
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, 0, THERMISTOR_EXTRUDER)
|
||||
// DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, 1, THERMISTOR_EXTRUDER)
|
||||
// "noheater" is a special name for a sensor which doesn't have a heater.
|
||||
// Use "M105 P#" to read it, where # is a zero-based index into this list.
|
||||
// DEFINE_TEMP_SENSOR(noheater, TT_THERMISTOR, 1)
|
||||
// DEFINE_TEMP_SENSOR(noheater, TT_THERMISTOR, 1, 0)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -256,9 +256,9 @@ temperature is "achieved" for purposes of M109 and friends when actual temperatu
|
|||
#define DEFINE_TEMP_SENSOR(...)
|
||||
#endif
|
||||
|
||||
// name type pin
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO2_PIN)
|
||||
DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1_PIN)
|
||||
// name type pin additional
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO2_PIN, THERMISTOR_EXTRUDER)
|
||||
DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, AIO1_PIN, THERMISTOR_EXTRUDER)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,11 @@
|
|||
// default thermistor lookup table
|
||||
|
||||
// How many thermistor tables we have
|
||||
#define NUMTABLES 1
|
||||
|
||||
#define THERMISTOR_EXTRUDER 0
|
||||
// #define THERMISTOR_BED 1
|
||||
|
||||
// Thermistor lookup table, generated with --num-temps=50 and trimmed in lower temperature ranges.
|
||||
// You may be able to improve the accuracy of this table in various ways.
|
||||
// 1. Measure the actual resistance of the resistor. It's "nominally" 4.7K, but that's ± 5%.
|
||||
|
|
@ -17,7 +24,8 @@
|
|||
// max adc: 1023
|
||||
#define NUMTEMPS 20
|
||||
// {ADC, temp*4 }, // temp
|
||||
uint16_t temptable[NUMTEMPS][2] PROGMEM = {
|
||||
uint16_t temptable[NUMTABLES][NUMTEMPS][2] PROGMEM = {
|
||||
{
|
||||
{1, 3364}, // 841.027617469 C
|
||||
{21, 1329}, // 332.486789769 C
|
||||
{41, 1104}, // 276.102666373 C
|
||||
|
|
@ -38,4 +46,5 @@ uint16_t temptable[NUMTEMPS][2] PROGMEM = {
|
|||
{881, 219}, // 54.8051659223 C
|
||||
{981, 93}, // 23.4825243529 C
|
||||
{1010, 1} // 0.498606463441 C
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/* OR-combined mask of all channels */
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
//! automagically generate analog_mask from DEFINE_TEMP_SENSOR entries in config.h
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin) | (((type == TT_THERMISTOR) || (type == TT_AD595)) ? 1 << (pin) : 0)
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) | (((type == TT_THERMISTOR) || (type == TT_AD595)) ? 1 << (pin) : 0)
|
||||
static const uint8_t analog_mask = 0
|
||||
#include "config.h"
|
||||
;
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@
|
|||
#define TEMP_RESIDENCY_TIME 60
|
||||
|
||||
#ifdef DEFINE_TEMP_SENSOR
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, TEMP_PIN_CHANNEL)
|
||||
DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, TEMP_BED_PIN_CHANNEL)
|
||||
DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, TEMP_PIN_CHANNEL, THERMISTOR_EXTRUDER)
|
||||
DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, TEMP_BED_PIN_CHANNEL, THERMISTOR_EXTRUDER)
|
||||
#endif
|
||||
|
||||
#ifdef DEFINE_HEATER
|
||||
|
|
|
|||
|
|
@ -21,6 +21,18 @@
|
|||
#include "intercom.h"
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_MAX6675
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_THERMISTOR
|
||||
#include "analog.h"
|
||||
#include "ThermistorTable.h"
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_AD595
|
||||
#include "analog.h"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
PRESENT,
|
||||
TCOPEN
|
||||
|
|
@ -31,11 +43,12 @@ typedef struct {
|
|||
temp_type_t temp_type; ///< type of sensor
|
||||
uint8_t temp_pin; ///< pin that sensor is on
|
||||
heater_t heater; ///< associated heater if any
|
||||
uint8_t additional; ///< additional, sensor type specifc config
|
||||
} temp_sensor_definition_t;
|
||||
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
/// help build list of sensors from entries in config.h
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin) { (type), (pin), (HEATER_ ## name) },
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) { (type), (pin), (HEATER_ ## name), (additional) },
|
||||
static const temp_sensor_definition_t temp_sensors[NUM_TEMP_SENSORS] =
|
||||
{
|
||||
#include "config.h"
|
||||
|
|
@ -54,18 +67,6 @@ struct {
|
|||
uint16_t next_read_time; ///< how long until we can read this sensor again?
|
||||
} temp_sensors_runtime[NUM_TEMP_SENSORS];
|
||||
|
||||
#ifdef TEMP_MAX6675
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_THERMISTOR
|
||||
#include "analog.h"
|
||||
#include "ThermistorTable.h"
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_AD595
|
||||
#include "analog.h"
|
||||
#endif
|
||||
|
||||
/// set up temp sensors. Currently only the 'intercom' sensor needs initialisation.
|
||||
void temp_init() {
|
||||
temp_sensor_t i;
|
||||
|
|
@ -165,13 +166,15 @@ void temp_sensor_tick() {
|
|||
#ifdef TEMP_THERMISTOR
|
||||
case TT_THERMISTOR:
|
||||
do {
|
||||
uint8_t j;
|
||||
uint8_t j, table_num;
|
||||
//Read current temperature
|
||||
temp = analog_read(temp_sensors[i].temp_pin);
|
||||
// for thermistors the thermistor table number is in the additional field
|
||||
table_num = temp_sensors[i].additional;
|
||||
|
||||
//Calculate real temperature based on lookup table
|
||||
for (j = 1; j < NUMTEMPS; j++) {
|
||||
if (pgm_read_word(&(temptable[j][0])) > temp) {
|
||||
if (pgm_read_word(&(temptable[table_num][j][0])) > temp) {
|
||||
// Thermistor table is already in 14.2 fixed point
|
||||
#ifndef EXTRUDER
|
||||
if (debug_flags & DEBUG_PID)
|
||||
|
|
@ -189,17 +192,17 @@ void temp_sensor_tick() {
|
|||
// Wikipedia's example linear interpolation formula.
|
||||
temp = (
|
||||
// ((x - x₀)y₁
|
||||
((uint32_t)temp - pgm_read_word(&(temptable[j-1][0]))) * pgm_read_word(&(temptable[j][1]))
|
||||
((uint32_t)temp - pgm_read_word(&(temptable[table_num][j-1][0]))) * pgm_read_word(&(temptable[table_num][j][1]))
|
||||
// +
|
||||
+
|
||||
// (x₁-x)
|
||||
(pgm_read_word(&(temptable[j][0])) - (uint32_t)temp)
|
||||
(pgm_read_word(&(temptable[table_num][j][0])) - (uint32_t)temp)
|
||||
// y₀ )
|
||||
* pgm_read_word(&(temptable[j-1][1])))
|
||||
* pgm_read_word(&(temptable[table_num][j-1][1])))
|
||||
// /
|
||||
/
|
||||
// (x₁ - x₀)
|
||||
(pgm_read_word(&(temptable[j][0])) - pgm_read_word(&(temptable[j-1][0])));
|
||||
(pgm_read_word(&(temptable[table_num][j][0])) - pgm_read_word(&(temptable[table_num][j-1][0])));
|
||||
#ifndef EXTRUDER
|
||||
if (debug_flags & DEBUG_PID)
|
||||
sersendf_P(PSTR(" temp:%d.%d"),temp/4,(temp%4)*25);
|
||||
|
|
@ -215,7 +218,7 @@ void temp_sensor_tick() {
|
|||
|
||||
//Clamp for overflows
|
||||
if (j == NUMTEMPS)
|
||||
temp = temptable[NUMTEMPS-1][1];
|
||||
temp = temptable[table_num][NUMTEMPS-1][1];
|
||||
|
||||
temp_sensors_runtime[i].next_read_time = 0;
|
||||
} while (0);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ we still need to specify which analog pins we use in machine.h for the analog se
|
|||
*/
|
||||
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin) TEMP_SENSOR_ ## name,
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) TEMP_SENSOR_ ## name,
|
||||
typedef enum {
|
||||
#include "config.h"
|
||||
NUM_TEMP_SENSORS,
|
||||
|
|
|
|||
43
temp.c
43
temp.c
|
|
@ -21,6 +21,18 @@
|
|||
#include "intercom.h"
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_MAX6675
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_THERMISTOR
|
||||
#include "analog.h"
|
||||
#include "ThermistorTable.h"
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_AD595
|
||||
#include "analog.h"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
PRESENT,
|
||||
TCOPEN
|
||||
|
|
@ -31,11 +43,12 @@ typedef struct {
|
|||
temp_type_t temp_type; ///< type of sensor
|
||||
uint8_t temp_pin; ///< pin that sensor is on
|
||||
heater_t heater; ///< associated heater if any
|
||||
uint8_t additional; ///< additional, sensor type specifc config
|
||||
} temp_sensor_definition_t;
|
||||
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
/// help build list of sensors from entries in config.h
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin) { (type), (pin), (HEATER_ ## name) },
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) { (type), (pin), (HEATER_ ## name), (additional) },
|
||||
static const temp_sensor_definition_t temp_sensors[NUM_TEMP_SENSORS] =
|
||||
{
|
||||
#include "config.h"
|
||||
|
|
@ -54,18 +67,6 @@ struct {
|
|||
uint16_t next_read_time; ///< how long until we can read this sensor again?
|
||||
} temp_sensors_runtime[NUM_TEMP_SENSORS];
|
||||
|
||||
#ifdef TEMP_MAX6675
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_THERMISTOR
|
||||
#include "analog.h"
|
||||
#include "ThermistorTable.h"
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_AD595
|
||||
#include "analog.h"
|
||||
#endif
|
||||
|
||||
/// set up temp sensors. Currently only the 'intercom' sensor needs initialisation.
|
||||
void temp_init() {
|
||||
temp_sensor_t i;
|
||||
|
|
@ -165,13 +166,15 @@ void temp_sensor_tick() {
|
|||
#ifdef TEMP_THERMISTOR
|
||||
case TT_THERMISTOR:
|
||||
do {
|
||||
uint8_t j;
|
||||
uint8_t j, table_num;
|
||||
//Read current temperature
|
||||
temp = analog_read(temp_sensors[i].temp_pin);
|
||||
// for thermistors the thermistor table number is in the additional field
|
||||
table_num = temp_sensors[i].additional;
|
||||
|
||||
//Calculate real temperature based on lookup table
|
||||
for (j = 1; j < NUMTEMPS; j++) {
|
||||
if (pgm_read_word(&(temptable[j][0])) > temp) {
|
||||
if (pgm_read_word(&(temptable[table_num][j][0])) > temp) {
|
||||
// Thermistor table is already in 14.2 fixed point
|
||||
#ifndef EXTRUDER
|
||||
if (debug_flags & DEBUG_PID)
|
||||
|
|
@ -189,17 +192,17 @@ void temp_sensor_tick() {
|
|||
// Wikipedia's example linear interpolation formula.
|
||||
temp = (
|
||||
// ((x - x₀)y₁
|
||||
((uint32_t)temp - pgm_read_word(&(temptable[j-1][0]))) * pgm_read_word(&(temptable[j][1]))
|
||||
((uint32_t)temp - pgm_read_word(&(temptable[table_num][j-1][0]))) * pgm_read_word(&(temptable[table_num][j][1]))
|
||||
// +
|
||||
+
|
||||
// (x₁-x)
|
||||
(pgm_read_word(&(temptable[j][0])) - (uint32_t)temp)
|
||||
(pgm_read_word(&(temptable[table_num][j][0])) - (uint32_t)temp)
|
||||
// y₀ )
|
||||
* pgm_read_word(&(temptable[j-1][1])))
|
||||
* pgm_read_word(&(temptable[table_num][j-1][1])))
|
||||
// /
|
||||
/
|
||||
// (x₁ - x₀)
|
||||
(pgm_read_word(&(temptable[j][0])) - pgm_read_word(&(temptable[j-1][0])));
|
||||
(pgm_read_word(&(temptable[table_num][j][0])) - pgm_read_word(&(temptable[table_num][j-1][0])));
|
||||
#ifndef EXTRUDER
|
||||
if (debug_flags & DEBUG_PID)
|
||||
sersendf_P(PSTR(" temp:%d.%d"),temp/4,(temp%4)*25);
|
||||
|
|
@ -215,7 +218,7 @@ void temp_sensor_tick() {
|
|||
|
||||
//Clamp for overflows
|
||||
if (j == NUMTEMPS)
|
||||
temp = temptable[NUMTEMPS-1][1];
|
||||
temp = temptable[table_num][NUMTEMPS-1][1];
|
||||
|
||||
temp_sensors_runtime[i].next_read_time = 0;
|
||||
} while (0);
|
||||
|
|
|
|||
2
temp.h
2
temp.h
|
|
@ -13,7 +13,7 @@ we still need to specify which analog pins we use in machine.h for the analog se
|
|||
*/
|
||||
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin) TEMP_SENSOR_ ## name,
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) TEMP_SENSOR_ ## name,
|
||||
typedef enum {
|
||||
#include "config.h"
|
||||
NUM_TEMP_SENSORS,
|
||||
|
|
|
|||
Loading…
Reference in New Issue