## LSAD Function Documentation

### Sys_LSAD_Gain_Offset

void Sys_LSAD_Gain_Offset(const volatile struct LSAD_TRIM * i_gain_offset, struct F_LSAD_TRIM * f_gain_offset)

Convert a gain and offset value from NVR in integer format to float format.

Location: lsad.h:220

Parameters

Direction | Name | Description
--- | --- | ---
in | i_gain_offset | Gain and offset error from NVR, raw integer form
out | f_gain_offset | Gain and offset error converted to floating point.

Example Code for Sys_LSAD_Gain_Offset
// Convert gain and offset values in integer format to floating point values // used in compensation for LSAD measurements. Low frequency and high frequency // values are converted. F_LSAD_TRIM f_gain_offset[1]; Sys_LSAD_Gain_Offset(&(trim_region->temp_sensor), &(f_gain_offset[0]));

### Sys_LSAD_TempSensor_Gain_Offset

void Sys_LSAD_TempSensor_Gain_Offset(const volatile struct TEMP_SENSOR_TRIM * i_gain_offset, struct F_LSAD_TRIM * f_gain_offset)

Convert a gain and offset value from NVR in integer format to float format for the temperature sensor.

Location: lsad.h:242

Parameters

Direction | Name | Description
--- | --- | ---
in | i_gain_offset | Gain and offset error from NVR, raw integer form
out | f_gain_offset | Gain and offset error converted to floating point.

Example Code for Sys_LSAD_TempSensor_Gain_Offset
// Convert gain and offset values in integer format to floating point values // used in compensation of measurements for the temperature sensor. Only low // frequency values are converted. F_LSAD_TRIM f_gain_offset[1]; Sys_LSAD_TempSensor_Gain_Offset(&(trim_region->temp_sensor), &(f_gain_offset[0]);

### Sys_LSAD_TrimsInit

void Sys_LSAD_TrimsInit()

Loads ATE trim values specific to the LSAD.

Location: lsad.h:257

Example Code for Sys_LSAD_TrimsInit
// Initialize the LSAD with calibrated trim values. Sys_LSAD_TrimsInit();

### Sys_LSAD_ModeConfig

void Sys_LSAD_ModeConfig(lsad_mode_t mode)

Configure the LSAD to use either normal or continuous mode.

Location: lsad.h:264

Parameters

Direction | Name | Description
--- | --- | ---
in | mode | Either normal (sample all channels) or continuous (sample one channel)

Example Code for Sys_LSAD_ModeConfig
// Configure the LSAD to normal mode, where the LSAD converts channels. Sys_LSAD_ModeConfig(LSAD_MODE_NORMAL);

### Sys_LSAD_AlarmConfig

void Sys_LSAD_AlarmConfig(lsad_channel_t channel, uint8_t threshold, uint8_t count)

Configure the LSAD monitor alarm.

Location: lsad.h:274

Parameters

Direction | Name | Description
--- | --- | ---
in | channel | The LSAD channel on which to enable the alarm
in | threshold | The value below which the alarm should be triggered. The values 0-255 are linearly mapped to 0-2 V with a step size of 7.8 mV.
in | count | The number of readings below the threshold needed to trigger the alarm

Example Code for Sys_LSAD_AlarmConfig
// Configure the LSAD to trigger the monitor alarm when the voltage on channel 0 // drops below the value encoded in ALARM_THRESHOLD for ALARM_COUNT number of samples. Sys_LSAD_AlarmConfig(LSAD_INPUT_CH0, ALARM_THRESHOLD, ALARM_COUNT);

### Sys_LSAD_InterruptEnable

void Sys_LSAD_InterruptEnable(lsad_channel_t IRQ_channel)

Sets LSAD interrupt to occur on conversion of the selected channel.

Location: lsad.h:282

Parameters

Direction | Name | Description
--- | --- | ---
in | IRQ_channel | The channel after which to interrupt. In continuous mode, this is the only channel sampled.

Example Code for Sys_LSAD_InterruptEnable
// Enable LSAD interrupt, set to trigger after sampling channel LSAD_IRQ_CHANNEL by default. // It can be configured to a different channel in app.h of the LSAD sample. Sys_LSAD_InterruptEnable(LSAD_IRQ_CHANNEL);

### Sys_LSAD_Start

void Sys_LSAD_Start(lsad_prescale_t prescale)

Start LSAD measurements at the frequency determined by the specified prescale.

Location: lsad.h:289

Parameters

Direction | Name | Description
--- | --- | ---
in | prescale | The prescale setting used to derive the LSAD sampling frequency

Example Code for Sys_LSAD_Start
// Start LSAD measurements with the frequency determined by prescale value. Sys_LSAD_Start(LSAD_PRESCALE);

### Sys_LSAD_Stop

void Sys_LSAD_Stop()

Stop LSAD measurements.

Location: lsad.h:295

Example Code for Sys_LSAD_Stop
// Stop LSAD measurements Sys_LSAD_Stop();

### Sys_LSAD_InputConfig

uint32_t Sys_LSAD_InputConfig(lsad_channel_t channel, lsad_io_t pos_io, lsad_io_t neg_io)

Configure LSAD channel inputs.

Location: lsad.h:306

Parameters

Direction | Name | Description
--- | --- | ---
in | channel | The LSAD channel to configure
in | pos_io | The signal to connect to the positive input of the channel
in | neg_io | The signal to connect to the negative input of the channel

Return

Resulting input selection register

Example Code for Sys_LSAD_InputConfig
// Use LSAD channel 0. // Set LSAD positive source to GPIO13. // Set LSAD negative source to Ground. Sys_LSAD_InputConfig(LSAD_INPUT_CH0, LSAD_GPIO13_CFG, LSAD_GROUND_CFG);

### Sys_LSAD_Special_InputConfig

uint8_t Sys_LSAD_Special_InputConfig(lsad_io_t gpio)

Read special LSAD configuration from the LSAD_SpecialCfg array.

Location: lsad.h:314

Parameters

Direction | Name | Description
--- | --- | ---
in | gpio | The signal to compare with special LSAD input values

Return

The corresponding LSAD configuration

Example Code for Sys_LSAD_Special_InputConfig
// Get the positive input configurations of the LSAD. lsad_io_t pos_io = LSAD_GPIO13_CFG; uint8_t pos_lsad_cfg; pos_lsad_cfg = Sys_LSAD_Special_InputConfig(pos_io);

### Sys_LSAD_PreSelectWrite

uint32_t Sys_LSAD_PreSelectWrite(uint8_t cfg, lsad_io_t gpio, lsad_in_t input_type)

Set LSAD->PRE_SEL_INPUT and return configuration which is written to LSAD->INPUT_SEL[channel].

Location: lsad.h:326

Parameters

Direction | Name | Description
--- | --- | ---
in | cfg | The LSAD configuration returned from Sys_LSAD_InputConfig()
in | gpio | The signal to be configured as an LSAD input
in | input_type | Specifies if the signal should be connected to the positive or negative input

Return

The configuration data for the input selection register

Example Code for Sys_LSAD_PreSelectWrite
// Set the LSAD pre-selection register to positive input and return the // configuration that should be written to LSAD->INPUT_SEL[channel]. uint32_t pos_sel; pos_sel = Sys_LSAD_PreSelectWrite(pos_lsad_cfg, pos_io, POS_IN);

### Sys_LSAD_GPIO_InputConfig

uint8_t Sys_LSAD_GPIO_InputConfig(lsad_io_t gpio)

This function reads GPIO configuration from LSAD_GPIOCfg array.

Location: lsad.h:335

Parameters

Direction | Name | Description
--- | --- | ---
in | gpio | The signal to compare with gpio numbers

Return

lsad_conf

Example Code for Sys_LSAD_GPIO_InputConfig
// Get the GPIO configuration of the specified GPIO (13). lsad_io_t gpio = LSAD_GPIO13_CFG; cfg = Sys_LSAD_GPIO_InputConfig(gpio);

### Sys_LSAD_GetRawData

uint32_t Sys_LSAD_GetRawData(lsad_channel_t channel)

Obtain the latest data from the DATA_TRIM_CH register.

Location: lsad.h:344

Parameters

Direction | Name | Description
--- | --- | ---
in | channel | The LSAD channel from which to obtain data

Return

The obtained data

Example Code for Sys_LSAD_GetRawData
// Sum the incoming LSAD data to be averaged later. static int32_t raw_LSAD_sum[NUM_LSAD_CHANNELS_USED] = {0}; for(uint8_t chn = 0; chn < NUM_LSAD_CHANNELS_USED; chn++) { raw_LSAD_sum[chn] += Sys_LSAD_GetRawData((lsad_channel_t)chn); }

### Sys_LSAD_ConvertToMVUntrimmed

uint32_t Sys_LSAD_ConvertToMVUntrimmed(uint32_t raw_data)

Convert data from DATA_TRIM_CH to millivolts using calibrated trim data.

Location: lsad.h:353

Parameters

Direction | Name | Description
--- | --- | ---
in | raw_data | The value obtained from DATA_TRIM_CH

Return

The converted data

Example Code for Sys_LSAD_ConvertToMVUntrimmed
// Process the averaged data without calibrated trim values. int32_t lsad_mv_raw = Sys_LSAD_ConvertToMVUntrimmed(raw_LSAD_avg);

### Sys_LSAD_ConvertToMVTrimmed

int32_t Sys_LSAD_ConvertToMVTrimmed(uint32_t raw_data)

Convert data from DATA_TRIM_CH to millivolts without using calibrated trim data.

Location: lsad.h:362

Parameters

Direction | Name | Description
--- | --- | ---
in | raw_data | The value obtained from DATA_TRIM_CH

Return

The converted data

Example Code for Sys_LSAD_ConvertToMVTrimmed
// Process the averaged data with calbirated trim values. int32_t lsad_mv_calib = Sys_LSAD_ConvertToMVTrimmed(raw_LSAD_avg);

### Sys_LSAD_NewSampleClear

void Sys_LSAD_NewSampleClear()

Clears the ready bit from the MONITOR_STATUS register to acknowledge the most recent LSAD sample and indicate that the next sample will not cause an overrun.

Location: lsad.h:370

Example Code for Sys_LSAD_NewSampleClear
// Clear LSAD ready bit, indicating LSAD data has been processed so // the next conversion completion will not cause an overrun. Sys_LSAD_NewSampleClear();