yarf 0.1
Yet Another RepRap Firmware
Data Structures | Defines | Enumerations | Functions | Variables
src/temperature/temperature.c File Reference

The temperature component manages the temperature of the nozzle and the printbed. More...

#include "temperature.h"
#include "yarf.h"
#include "thermistor_table.h"
#include "scheduling/periodic.h"
#include "util/math.h"
#include "pid.h"
#include <stdint.h>
#include <avr/interrupt.h>
#include <util/atomic.h>

Go to the source code of this file.

Data Structures

struct  heater
 Declaration of a datastructure representing a heater. More...

Defines

#define INITIAL_TARGET_TEMP_C   0
 The target temperature of the nozzle and printbed right after initializing the temperature component, in degrees celsius.

Enumerations

enum  { IDLE, READING_NOZZLE, READING_PRINTBED }
 Enumeration representing the states the ADC manager can be in. More...

Functions

static void set_nozzle_duty_cycle (uint8_t dc)
 Sets the nozzle heater's PWM duty cycle.
static void set_printbed_duty_cycle (uint8_t dc)
 Sets the printbed heater's PWM duty cycle.
static void adc_init (void)
 Initializes the hardware ADC component.
static void pwm_init (void)
 Initializes the hardware PWM component.
static void manage_heater_power (struct heater *heater)
 Sets the amount of power applied to a given heater, based on the result of calling the heater's PID instance.
static float nozzle_temperature (uint16_t adc)
 Returns the temperature for a given nozzle thermistor ADC value, based on the nozzle thermistor table.
static float printbed_temperature (uint16_t adc)
 Returns the temperature for a given printbed thermistor ADC value, based on the printbed thermistor table.
 ISR (ADC_vect, ISR_NOBLOCK)
 ADC conversion complete interrupt service routine.
static void temp_periodic (void)
 Starts an asynchronous ADC reading for the nozzle thermistor.
static bool temperature_reached (struct heater *h)
 Returns whether a heater's target temperature has been reached.
void temp_init (void)
 Initializes the temperature component.
void temp_set_nozzle_target (float c)
 Sets the target temperature of the nozzle.
float temp_get_nozzle_temp (void)
 Returns the last measured temperature of the nozzle in degrees Celsius.
uint16_t temp_get_nozzle_adc (void)
uint8_t temp_get_nozzle_power (void)
 Returns the relative amount of power applied to the nozzle's heater.
bool temp_nozzle_temperature_reached (void)
 Returns whether the nozzle's target temperature has been reached.
void temp_nozzle_temperature_wait (void)
 Blocks until the nozzle's target temperature has been reached.
void temp_set_printbed_target (float c)
 Sets the target temperature of the printbed.
float temp_get_printbed_temp (void)
 Returns the last measured temperature of the printbed in degrees Celsius.
uint8_t temp_get_printbed_power (void)
 Returns the relative amount of power applied to the printbed's heater.
bool temp_printbed_temperature_reached (void)
 Returns whether the printbed's target temperature has been reached.
void temp_printbed_temperature_wait (void)
 Blocks until the printbed's target temperature has been reached.

Variables

static struct heater nozzle
 Heater datastructure instance for the printhead nozzle.
static struct heater printbed
 Heater datastructure instance for the heated printbed.
static enum { ... }  adc_state
static periodic_task_t temperature_task
 Periodic task for checking and controlling the nozzle and printbed temperatures at constant intervals.

Detailed Description

The temperature component manages the temperature of the nozzle and the printbed.

Author:
Pieter Agten (pieter.agten@gmail.com)
Date:
9 okt 2011

Definition in file temperature.c.


Enumeration Type Documentation

anonymous enum

Enumeration representing the states the ADC manager can be in.

Enumerator:
IDLE 

The ADC manager is not doing anything.

READING_NOZZLE 

The ADC manager is reading the nozzle's temperature.

READING_PRINTBED 

The ADC manager is reading the printbed's temperature.

Definition at line 74 of file temperature.c.


Function Documentation

ISR ( ADC_vect  ,
ISR_NOBLOCK   
)

ADC conversion complete interrupt service routine.

This procedure is called when an ADC conversion is complete. After reading and managing the nozzle's temperature, the printbed's temperature is read and managed. All ADC conversions are performed asynchronously.

Definition at line 205 of file temperature.c.

static void manage_heater_power ( struct heater heater) [static]

Sets the amount of power applied to a given heater, based on the result of calling the heater's PID instance.

This function turns the heater off, if its temperature exceeds its maximum temperature.

Parameters:
heaterpointer to the heater structure for which to manage the power

Definition at line 162 of file temperature.c.

static float nozzle_temperature ( uint16_t  adc) [inline, static]

Returns the temperature for a given nozzle thermistor ADC value, based on the nozzle thermistor table.

Parameters:
adcthe 10-bit ADC value measured from the nozzle's thermistor

Definition at line 181 of file temperature.c.

static float printbed_temperature ( uint16_t  adc) [inline, static]

Returns the temperature for a given printbed thermistor ADC value, based on the printbed thermistor table.

Parameters:
adcthe 10-bit ADC value measured from the printbed's thermistor

Definition at line 193 of file temperature.c.

static void set_nozzle_duty_cycle ( uint8_t  dc) [static]

Sets the nozzle heater's PWM duty cycle.

Parameters:
dcthe duty cycle to which to set the nozzle heater's PWM module (0 to 255)
Note:
The nozzle heater's PWM duty cycle is never set higher than the NOZZLE_HEATER_MAX_DUTY_CYCLE configuration parameter.

Definition at line 98 of file temperature.c.

static void set_printbed_duty_cycle ( uint8_t  dc) [inline, static]

Sets the printbed heater's PWM duty cycle.

Parameters:
dcthe duty cycle to which to set the printbed heater's PWM module (0 to 255)
Note:
The printbed heater's PWM duty cycle is never set higher than the PRINTBED_HEATER_MAX_DUTY_CYCLE configuration parameter.

Definition at line 113 of file temperature.c.

uint8_t temp_get_nozzle_power ( void  )

Returns the relative amount of power applied to the nozzle's heater.

Returns:
The relative amount of power applied to the nozzle's heater (0 to 255).

Definition at line 323 of file temperature.c.

float temp_get_nozzle_temp ( void  )

Returns the last measured temperature of the nozzle in degrees Celsius.

Returns:
The last measured temperature of the nozzle in degrees Celsius.

Definition at line 309 of file temperature.c.

uint8_t temp_get_printbed_power ( void  )

Returns the relative amount of power applied to the printbed's heater.

Returns:
The relative amount of power applied to the printbed's heater (0 to 255).

Definition at line 357 of file temperature.c.

float temp_get_printbed_temp ( void  )

Returns the last measured temperature of the printbed in degrees Celsius.

Returns:
The last measured temperature of the printbed in degrees Celsius.

Definition at line 350 of file temperature.c.

void temp_init ( void  )

Initializes the temperature component.

The nozzle and printbed target temperatures are set to INITIAL_TARGET_TEMP_C.

Definition at line 280 of file temperature.c.

bool temp_nozzle_temperature_reached ( void  )

Returns whether the nozzle's target temperature has been reached.

Returns:
True if the nozzle's target temperature has been reached and false otherwise.

Definition at line 329 of file temperature.c.

static void temp_periodic ( void  ) [static]

Starts an asynchronous ADC reading for the nozzle thermistor.

After the reading is completed, the ADC_vect interrupt service routine will be executed. This function should be called periodically to manage the nozzle and printbed temperatures.

Definition at line 244 of file temperature.c.

bool temp_printbed_temperature_reached ( void  )

Returns whether the printbed's target temperature has been reached.

Returns:
True if the printbed's target temperature has been reached and false otherwise.

Definition at line 363 of file temperature.c.

void temp_set_nozzle_target ( float  c)

Sets the target temperature of the nozzle.

Parameters:
cthe target temperature of the nozzle in degrees Celsius.

Definition at line 302 of file temperature.c.

void temp_set_printbed_target ( float  c)

Sets the target temperature of the printbed.

Parameters:
cthe target temperature of the printbed in degrees Celsius.

Definition at line 343 of file temperature.c.

static bool temperature_reached ( struct heater h) [inline, static]

Returns whether a heater's target temperature has been reached.

This is considered to be the cases when its temperature is within 2 degrees celsius of the target temperature.

Parameters:
hpointer to the heater for which to check if the target temperature has been reached.
Returns:
True if the heater's target temperature has been reached and false otherwise.

Definition at line 273 of file temperature.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines