Unit tests for DAC driver using ADC.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <asf.h>
#include <conf_test.h>
Macros | |
DAC unit test definitions | |
#define | NUM_AVERAGE_SAMPLES 4 |
Number of samples to average over. More... | |
#define | NUM_CHANNELS 4 |
Number of ADC channels to use. More... | |
#define | DAC_MIN 0 |
Minimum value for DAC. More... | |
#define | DAC_MAX 0xfff |
Maximum value for DAC. More... | |
#define | DAC_8BIT_MAX 0xff |
Maximum value for DAC in 8-bit. More... | |
#define | ADC_ZERO 0 |
ADC zero value. More... | |
#define | ADC_UNSIGNED_8BIT_MAX 0xff |
Maximum value for ADC in unsigned 8-bit. More... | |
#define | ADC_UNSIGNED_12BIT_MAX 0xfff |
Maximum value for ADC in unsigned 12-bit. More... | |
#define | ADC_SIGNED_12BIT_MAX 0x7ff |
Maximum value for ADC in signed 12-bit. More... | |
#define | ADC_SIGNED_12BIT_MIN -0x800 |
Minimum value for ADC in signed 12-bit. More... | |
Functions | |
int | main (void) |
Run DAC unit tests. More... | |
DAC unit test helper functions | |
static uint16_t | left_adjust_8bit_value (uint16_t value) |
Shift 8 bit value to be used in left adjusted mode. More... | |
static void | single_ended_unsigned_average (ADC_t *adc, uint8_t ch_mask, const uint8_t *mux_inputs, uint8_t num_inputs, uint16_t *results) |
Measure single-ended input MUX combinations on channel. More... | |
static void | verify_unsigned_result (const struct test_case *test, uint16_t expected, uint16_t actual, uint8_t dac_ch, uint8_t adc_ch, uint8_t mux_input, uint16_t upper_limit, bool value_is_12bit) |
Verify that unsigned ADC result is in acceptable range. More... | |
DAC unit test functions | |
static void | run_dual_channel_12bit_conversion_test (const struct test_case *test) |
Test dual channel 12 bit conversion. More... | |
static void | run_dual_channel_8bit_conversion_test (const struct test_case *test) |
Test dual channel conversion in 8-bit mode using the DAC. More... | |
static void | run_single_channel_12bit_conversion_test (const struct test_case *test) |
Test single channel conversion in 12-bit mode using the DAC. More... | |
static void | run_single_channel_8bit_conversion_test (const struct test_case *test) |
Test single channel conversion in 8-bit mode using the DAC. More... | |
#define ADC_SIGNED_12BIT_MAX 0x7ff |
Maximum value for ADC in signed 12-bit.
#define ADC_SIGNED_12BIT_MIN -0x800 |
Minimum value for ADC in signed 12-bit.
#define ADC_UNSIGNED_12BIT_MAX 0xfff |
Maximum value for ADC in unsigned 12-bit.
Referenced by run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), and run_single_channel_8bit_conversion_test().
#define ADC_UNSIGNED_8BIT_MAX 0xff |
Maximum value for ADC in unsigned 8-bit.
#define ADC_ZERO 0 |
ADC zero value.
Referenced by run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), and run_single_channel_8bit_conversion_test().
#define DAC_8BIT_MAX 0xff |
Maximum value for DAC in 8-bit.
Referenced by run_dual_channel_8bit_conversion_test(), and run_single_channel_8bit_conversion_test().
#define DAC_MAX 0xfff |
Maximum value for DAC.
Referenced by run_dual_channel_12bit_conversion_test(), and run_single_channel_12bit_conversion_test().
#define DAC_MIN 0 |
Minimum value for DAC.
Referenced by run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), and run_single_channel_12bit_conversion_test().
#define NUM_AVERAGE_SAMPLES 4 |
Number of samples to average over.
Referenced by single_ended_unsigned_average().
#define NUM_CHANNELS 4 |
Number of ADC channels to use.
Referenced by run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), and run_single_channel_8bit_conversion_test().
|
static |
Shift 8 bit value to be used in left adjusted mode.
value | value to left adjust |
Referenced by run_dual_channel_8bit_conversion_test(), and run_single_channel_8bit_conversion_test().
int main | ( | void | ) |
Run DAC unit tests.
Initializes the clock system, board and serial output, then sets up the DAC unit test suite and runs it.
References usart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Test dual channel 12 bit conversion.
This tests output three different values on the two DAC channels:
These values are then measured using the ADC on the pins that are connected to the DAC channels, and the results are compared and checked to see if they are within the acceptable range of values that passes the test.
test | Current test case. |
References adc_read_configuration(), ADC_REF_BANDGAP, ADC_RES_12, adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_OFF, ADC_TRIG_MANUAL, ADC_UNSIGNED_12BIT_MAX, adc_write_configuration(), ADC_ZERO, DAC_ADJ_RIGHT, DAC_CH0, DAC_CH1, dac_enable(), DAC_MAX, DAC_MIN, dac_read_configuration(), DAC_REF_BANDGAP, dac_set_active_channel(), dac_set_channel_value(), dac_set_conversion_interval(), dac_set_conversion_parameters(), dac_set_conversion_trigger(), dac_set_refresh_interval(), dac_wait_for_channel_ready(), dac_write_configuration(), NUM_CHANNELS, single_ended_unsigned_average(), and verify_unsigned_result().
Referenced by main().
|
static |
Test dual channel conversion in 8-bit mode using the DAC.
This tests output three different values on the two DAC channels:
These values are then measured using the ADC on the pins that are connected to the DAC channels, using all available ADC channels and the results are compared and checked to see if they are within the acceptable range of values that passes the test.
test | Current test case. |
References adc_read_configuration(), ADC_REF_BANDGAP, ADC_RES_12, adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_OFF, ADC_TRIG_MANUAL, ADC_UNSIGNED_12BIT_MAX, adc_write_configuration(), ADC_ZERO, DAC_8BIT_MAX, DAC_ADJ_LEFT, DAC_CH0, DAC_CH1, dac_enable(), DAC_MIN, dac_read_configuration(), DAC_REF_BANDGAP, dac_set_active_channel(), dac_set_channel_value(), dac_set_conversion_interval(), dac_set_conversion_parameters(), dac_set_conversion_trigger(), dac_set_refresh_interval(), dac_wait_for_channel_ready(), dac_write_configuration(), left_adjust_8bit_value(), NUM_CHANNELS, single_ended_unsigned_average(), and verify_unsigned_result().
Referenced by main().
|
static |
Test single channel conversion in 12-bit mode using the DAC.
This tests output three different values on the two DAC channels:
These values are then measured using the ADC on the pins that are connected to the DAC channel, using all available ADC channels and the results are compared and checked to see if they are within the acceptable range of values that passes the test.
test | Current test case. |
References adc_read_configuration(), ADC_REF_BANDGAP, ADC_RES_12, adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_OFF, ADC_TRIG_MANUAL, ADC_UNSIGNED_12BIT_MAX, adc_write_configuration(), ADC_ZERO, DAC_ADJ_RIGHT, DAC_CH0, dac_enable(), DAC_MAX, DAC_MIN, dac_read_configuration(), DAC_REF_BANDGAP, dac_set_active_channel(), dac_set_channel_value(), dac_set_conversion_interval(), dac_set_conversion_parameters(), dac_set_conversion_trigger(), dac_set_refresh_interval(), dac_wait_for_channel_ready(), dac_write_configuration(), NUM_CHANNELS, single_ended_unsigned_average(), and verify_unsigned_result().
Referenced by main().
|
static |
Test single channel conversion in 8-bit mode using the DAC.
This tests output three different values on the two DAC channels:
These values are then measured using the ADC on the pins that are connected to the DAC channel, using all available ADC channels and the results are compared and checked to see if they are within the acceptable range of values that passes the test.
test | Current test case. |
References adc_read_configuration(), ADC_REF_BANDGAP, ADC_RES_12, adc_set_clock_rate(), adc_set_conversion_parameters(), adc_set_conversion_trigger(), ADC_SIGN_OFF, ADC_TRIG_MANUAL, ADC_UNSIGNED_12BIT_MAX, adc_write_configuration(), ADC_ZERO, DAC_8BIT_MAX, DAC_ADJ_LEFT, DAC_CH0, dac_enable(), dac_read_configuration(), DAC_REF_BANDGAP, dac_set_active_channel(), dac_set_channel_value(), dac_set_conversion_interval(), dac_set_conversion_parameters(), dac_set_conversion_trigger(), dac_set_refresh_interval(), dac_wait_for_channel_ready(), dac_write_configuration(), left_adjust_8bit_value(), NUM_CHANNELS, single_ended_unsigned_average(), and verify_unsigned_result().
Referenced by main().
|
static |
Measure single-ended input MUX combinations on channel.
Measures a set of input MUX combinations on a single channel, using averaging of the number of samples specified with NUM_AVERAGE_SAMPLES.
adc | Pointer to ADC to measure with. |
ch_mask | Mask for channel to measure with. |
mux_inputs | Pointer to array of input MUX settings. |
num_inputs | Number of input MUX settings. |
results | Pointer to array to store results in. |
References adc_disable(), adc_enable(), adc_get_result, adc_start_conversion(), adc_wait_for_interrupt_flag(), adcch_disable_interrupt(), ADCCH_MODE_COMPLETE, ADCCH_NEG_NONE, adcch_set_input(), adcch_set_interrupt_mode(), adcch_write_configuration(), and NUM_AVERAGE_SAMPLES.
Referenced by run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), and run_single_channel_8bit_conversion_test().
|
static |
Verify that unsigned ADC result is in acceptable range.
Checks that measurement is within the expected range, and outputs a clear error message to the unit test framework if it is not.
test | Pointer to current test case. |
expected | The expected ADC result. |
actual | The measured ADC result. |
dac_ch | The DAC channel used. |
adc_ch | The ADC channel used. |
mux_input | The ADC input MUX setting used. |
upper_limit | Upper limit of accepted range, can override the limit implicitly given by the accepted deviation. |
value_is_12bit | Specify the resolution of the ADC result and thus the accepted deviation:
|
References test_assert_true.
Referenced by run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), and run_single_channel_8bit_conversion_test().