Synergy Software Package User's Manual

Driver for the 24-bit Sigma Delta A/D Converter (SDADC). More...

Data Structures

struct  sdadc_calibrate_args_t
 
struct  sdadc_channel_cfg_t
 
struct  adc_on_sdadc_cfg_t
 
struct  sdadc_instance_ctrl_t
 

Macros

#define SDADC_CODE_VERSION_MAJOR   (2U)
 

Enumerations

enum  sdadc_vref_src_t { SDADC_VREF_SRC_INTERNAL = 0, SDADC_VREF_SRC_EXTERNAL = 1 }
 
enum  sdadc_vref_voltage_t {
  SDADC_VREF_VOLTAGE_800_MV = 0, SDADC_VREF_VOLTAGE_1000_MV = 1, SDADC_VREF_VOLTAGE_1200_MV = 2, SDADC_VREF_VOLTAGE_1400_MV = 3,
  SDADC_VREF_VOLTAGE_1600_MV = 4, SDADC_VREF_VOLTAGE_1800_MV = 5, SDADC_VREF_VOLTAGE_2000_MV = 6, SDADC_VREF_VOLTAGE_2200_MV = 7,
  SDADC_VREF_VOLTAGE_2400_MV = 15
}
 
enum  sdadc_channel_input_t { SDADC_CHANNEL_INPUT_DIFFERENTIAL = 0, SDADC_CHANNEL_INPUT_SINGLE_ENDED = 1 }
 
enum  sdadc_channel_stage_1_gain_t {
  SDADC_CHANNEL_STAGE_1_GAIN_1 = 0, SDADC_CHANNEL_STAGE_1_GAIN_2 = 1, SDADC_CHANNEL_STAGE_1_GAIN_3 = 2, SDADC_CHANNEL_STAGE_1_GAIN_4 = 3,
  SDADC_CHANNEL_STAGE_1_GAIN_8 = 4
}
 
enum  sdadc_channel_stage_2_gain_t { SDADC_CHANNEL_STAGE_2_GAIN_1 = 0, SDADC_CHANNEL_STAGE_2_GAIN_2 = 1, SDADC_CHANNEL_STAGE_2_GAIN_4 = 2, SDADC_CHANNEL_STAGE_2_GAIN_8 = 3 }
 
enum  sdadc_channel_oversampling_t {
  SDADC_CHANNEL_OVERSAMPLING_64 = 0, SDADC_CHANNEL_OVERSAMPLING_128 = 1, SDADC_CHANNEL_OVERSAMPLING_256 = 2, SDADC_CHANNEL_OVERSAMPLING_512 = 3,
  SDADC_CHANNEL_OVERSAMPLING_1024 = 4, SDADC_CHANNEL_OVERSAMPLING_2048 = 5
}
 
enum  sdadc_channel_polarity_t { SDADC_CHANNEL_POLARITY_POSITIVE = 0, SDADC_CHANNEL_POLARITY_NEGATIVE = 1 }
 
enum  sdadc_channel_average_t {
  SDADC_CHANNEL_AVERAGE_NONE = 0, SDADC_CHANNEL_AVERAGE_8 = 12, SDADC_CHANNEL_AVERAGE_16 = 13, SDADC_CHANNEL_AVERAGE_32 = 14,
  SDADC_CHANNEL_AVERAGE_64 = 15
}
 
enum  sdadc_channel_inversion_t { SDADC_CHANNEL_INVERSION_OFF = 0, SDADC_CHANNEL_INVERSION_ON = 1 }
 
enum  sdadc_channel_count_formula_t { SDADC_CHANNEL_COUNT_FORMULA_EXPONENTIAL = 0, SDADC_CHANNEL_COUNT_FORMULA_LINEAR = 1 }
 
enum  sdadc_calibration_t { SDADC_CALIBRATION_INTERNAL_GAIN_OFFSET = 0, SDADC_CALIBRATION_EXTERNAL_OFFSET = 1, SDADC_CALIBRATION_EXTERNAL_GAIN = 2 }
 

Functions

ssp_err_t R_SDADC_Open (adc_ctrl_t *p_api_ctrl, adc_cfg_t const *const p_cfg)
 
ssp_err_t R_SDADC_ScanConfigure (adc_ctrl_t *p_api_ctrl, adc_channel_cfg_t const *const p_channel_cfg)
 
ssp_err_t R_SDADC_SampleStateCountSet (adc_ctrl_t *p_api_ctrl, adc_sample_state_t *p_sample)
 
ssp_err_t R_SDADC_InfoGet (adc_ctrl_t *p_api_ctrl, adc_info_t *p_adc_info)
 
ssp_err_t R_SDADC_ScanStart (adc_ctrl_t *p_api_ctrl)
 
ssp_err_t R_SDADC_ScanStop (adc_ctrl_t *p_api_ctrl)
 
ssp_err_t R_SDADC_CheckScanDone (adc_ctrl_t *p_api_ctrl)
 
ssp_err_t R_SDADC_Read (adc_ctrl_t *p_api_ctrl, adc_register_t const reg_id, uint16_t *const p_data)
 
ssp_err_t R_SDADC_Read32 (adc_ctrl_t *p_api_ctrl, adc_register_t const reg_id, uint32_t *const p_data)
 
ssp_err_t R_SDADC_OffsetSet (adc_ctrl_t *const p_api_ctrl, adc_register_t const reg_id, int32_t const offset)
 
ssp_err_t R_SDADC_Calibrate (adc_ctrl_t *const p_api_ctrl, void *const p_extend)
 
ssp_err_t R_SDADC_Close (adc_ctrl_t *p_api_ctrl)
 
ssp_err_t R_SDADC_VersionGet (ssp_version_t *const p_version)
 

Detailed Description

Driver for the 24-bit Sigma Delta A/D Converter (SDADC).

This module supports the SDADC peripheral. It implements the following interfaces:

Macro Definition Documentation

◆ SDADC_CODE_VERSION_MAJOR

#define SDADC_CODE_VERSION_MAJOR   (2U)

Version of code that implements the API defined in this file

Enumeration Type Documentation

◆ sdadc_calibration_t

Calibration mode.

Enumerator
SDADC_CALIBRATION_INTERNAL_GAIN_OFFSET 

Use internal reference to calibrate offset and gain.

SDADC_CALIBRATION_EXTERNAL_OFFSET 

Use external reference to calibrate offset.

SDADC_CALIBRATION_EXTERNAL_GAIN 

Use external reference to calibrate gain.

◆ sdadc_channel_average_t

Per channel number of conversions to average before conversion end callback.

Enumerator
SDADC_CHANNEL_AVERAGE_NONE 

Do not average (callback for each conversion)

SDADC_CHANNEL_AVERAGE_8 

Average 8 samples for each conversion end callback.

SDADC_CHANNEL_AVERAGE_16 

Average 16 samples for each conversion end callback.

SDADC_CHANNEL_AVERAGE_32 

Average 32 samples for each conversion end callback.

SDADC_CHANNEL_AVERAGE_64 

Average 64 samples for each conversion end callback.

◆ sdadc_channel_count_formula_t

Select a formula to specify the number of conversions. The following symbols are used in the formulas:

Either m or n must be non-zero.

Enumerator
SDADC_CHANNEL_COUNT_FORMULA_EXPONENTIAL 

N = 32 * (2 ^ n - 1) + m * 2 ^ n.

SDADC_CHANNEL_COUNT_FORMULA_LINEAR 

N = (32 * n) + m.

◆ sdadc_channel_input_t

Per channel input mode.

Enumerator
SDADC_CHANNEL_INPUT_DIFFERENTIAL 

Differential input.

SDADC_CHANNEL_INPUT_SINGLE_ENDED 

Single-ended input.

◆ sdadc_channel_inversion_t

Per channel polarity, valid for negative-side single-ended input only.

Enumerator
SDADC_CHANNEL_INVERSION_OFF 

Do not invert conversion result.

SDADC_CHANNEL_INVERSION_ON 

Invert conversion result.

◆ sdadc_channel_oversampling_t

Per channel oversampling ratio.

Enumerator
SDADC_CHANNEL_OVERSAMPLING_64 

Oversampling ratio of 64.

SDADC_CHANNEL_OVERSAMPLING_128 

Oversampling ratio of 128.

SDADC_CHANNEL_OVERSAMPLING_256 

Oversampling ratio of 256.

SDADC_CHANNEL_OVERSAMPLING_512 

Oversampling ratio of 512.

SDADC_CHANNEL_OVERSAMPLING_1024 

Oversampling ratio of 1024.

SDADC_CHANNEL_OVERSAMPLING_2048 

Oversampling ratio of 2048.

◆ sdadc_channel_polarity_t

Per channel polarity, valid for single-ended input only.

Enumerator
SDADC_CHANNEL_POLARITY_POSITIVE 

Positive-side single-ended input.

SDADC_CHANNEL_POLARITY_NEGATIVE 

Negative-side single-ended input.

◆ sdadc_channel_stage_1_gain_t

Per channel stage 1 gain options.

Enumerator
SDADC_CHANNEL_STAGE_1_GAIN_1 

Gain of 1.

SDADC_CHANNEL_STAGE_1_GAIN_2 

Gain of 2.

SDADC_CHANNEL_STAGE_1_GAIN_3 

Gain of 3 (only valid for stage 1)

SDADC_CHANNEL_STAGE_1_GAIN_4 

Gain of 4.

SDADC_CHANNEL_STAGE_1_GAIN_8 

Gain of 8.

◆ sdadc_channel_stage_2_gain_t

Per channel stage 2 gain options.

Enumerator
SDADC_CHANNEL_STAGE_2_GAIN_1 

Gain of 1.

SDADC_CHANNEL_STAGE_2_GAIN_2 

Gain of 2.

SDADC_CHANNEL_STAGE_2_GAIN_4 

Gain of 4.

SDADC_CHANNEL_STAGE_2_GAIN_8 

Gain of 8.

◆ sdadc_vref_src_t

Source of Vref.

Enumerator
SDADC_VREF_SRC_INTERNAL 

Vref is internally sourced, can be output as SBIAS.

SDADC_VREF_SRC_EXTERNAL 

Vref is externally sourced from the VREFI pin.

◆ sdadc_vref_voltage_t

Voltage of Vref.

Enumerator
SDADC_VREF_VOLTAGE_800_MV 

Vref is 0.8 V.

SDADC_VREF_VOLTAGE_1000_MV 

Vref is 1.0 V.

SDADC_VREF_VOLTAGE_1200_MV 

Vref is 1.2 V.

SDADC_VREF_VOLTAGE_1400_MV 

Vref is 1.4 V.

SDADC_VREF_VOLTAGE_1600_MV 

Vref is 1.6 V.

SDADC_VREF_VOLTAGE_1800_MV 

Vref is 1.8 V.

SDADC_VREF_VOLTAGE_2000_MV 

Vref is 2.0 V.

SDADC_VREF_VOLTAGE_2200_MV 

Vref is 2.2 V.

SDADC_VREF_VOLTAGE_2400_MV 

Vref is 2.4 V (only valid for external Vref)

Function Documentation

◆ R_SDADC_Calibrate()

ssp_err_t R_SDADC_Calibrate ( adc_ctrl_t *const  p_api_ctrl,
void *const  p_extend 
)

Requires sdadc_calibrate_args_t passed to p_extend. Calibrates the specified channel. Calibration is not required or supported for single-ended mode. Internal calibration is automatically done during open() unless it is disabled in the user configuration. This API is provided primarily for external calibration. A callback with the event ADC_EVENT_CALIBRATION_COMPLETE is called when calibration completes. The calibration status can also be monitored using adc_api_t::statusGet(). Implements adc_api_t::calibrate().

During external offset calibration, apply a differential voltage of 0 to ANSDnP - ANSDnN, where n is the input channel and ANSDnP is OPAMP0 for channel 4 and ANSDnN is OPAMP1 for channel 4. Complete external offset calibration before external gain calibration.

During external gain calibration apply a voltage between 0.4 V / total_gain and 0.8 V / total_gain. The differential voltage applied during calibration is corrected to a conversion result of 0x7FFFFF, which is the maximum possible positive differential measurement.

This function clears the offset value. If offset is required after calibration, it must be reapplied after calibration is complete using adc_api_t::offsetSet.

Return values
SSP_SUCCESSCalibration began successfully.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_IN_USEA conversion or calibration is in progress.
SSP_ERR_NOT_OPENInstance control block is not open.

Calibration cannot be performed if conversion or calibration is already in progress.

Select software trigger.

Select single scan mode.

Enable calibration.

Set the offset voltage to 0 mV.

Set the calibration mode.

Start calibration.

Confirm that calibration started.

Return the error code

◆ R_SDADC_CheckScanDone()

ssp_err_t R_SDADC_CheckScanDone ( adc_ctrl_t p_api_ctrl)

Returns the status of a scan started by software, including calibration scans. It is not possible to determine the status of a scan started by a hardware trigger. Implements adc_api_t::scanStatusGet().

Return values
SSP_SUCCESSNo software scan or calibration is in progress.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_IN_USEA conversion or calibration is in progress.
SSP_ERR_NOT_OPENInstance control block is not open.

If calibration is in progress, return an error.

Return the scan status of a scan triggered by software.

◆ R_SDADC_Close()

ssp_err_t R_SDADC_Close ( adc_ctrl_t p_api_ctrl)

Stops any scan in progress, disables interrupts, and powers down the SDADC peripheral. Implements adc_api_t::close().

Return values
SSP_SUCCESSInstance control block closed successfully.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Perform parameter checking

Mark driver as closed

Disable hardware triggers.

Stop A/D conversion.

Disable interrupts.

Wait 3 us in normal mode as required by the hardware manual.

Turn off the power of VBIAS, channel, and sigma-delta A/D converter.

Turn off the power of ADBGR, SBIAS, and ADREG.

Stop the input clock for the 24-bit sigma-delta A/D converter (SDADCCLK).

Enter the module-stop state.

Release the hardware lock

Return the error code

◆ R_SDADC_InfoGet()

ssp_err_t R_SDADC_InfoGet ( adc_ctrl_t p_api_ctrl,
adc_info_t p_adc_info 
)

Returns the address of the lowest number configured channel, the total number of results to be read in order to read the results of all configured channels, the size of each result, and the ELC event enumerations. Implements adc_api_t::infoGet().

Return values
SSP_SUCCESSInformation stored in p_adc_info.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Retrieve the scan mask of active channels from the control block

Determine the lowest channel that is configured.

Determine the highest channel that is configured.

Determine the size of data that must be read to read all the channels between and including the highest and lowest channels.

Determine the base address and transfer size.

Specify the peripheral name in the ELC list

Set sensor information to invalid value

◆ R_SDADC_OffsetSet()

ssp_err_t R_SDADC_OffsetSet ( adc_ctrl_t *const  p_api_ctrl,
adc_register_t const  reg_id,
int32_t const  offset 
)

Sets the offset. Offset is applied after stage 1 of the input channel. Offset can only be applied when the channel is configured for differential input. Implements adc_api_t::offsetSet().

Note: The offset is cleared if adc_api_t::calibrate() is called. The offset can be re-applied if necessary after the the callback with event ADC_EVENT_CALIBRATION_COMPLETE is called.

Parameters
[in]p_api_ctrlSee p_ctrl in adc_api_t::offsetSet().
[in]reg_idSee reg_id in adc_api_t::offsetSet().
[in]offsetMust be between -15 and 15, offset (mV) = 10.9376 mV * offset_steps / stage 1 gain.
Return values
SSP_SUCCESSOffset updated successfully.
SSP_ERR_INVALID_ARGUMENTAn input argument was outside the valid range.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_IN_USEA conversion or calibration is in progress.
SSP_ERR_NOT_OPENInstance control block is not open.

Offset cannot be updated if conversion or calibration is in progress.

Set the offset.

◆ R_SDADC_Open()

ssp_err_t R_SDADC_Open ( adc_ctrl_t p_api_ctrl,
adc_cfg_t const *const  p_cfg 
)

Applies power to the SDADC and initializes the hardware based on the user configuration. As part of this initialization, the SDADC clock is configured and enabled. If an interrupt priority is non-zero, enables an interrupt which will call a callback to notify the user when a conversion, scan, or calibration is complete. For all channels that are configured in differential mode, calibration is performed unless it is disabled in the user configuration. Implements adc_api_t::open().

Return values
SSP_SUCCESSConfiguration and calibration successful.
SSP_ERR_CALIBRATE_FAILEDCalibration failed.
SSP_ERR_ASSERTIONAn input pointer is NULL.
SSP_ERR_INVALID_ARGUMENTAn input argument is invalid.
SSP_ERR_IN_USEControl block is already open.
SSP_ERR_IRQ_BSP_DISABLEDA required interrupt is disabled
Returns
See Common Error Codes or functions called by this function for other possible return codes. This function calls:

Ensure the SDADC exists on the hardware, enable interrupts, and reserve the SDADC hardware lock.

Initialize the hardware based on the configuration.

Start the SDADC.

Configure the SDADC clock source and divisor to the clock source selected in the clock configuration.

Set the reference voltage for sensors (internal or external VREF mode).

Set the A/D conversion operation mode (normal or low power mode).

Supply the 24-bit sigma-delta A/D converter clock (SDADCCLK).

Turn on the power of ADBGR, SBIAS, and ADREG.

Stabilization wait time of 2 ms is required between power on of ADBGR/SBIAS/ADREG and VBIAS/channel/SDADC.

Turn on the power of VBIAS, channel, and sigma-delta A/D converter.

For each channel:

  1. Set the oversampling ratio.
  2. Set the gain.
  3. Select single-end input/differential input.
  4. If differential mode is used and calibration during open is not skipped, enable calibration on this channel.
  5. Select the polarity of single-end input (only for single-end mode).

Set the A/D conversion count.

  1. Select the averaging operation. Select the average data count.
    1. Select whether to reverse the A/D conversion results of single-end input (only for negative-side single end mode).
  2. Enable conversion for the channel.

Configure enabled channels and autoscan mode.

If the A/D conversion trigger is ELC hardware events, the hardware events are enabled in adc_api_t::scanStart().

Mark driver as open by initializing it to "SDAD" - its ASCII equivalent.

If at least one channel is configured for differential mode and calibration is not disabled in the user configuration, calibrate all PGAs configured for differential mode.

The calibration takes approximately 3.4 ms per channel in normal mode or 27 ms in low power mode. The open() API blocks waiting for calibration to complete unless calibration is skipped. Calibration during open can be skipped and handled in at the application level by setting adc_on_sdadc_cfg_t::skip_internal_calibration to true, then calling adc_api_t::calibrate().

◆ R_SDADC_Read()

ssp_err_t R_SDADC_Read ( adc_ctrl_t p_api_ctrl,
adc_register_t const  reg_id,
uint16_t *const  p_data 
)

Reads the most recent conversion result from a channel. Truncates 24-bit results to the upper 16 bits. Implements adc_api_t::read().

Return values
SSP_SUCCESSConversion result in p_data.
SSP_ERR_INVALID_ARGUMENTAn input argument was outside the valid range.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Read the most recent conversion value into a 16-bit result.

◆ R_SDADC_Read32()

ssp_err_t R_SDADC_Read32 ( adc_ctrl_t p_api_ctrl,
adc_register_t const  reg_id,
uint32_t *const  p_data 
)

Reads the most recent conversion result from a channel. Implements adc_api_t::read32().

Return values
SSP_SUCCESSConversion result in p_data.
SSP_ERR_INVALID_ARGUMENTAn input argument was outside the valid range.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

Read the most recent conversion value into a 32-bit result.

◆ R_SDADC_SampleStateCountSet()

ssp_err_t R_SDADC_SampleStateCountSet ( adc_ctrl_t p_api_ctrl,
adc_sample_state_t p_sample 
)

adc_api_t::sampleStateCountSet is not supported on the SDADC.

Return values
SSP_ERR_UNSUPPORTEDThis API is not supported.

Return the unsupported error.

◆ R_SDADC_ScanConfigure()

ssp_err_t R_SDADC_ScanConfigure ( adc_ctrl_t p_api_ctrl,
adc_channel_cfg_t const *const  p_channel_cfg 
)

Configures the enabled channels of the ADC. Only adc_channel_cfg_t::scan_mask is used. Implements adc_api_t::scanCfg().

Return values
SSP_SUCCESSInformation stored in p_adc_info.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.
SSP_ERR_INVALID_ARGUMENTAn input argument is invalid.

Update the enabled channels.

◆ R_SDADC_ScanStart()

ssp_err_t R_SDADC_ScanStart ( adc_ctrl_t p_api_ctrl)

If the SDADC is configured for hardware triggers, enables hardware triggers. Otherwise, starts a scan. Implements adc_api_t::scanStart().

Return values
SSP_SUCCESSScan started or hardware triggers enabled successfully.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.
SSP_ERR_IN_USEA conversion or calibration is in progress.

Conversion cannot be performed if conversion or calibration is already in progress.

If the unit is configured for software triggering, trigger a scan.

Otherwise, enable hardware triggers.

Return the error code

◆ R_SDADC_ScanStop()

ssp_err_t R_SDADC_ScanStop ( adc_ctrl_t p_api_ctrl)

If the SDADC is configured for hardware triggers, disables hardware triggers. Otherwise, stops any in-progress scan started by software. Implements adc_api_t::scanStop().

Return values
SSP_SUCCESSScan stopped or hardware triggers disabled successfully.
SSP_ERR_ASSERTIONAn input pointer was NULL.
SSP_ERR_NOT_OPENInstance control block is not open.

If the unit is configured for software triggering, stop the scan.

Otherwise, disable hardware triggers.

Return the error code

◆ R_SDADC_VersionGet()

ssp_err_t R_SDADC_VersionGet ( ssp_version_t *const  p_version)

Gets the API and code version. Implements adc_api_t::versionGet().

Return values
SSP_SUCCESSVersion information available in p_version.
SSP_ERR_ASSERTIONThe parameter p_version is NULL.

Return the version number