ModusToolbox Safety Test Library
Loading...
Searching...
No Matches

General Description

Functions

uint8_t SelfTests_ATOP_DAC (uint32_t adcChannel, uint32_t dacSlice, const uint32_t *dacVals, uint32_t numVals, uint16_t accuracy)
 Performs ATOP DAC R2R loopback self-test using PDL functions.

Function Documentation

◆ SelfTests_ATOP_DAC()

uint8_t SelfTests_ATOP_DAC ( uint32_t adcChannel,
uint32_t dacSlice,
const uint32_t * dacVals,
uint32_t numVals,
uint16_t accuracy )

Performs ATOP DAC R2R loopback self-test using PDL functions.

This function initializes the DAC/ADC peripherals once and then tests multiple DAC values in a loop. For each value, it sets the DAC output, triggers ADC conversion, reads the result, and validates against the expected value with specified accuracy tolerance.

Parameters
adcChannelADC channel/group to use for measurement. Use ATOP_ADC_CHANNEL_0.
dacSliceDAC slice to test. Use ATOP_DAC_SLICE_0 or ATOP_DAC_SLICE_1.
dacValsPointer to array of DAC output codes to test (0-4095 for 12-bit DAC).
numValsNumber of values in the dacVals array.
accuracyAcceptable deviation in ADC codes. Test passes if: (dacVal - accuracy) <= adcResult <= (dacVal + accuracy)
Returns
OK_STATUS (0) - All tests passed, ADC results within tolerance
ERROR_STATUS (1) - Test failed (ADC result out of tolerance)
ERROR_BAD_PARAM (9) - Invalid parameters (bad slice, null pointer, incorrect accuracy)
MTB_STL_ERROR_TIMEOUT (10) - ADC conversion timed out
Note
The PPCA subsystem must be enabled by the caller before invoking this function (e.g. Cy_PPCA_Enable(PPCA_CNFG)). The test only configures AREF, DCSG, DAC, and ADC sub-blocks and restores their state on exit; it does not modify the top-level PPCA control register.
In loopback single-ended mode, DAC and ADC share the same voltage reference, so expected ADC result equals dacVal (1:1 code mapping).
static const uint32_t dac_test_values[] = {
0U, // Minimum code (0V)
2048U, // Mid-scale (1.65V)
4095U // Maximum code (3.3V)
};
#define DAC_TEST_NUM_VALUES (sizeof(dac_test_values) / sizeof(dac_test_values[0]))
#define DAC_TEST_ACCURACY 50U
// Enable PPCA subsystem before calling the self-test
Cy_PPCA_Enable(PPCA_CNFG);
// Test DAC Slice 0
dac_test_values, DAC_TEST_NUM_VALUES,
DAC_TEST_ACCURACY);
if (result != OK_STATUS)
{
// Handle error (ERROR_STATUS or ERROR_BAD_PARAM)
}
uint8_t SelfTests_ATOP_DAC(uint32_t adcChannel, uint32_t dacSlice, const uint32_t *dacVals, uint32_t numVals, uint16_t accuracy)
Performs ATOP DAC R2R loopback self-test using PDL functions.
#define ATOP_ADC_CHANNEL_0
ADC channel 0 (ADC_GRP_0)
Definition SelfTest_ATOP_DAC.h:73
#define ATOP_DAC_SLICE_0
DAC slice 0 (DAC_R2R_0 in DCSG_GRP_0)
Definition SelfTest_ATOP_DAC.h:67
#define OK_STATUS
Test passed / operation completed successfully.
Definition SelfTest_common.h:93