Safety ADC

group safety-adc

The safety ADC continuously monitors the microcontrollers internal core temperature (and therefore the whole device’s temperature) and the external reference voltage compared to its internal bandgap reference voltage.

Enums

enum safety_adc_meas_channel

The safety ADC’s measure channel.

Values:

enumerator SAFETY_ADC_MEAS_VREF

Internal reference voltage.

Note

This will not output the internal reference voltage but the recalculated external voltage!

enumerator SAFETY_ADC_MEAS_TEMP

Internal temperature sensor.

enumerator SAFETY_ADC_MEAS_SUPPLY

Supply voltage.

Functions

void safety_adc_init(void)

Initialize safety ADC. Only call this function once!

void safety_adc_deinit(void)

safety_adc_deinit Deactivate safety ADC

Warning

For completeness. Do not call! the safety ADC is a vital component. It’s malfunction will trigger a critical safety flag.

void safety_adc_trigger_meas(void)

safety_adc_trigger_meas

int safety_adc_poll_result(void)

Poll ADC result.

Return

1 if measurement successful, 0 if not ready, -1 if ADC aborted or not started

const uint16_t *safety_adc_get_values(void)

Get the sampled signal values of the safety ADC.

Use safety_adc_poll_result to poll for a finished conversion of the safety ADC. After that, it is safe to use the output values until a new conversion is triggered using safety_adc_trigger_meas

Warning

This function return a constant buffer, that is directly written on by the DMA! Check safety_adc_poll_result to prevent race conditions.

Return

Array of raw ADC readings with length of SAFETY_ADC_NUM_OF_CHANNELS

float safety_adc_convert_channel(enum safety_adc_meas_channel channel, uint16_t analog_value)

Convert a safety ADC raw value to an actual signal value.

Warning

Double check safety_adc_meas_channel to make sure you understand the output of this function correctly.

Return

Parameters
  • channel: Measurment channel to convert voltage for

  • analog_value: Raw value of the ADC to convert

void DMA2_Stream4_IRQHandler()

Variables

const uint8_t safety_adc_channels[SAFETY_ADC_NUM_OF_CHANNELS] = {SAFETY_ADC_CHANNELS}
uint8_t safety_adc_conversion_complete
uint8_t safety_adc_triggered
uint16_t safety_adc_conversions[SAFETY_ADC_NUM_OF_CHANNELS]