Microchip® Advanced Software Framework

main.c File Reference

XMEGA A3BU Class B demonstration.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include "oven.h"
#include "oven_controller.h"
#include "oven_plant.h"
#include "oven_ui.h"
#include "oven_classb.h"
#include <error_handler.h>
#include <classb_analog.h>
#include <classb_sram.h>
#include <classb_cpu.h>
#include <classb_freq.h>
#include <classb_interrupt_monitor.h>
#include <classb_rtc_common.h>
#include <classb_crc.h>

Macros

#define FIRST_POSSIBLE_TIMESTAMP   1293840000
 Default start time for RTC32: 01.01.2011 00:00:00 UTC. More...
 

Functions

int main (void)
 Main function. More...
 
static void main_execute_simulation_step (uint32_t time, const enum pot_t potstate)
 Executes a simulation step. More...
 
Information display functions
static void show_button_splash (void)
 Show button names on display. More...
 
static void show_explain_splash (void)
 Show explanation screen. More...
 
Hardware initialization functions
void main_init_adc_dac (void)
 Initialize ADC and DAC used to simulate a temperature sensor. More...
 
void main_init_tc (void)
 Initialize Timer/Counters used to simulate oven actuation signal. More...
 
static void main_init_rtc32 (void)
 Initialize RTC32 and VBAT. More...
 
static bool main_check_jumpers (void)
 Check for presence of required jumpers. More...
 

Variables

NO_INIT enum classb_error_value classb_error
 Global Class B error indicator. More...
 
volatile uint32_t classb_last_wdt_reset = 0
 Global holder for last WDT reset time. More...
 

#define FIRST_POSSIBLE_TIMESTAMP   1293840000

Default start time for RTC32: 01.01.2011 00:00:00 UTC.

static bool main_check_jumpers ( void  )
static

Check for presence of required jumpers.

This function checks that the two jumpers on header J1 and J2 are present. The jumpers should connect:

  • PC2 to PC4 (RXD to SS on header J1)
  • PB2 to PA4 (ADC2 to ADC4 on header J2)
Returns
true if both jumpers are present, false otherwise

References ioport_configure_pin(), IOPORT_DIR_INPUT, IOPORT_DIR_OUTPUT, ioport_get_value(), IOPORT_INIT_HIGH, IOPORT_PULL_DOWN, J1_PIN2, J1_PIN4, J2_PIN2, and J2_PIN4.

Referenced by main().

static void main_execute_simulation_step ( uint32_t  time,
const enum pot_t  potstate 
)
static

Executes a simulation step.

This function executes one step in the simulation of the cooking plate and updates the plot of temperature over time.

As input to the plots, an analog reading with ADCA is used to report the temperature of the plate, and the temperature of the pot contents is taken directly from the simulation state vector.

Parameters
timeRTC Time.
potstateTell the simulation whether the pot is on the plate.

References oven_plant_get_state_temp(), oven_plant_sim_step(), oven_ui_draw_plot_step(), and ovenctl_get_plate_temperature().

Referenced by main().

void main_init_adc_dac ( void  )

Initialize ADC and DAC used to simulate a temperature sensor.

DACB is used by the simulation plant to output a temperature reading of the oven plate. It is set up to output a voltage on pin B2 which is marked as ADC2 on header J2.

ADCA is used in the control step and graphical interface to show the current temperature of the oven plate. It is set up to read a voltage on pin A4 which is marked as ADC4 on header J2.

ADC2 and ADC4 should be connected together, so that the ADC samples the DAC directly.

References ADC_CH0, adc_enable(), adc_read_configuration(), ADC_REF_BANDGAP, ADC_RES_12, adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_ON, adc_start_conversion(), ADC_TRIG_MANUAL, adc_write_configuration(), ADCCH_NEG_NONE, ADCCH_POS_PIN4, adcch_read_configuration(), adcch_set_input(), adcch_write_configuration(), DAC_ADJ_RIGHT, DAC_CH0, dac_enable(), dac_read_configuration(), DAC_REF_BANDGAP, dac_set_active_channel(), dac_set_conversion_parameters(), dac_write_configuration(), IOPORT_DIR_INPUT, IOPORT_MODE_PULLDOWN, ioport_set_pin_dir(), ioport_set_pin_mode(), and J2_PIN4.

Referenced by main(), and ovenctl_turn_on_plate().

static void main_init_rtc32 ( void  )
static

Initialize RTC32 and VBAT.

This function checks the RTC32 and VBAT systems' status, initializing them if necessary. If the status is OK, only the RTC32 is reset.

To ensure that WDT resets occur with correct timing, the RTC32 is reset to the last time which was read out from it.

References classb_last_wdt_reset, RTC32, rtc_init(), rtc_set_time(), rtc_vbat_system_check(), sysclk_enable_module(), SYSCLK_PORT_GEN, SYSCLK_RTC, and VBAT_STATUS_OK.

Referenced by main().

void main_init_tc ( void  )

Initialize Timer/Counters used to simulate oven actuation signal.

TCC0 is set up to generate a dual variable frequency signal with dead-time insertion using the AWEX module. This is similar to how heating elements are actuated in real induction ovens. Its output is on pin C2 which is marked as RXD on header J1.

TCC1 is set up to capture a frequency signal via a pin change event using the XMEGA Event System. Its input is pin C4 which is marked as SS on header J1.

References FREQ_TIMER_PERIOD_INIT, IOPORT_BOTHEDGES, ioport_configure_pin(), IOPORT_DIR_INPUT, IOPORT_DIR_OUTPUT, J1_PIN2, J1_PIN4, OVEN_FREQ_CAPT_TC, OVEN_FREQ_TC, tc_awex_enable_ccb_deadtime(), tc_awex_set_dti_high(), tc_awex_set_dti_low(), tc_awex_set_output_override(), TC_CCA, TC_CCAEN, tc_enable(), tc_enable_cc_channels(), tc_set_input_capture(), tc_set_wgm(), TC_WG_FRQ, tc_write_cc(), and tc_write_clock_source().

Referenced by main(), and ovenctl_turn_on_plate().

static void show_button_splash ( void  )
static

Show button names on display.

This function shows the user what the different on-board buttons do. When the user presses a button, this function exits and the application can continue.

References gfx_mono_draw_filled_circle, gfx_mono_draw_filled_rect, gfx_mono_draw_string(), GFX_PIXEL_CLR, GFX_PIXEL_SET, GFX_WHOLE, keyboard_get_key_state(), KEYBOARD_RELEASE, oven_wdt_periodic_reset, sysfont, and keyboard_event::type.

Referenced by main().

static void show_explain_splash ( void  )
static

Show explanation screen.

This function draws an explanation screen, and is run if the applications are started without the jumpers described in the documentation attached.

References gfx_mono_draw_filled_rect, gfx_mono_draw_string(), GFX_PIXEL_CLR, keyboard_get_key_state(), KEYBOARD_RELEASE, oven_wdt_periodic_reset, sysfont, and keyboard_event::type.

Referenced by main().

volatile uint32_t classb_last_wdt_reset = 0

Global holder for last WDT reset time.

Global container for last WDT reset time.

Referenced by main(), and main_init_rtc32().