This set of functions is for initialization and basic usage.
More...
This set of functions is for initialization and basic usage.
◆ Cy_SAR_Init()
Initialize all SAR configuration registers.
If routing is to be configured, all switches will be cleared before being initialized.
- Note
- If interleaved averaging mode is used, the Differential Result Format should be the same as the Single-Ended Result Format. Otherwise, this function will return CY_SAR_BAD_PARAM.
- Parameters
-
- Returns
- CY_SAR_SUCCESS : initialization complete successfully
- CY_SAR_BAD_PARAM : input pointers are null or some configuration setting is invalid, initialization incomplete.
- Function Usage
◆ Cy_SAR_DeInit()
Reset SAR registers back to power on reset defaults.
- Parameters
-
base | Pointer to structure describing registers |
deInitRouting | If true, all SARMUX switches are opened and switch control registers are reset to zero. If false, switch registers are untouched. |
- Returns
-
- Function Usage
◆ Cy_SAR_Enable()
Power up the SAR ADC subsystem block.
The hardware is ready to use after 2 us, which is included in this function.
- Parameters
-
base | Pointer to structure describing registers |
- Returns
- None
◆ Cy_SAR_Disable()
Turn off the hardware block.
- Parameters
-
base | Pointer to structure describing registers |
- Returns
- None
◆ Cy_SAR_StartConvert()
Start a single scan (one shot) of all enabled channels or start scanning continuously.
When in continuous mode, all firmware and hardware triggers are ignored. To stop continuous scanning, call Cy_SAR_StopConvert.
- Parameters
-
- Returns
- None
- Function Usage
◆ Cy_SAR_StopConvert()
void Cy_SAR_StopConvert |
( |
SAR_Type * |
base | ) |
|
Stop continuous scanning of enabled channels.
If a conversion is currently executing, that conversion will complete, but no further conversions will occur until the next call to Cy_SAR_StartConvert or the next hardware trigger, if enabled.
- Parameters
-
base | Pointer to structure describing registers |
- Returns
- None
- Function Usage
◆ Cy_SAR_IsEndConversion()
Immediately return the status of the conversion or does not return (blocking) until the conversion completes, depending on the retMode parameter.
In blocking mode, there is a time out of about 10 seconds for a CPU speed of 48 MHz.
- Parameters
-
- Returns
-
- Side Effects
- This function reads the end of conversion status and clears it after.
- Note
- CY_SAR_WAIT_FOR_RESULT and CY_SAR_WAIT_FOR_RESULT_INJ return modes are not recommended, especially in RTOS applications, as the timeout is generated by the CPU waiting for a few seconds. It is recommended to handle the timeout in the user firmware.
- Function Usage
◆ Cy_SAR_GetBusyStatus()
bool Cy_SAR_GetBusyStatus |
( |
const SAR_Type * |
base | ) |
|
Get SAR conversion status.
- Parameters
-
base | Pointer to structure describing registers |
- Returns
- TRUE : SAR conversion is busy. FALSE: SAR conversion is not busy.
◆ Cy_SAR_GetResult16()
int16_t Cy_SAR_GetResult16 |
( |
const SAR_Type * |
base, |
|
|
uint32_t |
chan |
|
) |
| |
Return the data available in the channel result data register as a signed 16-bit integer.
- Parameters
-
base | Pointer to structure describing registers |
chan | The channel to read the result from, between 0 and CY_SAR_INJ_CHANNEL |
- Returns
- Data is returned as a signed 16-bit integer. If channel number is invalid, 0 is returned.
- Function Usage
uint32_t chan = 0UL;
int16_t result;
int16_t resultmV;
◆ Cy_SAR_GetResult32()
int32_t Cy_SAR_GetResult32 |
( |
const SAR_Type * |
base, |
|
|
uint32_t |
chan |
|
) |
| |
Return the data available in the channel result data register as a signed 32-bit integer.
- Parameters
-
base | Pointer to structure describing registers |
chan | The channel to read the result from, between 0 and CY_SAR_INJ_CHANNEL |
- Returns
- Data is returned as a signed 32-bit integer. If channel number is invalid, 0 is returned.
- Function Usage
uint32_t chan = 0UL;
int32_t result;
◆ Cy_SAR_GetChanResultUpdated()
__STATIC_INLINE uint32_t Cy_SAR_GetChanResultUpdated |
( |
const SAR_Type * |
base | ) |
|
Return whether the RESULT register has been updated or not.
If the bit is high, the corresponding channel RESULT register was updated, i.e. was sampled during the previous scan.
- Parameters
-
base | Pointer to structure describing registers |
- Returns
- Each bit of the result corresponds to the channel. Bit 0 is for channel 0, etc.
- Function Usage
uint32_t chan = 0UL;
uint32_t chanMask = (1u << chan);
uint32_t chanResultUpdated;
if (chanMask == (chanResultUpdated & chanMask))
{
}
◆ Cy_SAR_EnableInjection()
__STATIC_INLINE void Cy_SAR_EnableInjection |
( |
SAR_Type * |
base, |
|
|
bool |
tailgating |
|
) |
| |
Triggers the injection channel sample.
- Parameters
-
base | Pointer to structure describing registers |
tailgating | Injection channel tailgating enable:
- true: The addressed pin is sampled after the next trigger and after all enabled channels have been scanned.
- false: SAR is immediately triggered when the SAR is not busy. If the SAR is busy, the INJ channel addressed pin is sampled at the end of the current scan.
|
- Function Usage