This set of functions performs counts to *volts conversions.
Functions | |
int16_t | Cy_SAR_RawCounts2Counts (const SAR_Type *base, uint32_t chan, int16_t adcCounts) |
Convert the channel result to a consistent result after accounting for averaging and subtracting the offset. More... | |
float32_t | Cy_SAR_CountsTo_Volts (const SAR_Type *base, uint32_t chan, int16_t adcCounts) |
Convert the ADC output to Volts as a float32. More... | |
int16_t | Cy_SAR_CountsTo_mVolts (const SAR_Type *base, uint32_t chan, int16_t adcCounts) |
Convert the ADC output to millivolts as an int16. More... | |
int32_t | Cy_SAR_CountsTo_uVolts (const SAR_Type *base, uint32_t chan, int16_t adcCounts) |
Convert the ADC output to microvolts as a int32. More... | |
cy_en_sar_status_t | Cy_SAR_SetOffset (uint32_t chan, int16_t offset) |
Override the channel offset stored in the Cy_SAR_offset array for the voltage conversion functions. More... | |
cy_en_sar_status_t | Cy_SAR_SetGain (uint32_t chan, int32_t adcGain) |
Override the gain stored in the Cy_SAR_countsPer10Volt array for the voltage conversion functions. More... | |
int16_t Cy_SAR_RawCounts2Counts | ( | const SAR_Type * | base, |
uint32_t | chan, | ||
int16_t | adcCounts | ||
) |
Convert the channel result to a consistent result after accounting for averaging and subtracting the offset.
The equation used is:
Counts = (RawCounts/AvgDivider - Offset)
where,
base | Pointer to structure describing registers |
chan | The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 |
adcCounts | Conversion result from Cy_SAR_GetResult16 |
This function is used by Cy_SAR_CountsTo_Volts, Cy_SAR_CountsTo_mVolts, and Cy_SAR_CountsTo_uVolts. Calling this function directly is usually not needed.
Convert the ADC output to Volts as a float32.
For example, if the ADC measured 0.534 volts, the return value would be 0.534. The calculation of voltage depends on the contents of Cy_SAR_offset, Cy_SAR_countsPer10Volt, and other parameters. The equation used is:
V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain
where,
base | Pointer to structure describing registers |
chan | The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 |
adcCounts | Conversion result from Cy_SAR_GetResult16 |
int16_t Cy_SAR_CountsTo_mVolts | ( | const SAR_Type * | base, |
uint32_t | chan, | ||
int16_t | adcCounts | ||
) |
Convert the ADC output to millivolts as an int16.
For example, if the ADC measured 0.534 volts, the return value would be 534. The calculation of voltage depends on the contents of Cy_SAR_offset, Cy_SAR_countsPer10Volt, and other parameters. The equation used is:
V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain mV = V * 1000
where,
base | Pointer to structure describing registers |
chan | The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 |
adcCounts | Conversion result from Cy_SAR_GetResult16 |
int32_t Cy_SAR_CountsTo_uVolts | ( | const SAR_Type * | base, |
uint32_t | chan, | ||
int16_t | adcCounts | ||
) |
Convert the ADC output to microvolts as a int32.
For example, if the ADC measured 0.534 volts, the return value would be 534000. The calculation of voltage depends on the contents of Cy_SAR_offset, Cy_SAR_countsPer10Volt, and other parameters. The equation used is:
V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain uV = V * 1000000
where,
base | Pointer to structure describing registers |
chan | The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1 |
adcCounts | Conversion result from Cy_SAR_GetResult16 |
cy_en_sar_status_t Cy_SAR_SetOffset | ( | uint32_t | chan, |
int16_t | offset | ||
) |
Override the channel offset stored in the Cy_SAR_offset array for the voltage conversion functions.
Offset is applied to counts before unit scaling and gain. See Cy_SAR_CountsTo_Volts for more about this formula.
To change channel 0's offset based on a known V_offset_mV, use:
Cy_SAR_SetOffset(0uL, -1 * V_offset_mV * (1uL << Resolution) / (2 * V_ref_mV));
chan | The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1. |
offset | The count value measured when the inputs are shorted or connected to the same input voltage. |
cy_en_sar_status_t Cy_SAR_SetGain | ( | uint32_t | chan, |
int32_t | adcGain | ||
) |
Override the gain stored in the Cy_SAR_countsPer10Volt array for the voltage conversion functions.
The gain is configured at initialization in Cy_SAR_Init based on the SARADC resolution and voltage reference.
Gain is applied after offset and unit scaling. See Cy_SAR_CountsTo_Volts for more about this formula.
To change channel 0's gain based on a known V_ref_mV, use:
Cy_SAR_SetGain(0uL, 10000 * (1uL << Resolution) / (2 * V_ref_mV));
chan | The channel number, between 0 and CY_SAR_MAX_NUM_CHANNELS - 1. |
adcGain | The gain in counts per 10 volt. |