UNTESTED support for thermistor and AD595
This commit is contained in:
parent
fb82865dfc
commit
b80c5ea7b5
2
Makefile
2
Makefile
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
PROGRAM = mendel
|
||||
|
||||
SOURCES = $(PROGRAM).c serial.c dda.c gcode.c timer.c clock.c temp.c sermsg.c dda_queue.c watchdog.c debug.c sersendf.c heater.c
|
||||
SOURCES = $(PROGRAM).c serial.c dda.c gcode.c timer.c clock.c temp.c sermsg.c dda_queue.c watchdog.c debug.c sersendf.c heater.c analog.c
|
||||
|
||||
##############################################################################
|
||||
# #
|
||||
|
|
|
|||
2
analog.c
2
analog.c
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
uint8_t adc_running_mask, adc_counter;
|
||||
|
||||
volatile uint16_t adc_result[8] __attribute__ ((section ".bss"));
|
||||
volatile uint16_t adc_result[8] __attribute__ ((__section__ (".bss")));
|
||||
|
||||
void analog_init() {
|
||||
#if ANALOG_MASK > 0
|
||||
|
|
|
|||
12
machine.h
12
machine.h
|
|
@ -63,6 +63,15 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
// which temperature sensor are you using?
|
||||
// #define TEMP_MAX6675
|
||||
#define TEMP_THERMISTOR
|
||||
// #define TEMP_AD595
|
||||
|
||||
// if you selected thermistor or AD595, what pin is it on?
|
||||
#define TEMP_PIN_CHANNEL AIO0_PIN
|
||||
#define ANALOG_MASK MASK(TEMP_PIN_CHANNEL)
|
||||
|
||||
/*
|
||||
firmware build options
|
||||
*/
|
||||
|
|
@ -91,8 +100,9 @@ firmware build options
|
|||
ANALOG_MASK - which analog inputs we will be using, bitmask. eg; #define ANALOG_MASK MASK(AIO0_PIN) | MASK(3) for AIN0 and AIN3
|
||||
*/
|
||||
#define REFERENCE REFERENCE_AREF
|
||||
#ifndef ANALOG_MASK
|
||||
#define ANALOG_MASK 0
|
||||
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// you shouldn't need to edit anything below this line
|
||||
|
|
|
|||
81
temp.c
81
temp.c
|
|
@ -31,13 +31,53 @@
|
|||
#include "debug.h"
|
||||
#include "heater.h"
|
||||
|
||||
#ifdef TEMP_MAX6675
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_THERMISTOR
|
||||
#include "analog.h"
|
||||
|
||||
#define NUMTEMPS 20
|
||||
uint16_t temptable[NUMTEMPS][2] PROGMEM = {
|
||||
{1, 841},
|
||||
{54, 255},
|
||||
{107, 209},
|
||||
{160, 184},
|
||||
{213, 166},
|
||||
{266, 153},
|
||||
{319, 142},
|
||||
{372, 132},
|
||||
{425, 124},
|
||||
{478, 116},
|
||||
{531, 108},
|
||||
{584, 101},
|
||||
{637, 93},
|
||||
{690, 86},
|
||||
{743, 78},
|
||||
{796, 70},
|
||||
{849, 61},
|
||||
{902, 50},
|
||||
{955, 34},
|
||||
{1008, 3}
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_AD595
|
||||
#include "analog.h"
|
||||
#endif
|
||||
|
||||
#ifndef TEMP_MAX6675
|
||||
#ifndef TEMP_THERMISTOR
|
||||
#ifndef TEMP_AD595
|
||||
#error none of TEMP_MAX6675, TEMP_THERMISTOR or TEMP_AD595 are defined! What type of temp sensor are you using?
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uint16_t current_temp = 0;
|
||||
uint16_t target_temp = 0;
|
||||
|
||||
uint8_t temp_flags = 0;
|
||||
#define TEMP_FLAG_PRESENT 1
|
||||
#define TEMP_FLAG_TCOPEN 2
|
||||
|
||||
uint8_t temp_residency = 0;
|
||||
|
||||
#ifndef ABSDELTA
|
||||
|
|
@ -47,6 +87,7 @@ uint8_t temp_residency = 0;
|
|||
uint16_t temp_read() {
|
||||
uint16_t temp;
|
||||
|
||||
#ifdef TEMP_MAX6675
|
||||
SPCR = MASK(MSTR) | MASK(SPE) | MASK(SPR0);
|
||||
|
||||
// enable MAX6675
|
||||
|
|
@ -82,6 +123,40 @@ uint16_t temp_read() {
|
|||
return current_temp;
|
||||
}
|
||||
}
|
||||
#endif /* TEMP_MAX6675 */
|
||||
|
||||
#ifdef TEMP_THERMISTOR
|
||||
uint8_t i;
|
||||
|
||||
//Read current temperature
|
||||
temp = analog_read(TEMP_PIN_CHANNEL);
|
||||
|
||||
//Calculate real temperature based on lookup table
|
||||
for (i = 1; i < NUMTEMPS; i++) {
|
||||
if (pgm_read_word(&(temptable[i][0])) > temp) {
|
||||
// multiply by 4 because internal temp is stored as 14.2 fixed point
|
||||
temp = pgm_read_word(&(temptable[i][1])) + (pgm_read_word(&(temptable[i][0])) - temp) * 4 * (pgm_read_word(&(temptable[i-1][1])) - pgm_read_word(&(temptable[i][1]))) / (pgm_read_word(&(temptable[i][0])) - pgm_read_word(&(temptable[i-1][0])));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Clamp for overflows
|
||||
if (i == NUMTEMPS)
|
||||
temp = temptable[NUMTEMPS-1][1];
|
||||
|
||||
return temp;
|
||||
|
||||
#endif /* TEMP_THERMISTOR */
|
||||
|
||||
#ifdef TEMP_AD595
|
||||
temp = analog_read(TEMP_PIN_CHANNEL);
|
||||
|
||||
// convert
|
||||
// >>8 instead of >>10 because internal temp is stored as 14.2 fixed point
|
||||
temp = (temp * 500L) >> 8;
|
||||
|
||||
return temp;
|
||||
#endif /* TEMP_AD595 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
14
temp.h
14
temp.h
|
|
@ -3,9 +3,15 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "machine.h"
|
||||
|
||||
// RepRap host software isn't exactly tolerant on what it ready back.
|
||||
#define REPRAP_HOST_COMPATIBILITY
|
||||
|
||||
#define TEMP_FLAG_PRESENT 1
|
||||
#define TEMP_FLAG_TCOPEN 2
|
||||
|
||||
#ifdef TEMP_MAX6675
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t high;
|
||||
|
|
@ -19,6 +25,14 @@ typedef union {
|
|||
uint16_t tristate :1;
|
||||
} interpret;
|
||||
} max6675_data_format;
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_THERMISTOR
|
||||
#include <avr/pgmspace.h>
|
||||
#endif
|
||||
|
||||
#ifdef TEMP_AD595
|
||||
#endif
|
||||
|
||||
// setup temperature system
|
||||
void temp_init(void);
|
||||
|
|
|
|||
Loading…
Reference in New Issue