Data Structures | Defines | Functions | Variables

extruder/heater.c File Reference

Manage heaters. More...

#include "heater.h"
#include <stdlib.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include "arduino.h"
#include "debug.h"
#include "temp.h"
#include "crc.h"
#include "sersendf.h"
#include "config.h"

Data Structures

struct  heater_definition_t
 simply holds pinout data- port, pin, pwm channel if used More...
struct  EE_factor
 this lives in the eeprom so we can save our PID settings for each heater More...

Defines

#define DEFINE_HEATER(name, port, pin, pwm)   { &(port), (pin), &(pwm) },
 helper macro to fill heater definition struct from config.h
#define DEFAULT_P   8192
 default scaled P factor, equivalent to 8.0
#define DEFAULT_I   512
 default scaled I factor, equivalent to 0.5
#define DEFAULT_D   24576
 default scaled D factor, equivalent to 24
#define DEFAULT_I_LIMIT   384
 default scaled I limit

Functions

void heater_init ()
 initialise heater subsystem Set directions, initialise PWM timers, read PID factors from eeprom, etc
void heater_save_settings ()
 Write PID factors to eeprom.
void heater_tick (heater_t h, temp_sensor_t t, uint16_t current_temp, uint16_t target_temp)
 run heater PID algorithm
void heater_set (heater_t index, uint8_t value)
 manually set PWM output
uint8_t heaters_all_off ()
 turn off all heaters
void pid_set_p (heater_t index, int32_t p)
 set heater P factor
void pid_set_i (heater_t index, int32_t i)
 set heater I factor
void pid_set_d (heater_t index, int32_t d)
 set heater D factor
void pid_set_i_limit (heater_t index, int32_t i_limit)
 set heater I limit
void heater_print (uint16_t i)
 send heater debug info to host

Variables

struct {
   int32_t   p_factor
 scaled P factor
   int32_t   i_factor
 scaled I factor
   int32_t   d_factor
 scaled D factor
   int16_t   i_limit
 scaled I limit, such that $-i_{limit} < i_{factor} < i_{limit}$
heaters_pid [NUM_HEATERS]
struct {
   int16_t   heater_i
 integrator, $-i_{limit} < \sum{\Delta t} < i_{limit}$
   uint16_t   temp_history [TH_COUNT]
 store last TH_COUNT readings in a ring, so we can smooth out our differentiator
   uint8_t   temp_history_pointer
 pointer to last entry in ring
   uint8_t   heater_output
 this is the PID value we eventually send to the heater
heaters_runtime [NUM_HEATERS]
EE_factor EEMEM EE_factors [NUM_HEATERS]

Detailed Description

Manage heaters.


Function Documentation

void heater_print ( uint16_t  i )

send heater debug info to host

Parameters:
iindex of heater to send info for
void heater_set ( heater_t  index,
uint8_t  value 
)

manually set PWM output

Parameters:
indexthe heater we're setting the output for
valuethe PWM value to write

anything done by this function is overwritten by heater_tick above if the heater has an associated temp sensor

void heater_tick ( heater_t  h,
temp_sensor_t  t,
uint16_t  current_temp,
uint16_t  target_temp 
)

run heater PID algorithm

Parameters:
hwhich heater we're running the loop for
twhich temp sensor this heater is attached to
current_tempthe temperature that the associated temp sensor is reporting
target_tempthe temperature we're trying to achieve
uint8_t heaters_all_off ( void   )

turn off all heaters

for emergency stop

void pid_set_d ( heater_t  index,
int32_t  d 
)

set heater D factor

Parameters:
indexheater to change D factor for
dscaled D factor
void pid_set_i ( heater_t  index,
int32_t  i 
)

set heater I factor

Parameters:
indexheater to change I factor for
iscaled I factor
void pid_set_i_limit ( heater_t  index,
int32_t  i_limit 
)

set heater I limit

Parameters:
indexheater to set I limit for
i_limitscaled I limit
void pid_set_p ( heater_t  index,
int32_t  p 
)

set heater P factor

Parameters:
indexheater to change factor for
pscaled P factor
 All Data Structures Files Functions Variables Defines