Atmel Software Framework

oven_controller.c File Reference

Class B Oven controller.

Copyright (C) 2014-2015 Atmel Corporation. All rights reserved.

#include <asf.h>
#include "oven.h"
#include "oven_controller.h"
#include "oven_classb.h"
#include <error_handler.h>
#include <classb_cpu.h>
#include <classb_interrupt_monitor.h>
#include <classb_sram.h>

Functions

void ovenctl_execute_control_step (uint32_t time, uint8_t *wattage, bool *power, enum pot_t potstate)
 Execute oven control step. More...
 
uint16_t ovenctl_get_plate_temperature (void)
 Reads a 16-bit analog value on ADC channel 0 and returns it. More...
 
Internal test functions
static void ovenctl_periodic_temperature_sanity_check (void)
 Perform a sanity check on the temperature measured by the ADC. More...
 
static void ovenctl_periodic_classb_tests (void)
 Execute SRAM and CPU tests. More...
 
static void ovenctl_turn_on_plate (void)
 Run tests and turn on power to simulated oven plate. More...
 
static void ovenctl_turn_off_plate (uint8_t *wattage, bool *power)
 Turn off power to simulated oven plate, disable tests. More...
 
static void ovenctl_actuate_induction_element (uint8_t wattage)
 Updates or turns off the signal to the induction element. More...
 

static void ovenctl_actuate_induction_element ( uint8_t  wattage)
static

Updates or turns off the signal to the induction element.

Converts a wattage value to a signal period. Higher wattage means shorter period, which means more induced power if this was a physical stove top.

Parameters
wattagevalue representing the desired power level.

References OVEN_FREQ_TC, and tc_write_clock_source().

Referenced by ovenctl_execute_control_step().

void ovenctl_execute_control_step ( uint32_t  time,
uint8_t *  wattage,
bool power,
enum pot_t  potstate 
)

Execute oven control step.

This function takes information from the user interface, temperature sensor and plate (QTouch) sensing and controls the output to the induction elements via a frequency signal.

The oven has three states:

  • POWER_OFF where we just wait for input from the user interface to turn on.
  • ON_NO_POT where the user has indicated that power should be applied, but there is no pot in the plate. A safety timer changes the state back to POWER_OFF.
  • ON_ACTUATING where we have a pot on the oven, and actuate the induction elements while waiting for user input, and check if there is a pot on the oven.
Parameters
timeCurrent system time in milliseconds.
*wattagePointer to the variable representing the desired effect
*powerPointer to the variable controlling whether the induction coils should be actuated.
potstateA variable representing the latest information on whether anything is present on the plate (QTouch sensor)

References ON_ACTUATING, ON_NO_POT, ovenctl_actuate_induction_element(), ovenctl_turn_off_plate(), ovenctl_turn_on_plate(), POT_OFF, POT_ON, POWER_OFF, and rtc_get_time().

Referenced by main().

uint16_t ovenctl_get_plate_temperature ( void  )

Reads a 16-bit analog value on ADC channel 0 and returns it.

In this application CH0 is set up to read the analog voltage from a simulated thermometer.

Returns
Temperature of the induction element.

References ADC_CH0, adc_get_unsigned_result(), adc_start_conversion(), and adc_wait_for_interrupt_flag().

Referenced by main_execute_simulation_step(), and ovenctl_periodic_temperature_sanity_check().

static void ovenctl_periodic_classb_tests ( void  )
static

Execute SRAM and CPU tests.

This is an example of how the Class B interrupt monitor is used. The tests performed in this function are not required to be run periodically for Class B certification.

Returns
Nothing is returned, but the tests will alter the state of the global classb_error if an error is detected.

References classb_intmon_increase(), classb_register_test(), classb_sram_test(), and PER_CLASSB_TESTS.

Referenced by ovenctl_turn_on_plate().

static void ovenctl_periodic_temperature_sanity_check ( void  )
static

Perform a sanity check on the temperature measured by the ADC.

This is an example of how the Class B interrupt monitor is used, and as such does not perform a rigorous check.

An error can be induced by removing the jumper between ADC2 and ADC4 on the J2 header on the XPLAINED board.

Returns
Nothing is returned, but the test will alter the state of the global classb_error if an error is detected.

References classb_error, CLASSB_ERROR_OTHER, classb_intmon_increase(), ovenctl_get_plate_temperature(), temp, and TEMP_SANITY_TEST.

Referenced by ovenctl_turn_on_plate().

static void ovenctl_turn_off_plate ( uint8_t *  wattage,
bool power 
)
static

Turn off power to simulated oven plate, disable tests.

This function modified the simulation input to zero (zero watts, no power input), then turns off the periodic tests and disables monitoring of them.

Parameters
*wattagePointer to the value representing desired power level
*powerPointer to the value representing whether the desired power level should be applied to the induction element.

References classb_intmon_set_state(), M_DISABLE, OVEN_PERIODIC_CLASSB_TC, OVEN_PERIODIC_TEMPTEST_TC, PER_CLASSB_TESTS, tc_reset(), tc_write_clock_source(), and TEMP_SANITY_TEST.

Referenced by ovenctl_execute_control_step().

static void ovenctl_turn_on_plate ( void  )
static

Run tests and turn on power to simulated oven plate.

This functions runs some class B tests, reinitializes Timer/Counters, ADC and DAC used by the oven, then turns on and starts monitoring of periodic tests.

References classb_intmon_set_state(), M_ENABLE, main_init_adc_dac(), main_init_tc(), oven_classb_run_tests(), OVEN_PERIODIC_CLASSB_TC, OVEN_PERIODIC_TEMPTEST_TC, ovenctl_periodic_classb_tests(), ovenctl_periodic_temperature_sanity_check(), PER_CLASSB_TESTS, tc_enable(), tc_set_overflow_interrupt_callback(), tc_set_overflow_interrupt_level(), tc_write_clock_source(), tc_write_period(), and TEMP_SANITY_TEST.

Referenced by ovenctl_execute_control_step().