MCUXpresso SDK API Reference Manual  Rev 2.12.1
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
GPADC: General Purpose ADC Driver

ADC driver supports read voltage for internal sensor for external pin. More...

Overview

The MCUXpresso SDK provides a driver for the GPADC.

The typical workflow:

Optionally, GPADC_SetThreshold can be called to set the threshold for each sensor, meanwhile, GPADC_RegisterCallback can register the callback when voltage out of threshold range. the external pin shares the same threshold with kGPADC_SensorVBAT_ExtPin.

Macros

#define FSL_GPADC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 GPADC driver version. More...
 

Typedefs

typedef void(* gpadc_callback_t )(void)
 GPADC callback. More...
 

Enumerations

enum  gpadc_sensor_t {
  kGPADC_SensorReserved = E_PN76_PCRM_GPADC_SENSOR_RESERVED,
  kGPADC_SensorRSSI = E_PN76_PCRM_GPADC_SENSOR_RSSI_OUT,
  kGPADC_SensorBandgap = E_PN76_PCRM_GPADC_SENSOR_VBG_SNS,
  kGPADC_SensorTempPmu = E_PN76_PCRM_GPADC_SENSOR_TEMP_PMU,
  kGPADC_SensorTempClif = E_PN76_PCRM_GPADC_SENSOR_TEMP_CLIF,
  kGPADC_SensorXtalPeakDet = E_PN76_PCRM_GPADC_SENSOR_XTAL_PEAK_DET,
  kGPADC_SensorVBAT_ExtPin = E_PN76_PCRM_GPADC_SENSOR_VBAT,
  kGPADC_SensorGround = E_PN76_PCRM_GPADC_SENSOR_GROUND,
  kGPADC_SensorVDDPA = E_PN76_PCRM_GPADC_SENSOR_VDDPA
}
 GPADC sensor selection. More...
 
enum  gpadc_value_type_t {
  kGPADC_TypeVal = E_PN76_PCRM_GPADC_TYPE_VAL,
  kGPADC_TypeMin = E_PN76_PCRM_GPADC_TYPE_MIN,
  kGPADC_TypeMax = E_PN76_PCRM_GPADC_TYPE_MAX,
  kGPADC_TypeIIR = E_PN76_PCRM_GPADC_TYPE_IIR,
  kGPADC_TypeAvg = E_PN76_PCRM_GPADC_TYPE_AVG,
  kGPADC_TypeConv = E_PN76_PCRM_GPADC_TYPE_CONV,
  kGPADC_TypeGross = E_PN76_PCRM_GPADC_TYPE_GROSS,
  kGPADC_TypeSingleEnd = E_PN76_PCRM_GPADC_TYPE_SINGLE_ENDED,
  kGPADC_TypeDifferential = E_PN76_PCRM_GPADC_TYPE_DIFFERENTIAL,
  kGPADC_TypeConvGrossMask = E_PN76_PCRM_GPADC_TYPE_CONV_GROSS_MASK,
  kGPADC_TypeValMask = E_PN76_PCRM_GPADC_TYPE_VAL_MASK,
  kGPADC_TypeMeasureTypeMask,
  kGPADC_TypeValConv = E_PN76_PCRM_GPADC_TYPE_VAL_CONV,
  kGPADC_TypeMinConv = E_PN76_PCRM_GPADC_TYPE_MIN_CONV,
  kGPADC_TypeMaxConv = E_PN76_PCRM_GPADC_TYPE_MAX_CONV,
  kGPADC_TypeIIRConv = E_PN76_PCRM_GPADC_TYPE_IIR_CONV,
  kGPADC_TypeAvgConv = E_PN76_PCRM_GPADC_TYPE_AVG_CONV,
  kGPADC_TypeValGross = E_PN76_PCRM_GPADC_TYPE_VAL_GROSS,
  kGPADC_TypeMinGross = E_PN76_PCRM_GPADC_TYPE_MIN_GROSS,
  kGPADC_TypeMaxGross = E_PN76_PCRM_GPADC_TYPE_MAX_GROSS,
  kGPADC_TypeIIRGross = E_PN76_PCRM_GPADC_TYPE_IIR_GROSS,
  kGPADC_TypeAvgGross = E_PN76_PCRM_GPADC_TYPE_AVG_GROSS,
  kGPADC_TypeValConvDiff = E_PN76_PCRM_GPADC_TYPE_VAL_CONV_DIFF,
  kGPADC_TypeMinConvDiff = E_PN76_PCRM_GPADC_TYPE_MIN_CONV_DIFF,
  kGPADC_TypeMaxConvDiff = E_PN76_PCRM_GPADC_TYPE_MAX_CONV_DIFF,
  kGPADC_TypeIIRConvDiff = E_PN76_PCRM_GPADC_TYPE_IIR_CONV_DIFF,
  kGPADC_TypeAvgConvDiff = E_PN76_PCRM_GPADC_TYPE_AVG_CONV_DIFF,
  kGPADC_TypeValGrossDiff = E_PN76_PCRM_GPADC_TYPE_VAL_GROSS_DIFF,
  kGPADC_TypeMinGrossDiff = E_PN76_PCRM_GPADC_TYPE_MIN_GROSS_DIFF,
  kGPADC_TypeMaxGrossDiff = E_PN76_PCRM_GPADC_TYPE_MAX_GROSS_DIFF,
  kGPADC_TypeIIRGrossDiff = E_PN76_PCRM_GPADC_TYPE_IIR_GROSS_DIFF,
  kGPADC_TypeAvgGrossDiff = E_PN76_PCRM_GPADC_TYPE_AVG_GROSS_DIFF
}
 Enum for Different General Purpose Analog to Digital Converter (GPADC) value types. More...
 

Functions

static pn_status_t GPADC_Init (void)
 Performs GPADC Initialization. More...
 
pn_status_t GPADC_ReadSensor (gpadc_sensor_t eSensor, gpadc_value_type_t eType, int32_t *milliVolt)
 This function returns the requested sensor value. More...
 
pn_status_t GPADC_ReadSensorOneShot (gpadc_sensor_t eSensor, gpadc_value_type_t eType, int32_t *milliVolt)
 This function returns the instant value of requested sensor. More...
 
static pn_status_t GPADC_SetThreshold (gpadc_sensor_t eSensor, gpadc_value_type_t eType, int16_t wLowThreshold, int16_t wHighThreshold)
 This function Sets the thresholds for requested sensor. More...
 
static pn_status_t GPADC_GetThreshold (gpadc_sensor_t eSensor, gpadc_value_type_t eType, int16_t *wLowThreshold, int16_t *wHighThreshold)
 This function Reads the thresholds of requested sensor. More...
 
static void GPADC_Deinit (void)
 Performs GPADC De-Initialization. More...
 
static pn_status_t GPADC_ExtPin_Init (void)
 This API will initialize for the MUX that was enabled to measure the voltage on external ADC pin AD1. More...
 
static void GPADC_ExtPin_DeInit (void)
 De-Initialize the GPADC after disabling measurement for external Analog signal. More...
 
static pn_status_t GPADC_ExtPin_ReadRawData (int16_t *pwValue)
 This API reads the raw data from external pin. More...
 
pn_status_t GPADC_ExtPin_Read (int32_t *milliVolt)
 This API reads the voltage from external pin. More...
 
static bool GPADC_ExtPin_GetEnableStatus (void)
 This API will return the status of whether the MUX is enabled for measuring the external ADC pin. More...
 
pn_status_t GPADC_RegisterCallback (gpadc_sensor_t sensor, gpadc_callback_t callback)
 Regsiter GPADC IRQ callback. More...
 
void GPADC_HandleIRQ (void)
 Function to handle the GPADC IRQ.
 

Macro Definition Documentation

#define FSL_GPADC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))

Typedef Documentation

typedef void(* gpadc_callback_t)(void)

Enumeration Type Documentation

Enumerator
kGPADC_SensorReserved 

Reserved sensor

kGPADC_SensorRSSI 

RX RSSI output sense

kGPADC_SensorBandgap 

Trimmed Bandgap 0.9V

kGPADC_SensorTempPmu 

Temperature sense PMU (in Celcius degrees)

kGPADC_SensorTempClif 

Temperature sense CLIF

kGPADC_SensorXtalPeakDet 

XTAL peak detector

kGPADC_SensorVBAT_ExtPin 

Battery voltage (in mV) or external pin.

kGPADC_SensorGround 

Ground

kGPADC_SensorVDDPA 

VDDPA voltage

Enumerator
kGPADC_TypeVal 

Current value

kGPADC_TypeMin 

Min value

kGPADC_TypeMax 

Max value

kGPADC_TypeIIR 

IIR filtered value

kGPADC_TypeAvg 

Average filtered value

kGPADC_TypeConv 

Select converted values (with conversion to physical scale)

kGPADC_TypeGross 

Select gross values (no conversion to physical scale)

kGPADC_TypeSingleEnd 

Single ended measurement

kGPADC_TypeDifferential 

Differential measurement

kGPADC_TypeConvGrossMask 

Mask for the converted/gross option.

kGPADC_TypeValMask 

Mask for value type, current value/min/max/iir/avg.

kGPADC_TypeMeasureTypeMask 

Mask for measurement type, single end or differential.

kGPADC_TypeValConv 

Converted current value

kGPADC_TypeMinConv 

Converted Min value

kGPADC_TypeMaxConv 

Converted Max value

kGPADC_TypeIIRConv 

Converted IIR filtered value

kGPADC_TypeAvgConv 

Converted average filtered value

kGPADC_TypeValGross 

Gross current value

kGPADC_TypeMinGross 

Gross Min value

kGPADC_TypeMaxGross 

Gross Max value

kGPADC_TypeIIRGross 

Gross IIR filtered value

kGPADC_TypeAvgGross 

Gross average filtered value

kGPADC_TypeValConvDiff 

Differential Converted current value

kGPADC_TypeMinConvDiff 

Differential Converted Min value

kGPADC_TypeMaxConvDiff 

Differential Converted Max value

kGPADC_TypeIIRConvDiff 

Differential Converted IIR filtered value

kGPADC_TypeAvgConvDiff 

Differential Converted average filtered value

kGPADC_TypeValGrossDiff 

Differential Gross current value

kGPADC_TypeMinGrossDiff 

Differential Gross Min value

kGPADC_TypeMaxGrossDiff 

Differential Gross Max value

kGPADC_TypeIIRGrossDiff 

Differential Gross IIR filtered value

kGPADC_TypeAvgGrossDiff 

Differential Gross average filtered value

Function Documentation

static pn_status_t GPADC_Init ( void  )
inlinestatic

This function Initialized the GPADC by mapping the channels and performing calibration.

Returns
Returns kStatus_PN_Success no error occurred, return any other value if an error occurred.
pn_status_t GPADC_ReadSensor ( gpadc_sensor_t  eSensor,
gpadc_value_type_t  eType,
int32_t *  milliVolt 
)

This API reads the requested sensor value based on the value type.

When calling this API, each sensor is fixed mapped to seperate channel, the channels can work simultaneously, the ADC value type can be averaged, minimum, maximum.

Note
If the MUX is enabled for measuring the external pin value (GPADC_ExtPin_GetEnableStatus()), then this function returns the external pin voltage, but not VBAT voltage, when eSensor is kGPADC_SensorVBAT_ExtPin.
Parameters
eSensor,:Sensor used to get General Purpose Analog to Digital Converter (GPADC) value.
eType,:Type of acquisition (either gross value or real scale value).
*milliVolt,:Voltage.
Return values
kStatus_PN_SuccessOn Success.
kStatus_PN_InternalErrorOn wrong sensor acquisition request.
pn_status_t GPADC_ReadSensorOneShot ( gpadc_sensor_t  eSensor,
gpadc_value_type_t  eType,
int32_t *  milliVolt 
)

This API reads the sensor once and returns the value.

When calling this API, there is only one ADC channel used, it is mapped to desired sensor dynamically on request.

Note
If the MUX is enabled for measuring the external pin value (GPADC_ExtPin_GetEnableStatus()), then this function returns the external pin voltage, but not VBAT voltage, when eSensor is kGPADC_SensorVBAT_ExtPin.
Parameters
eSensor,:Sensor used to get General Purpose Analog to Digital Converter (GPADC) value.
eType,:Type of acquisition (either gross value or real scale value).
*milliVolt,:Voltage.
Return values
kStatus_PN_SuccessOn Success.
kStatus_PN_InternalErroron wrong sensor acquisition request.
static pn_status_t GPADC_SetThreshold ( gpadc_sensor_t  eSensor,
gpadc_value_type_t  eType,
int16_t  wLowThreshold,
int16_t  wHighThreshold 
)
inlinestatic

It configures both high and low thresholds.

Parameters
eSensor,:Sensor whose threshold is to be configured, PN76_PCRM_GpadcSensor_t.
eType,:type of threshold (either gross value or real scale value) PN76_PCRM_GpadcValueType_t values
wLowThreshold,:Low threshold below which an interrupt will be triggered
wHighThreshold,:High threshold above which an interrupt will be triggered
Return values
kStatus_PN_SuccessOn Success.
kStatus_PN_InternalErrorif the sensor is not mapped on any of the channels.
kStatus_PN_ParameterErrorIf kGPADC_SensorReserved sensor is requested.
kStatus_PN_ParameterErrorif kGPADC_SensorAny sensor is requested, since kGPADC_SensorAny has no support of real scale threshold
Note
kGPADC_SensorAny Sensor to be used only to get One Shot value with GPADC_ReadSensorOneShot.
static pn_status_t GPADC_GetThreshold ( gpadc_sensor_t  eSensor,
gpadc_value_type_t  eType,
int16_t *  wLowThreshold,
int16_t *  wHighThreshold 
)
inlinestatic

It returns both high and low thresholds.

Parameters
eSensor,:Sensor whose threshold is to be acquired, PN76_PCRM_GpadcSensor_t.
eType,:type of threshold (either gross value or real scale value) PN76_PCRM_GpadcValueType_t values
*wLowThreshold,:Low threshold below which an interrupt will be triggered
*wHighThreshold,:High threshold above which an interrupt will be triggered
Return values
kStatus_PN_SuccessOn Success.
kStatus_PN_InternalErrorif the sensor is not mapped on any of the channels.
kStatus_PN_ParameterErrorif kGPADC_SensorAny sensor selected, since kGPADC_SensorAny has no support of real scale threshold
Note
kGPADC_SensorAny Sensor to be used only to get One Shot value with GPADC_ReadSensorOneShot.
static void GPADC_Deinit ( void  )
inlinestatic

This function disabled the GPADC module.

Note
If this API is called, RF will not work.
static pn_status_t GPADC_ExtPin_Init ( void  )
inlinestatic
Return values
kStatus_PN_Success: Initialization of MUX for measurement on AD1 pin is successfull.
Othervalues Indicates an error occured. Please refer to pn_status_t enum.
static void GPADC_ExtPin_DeInit ( void  )
inlinestatic
Note
If this API is called, RF will not work.
static pn_status_t GPADC_ExtPin_ReadRawData ( int16_t *  pwValue)
inlinestatic
Note
This API must be called only after the GPADC_ExtPin_Init() API.
Only digital equivalent to the external pin value is provided. The caller must convert this to absolute value.
Parameters
*pwValue: Raw Data that is being read from the ADC. Only valid if return value is kStatus_PN_Success.
Return values
kStatus_PN_Success,:GPADC One Shot mode is executed successfully and read data is stored in the parameter.
Othervalues Indicates an error occured. Please refer to pn_status_t enum.
pn_status_t GPADC_ExtPin_Read ( int32_t *  milliVolt)
Note
This API must be called only after the GPADC_ExtPin_Init() API.
Parameters
*milliVolt: Voltage read from the ADC. Only valid if return value is kStatus_PN_Success.
Return values
kStatus_PN_Success,:GPADC One Shot mode is executed successfully and read data is stored in the parameter.
Othervalues Indicates an error occured. Please refer to pn_status_t enum.
static bool GPADC_ExtPin_GetEnableStatus ( void  )
inlinestatic
Return values
trueIndicates that MUX is enabled to measure the voltage on external pin.
falseIndicates that MUX is disabled to measure the voltage on external pin.
pn_status_t GPADC_RegisterCallback ( gpadc_sensor_t  sensor,
gpadc_callback_t  callback 
)
Parameters
sensorWhich sensor to register.
callbackThe callback to register.
Return values
kStatus_PN_SuccessRegister succeed.
kStatus_PN_InternalErrorRegister failed because of internal error.
kStatus_PN_ParameterErrorRegister failed because of wrong parameter.