PSoC-FDC1004Q
PSoC FDC1004Q Library
Functions
FDC1004Q.h File Reference

Header file for the FDC1004Q driver. More...

#include "FDC1004Q_Defs.h"
#include "project.h"

Go to the source code of this file.

Functions

uint8_t FDC_Start (void)
 Start the FDC1004Q. More...
 
void FDC_Stop (void)
 Stop communication with the FDC1004Q.
 
uint8_t FDC_Reset (void)
 Perform a software reset of the sensor. More...
 
uint8_t FDC_IsDeviceConnected (void)
 Check if device is connected on the I2C bus. More...
 
uint8_t FDC_SetSampleRate (uint8_t sampleRate)
 Set up sample rate for continuous measurements. More...
 
uint8_t FDC_ReadSampleRate (uint8_t *sampleRate)
 Read current sample rate. More...
 
uint8_t FDC_ReadOffsetCalibration (uint8_t channel, float *offset)
 Read channel offset calibration register as float value. More...
 
uint8_t FDC_ReadRawOffsetCalibration (uint8_t channel, int16_t *offset)
 Read channel offset calibration register as Q5.11 format. More...
 
uint8_t FDC_SetOffsetCalibration (uint8_t channel, float offset)
 Set channel offset calibration register in float format. More...
 
uint8_t FDC_SetRawOffsetCalibration (uint8_t channel, int16_t offset)
 Set channel offset calibration register in raw format. More...
 
uint8_t FDC_ReadGainCalibration (uint8_t channel, float *gain)
 Read gain calibration register in float format. More...
 
uint8_t FDC_ReadRawGainCalibration (uint8_t channel, uint16_t *gain)
 Read gain calibration register in fixed point Q2.14 formta. More...
 
uint8_t FDC_SetGainCalibration (uint8_t channel, float gain)
 Set gain calibration register. More...
 
uint8_t FDC_SetRawGainCalibration (uint8_t channel, uint16_t gain)
 Set gain calibration register in Q2.14 format. More...
 
uint8_t FDC_InitMeasurement (uint8_t channel)
 Init measurement for given channel. More...
 
uint8_t FDC_StopMeasurement (uint8_t channel)
 Stop measurement for given channel. More...
 
uint8_t FDC_IsMeasurementDone (uint8_t channel, uint8_t *done)
 Check if measurement for a given channel is complete. More...
 
uint8_t FDC_EnableRepeatMeasurement (uint8_t channel_flags)
 Enable repeated measurement. More...
 
uint8_t FDC_DisableRepeatMeasurement (void)
 Disable repated measurement. More...
 
uint8_t FDC_ConfigureMeasurementInput (uint8_t meas_channel, uint8_t pos_channel, uint8_t neg_channel, uint8_t capdac)
 Configure measurement input settings. More...
 
uint8_t FDC_ConfigureMeasurement (uint8_t meas_channel, uint8_t pos_channel, uint8_t neg_channel, uint8_t capdac, int16_t offset, uint16_t gain)
 Configure measurement settings. More...
 
uint8_t FDC_ReadRawCapdacSetting (uint8_t channel, uint8_t *capdac)
 Read current capdac setting. More...
 
uint8_t FDC_ReadCapdacSetting (uint8_t channel, float *capdac)
 Read current capdac setting in float format. More...
 
uint8_t FDC_ReadPositiveChannelSetting (uint8_t channel, uint8_t *input)
 Read current positive input channel setting. More...
 
uint8_t FDC_ReadNegativeChannelSetting (uint8_t channel, uint8_t *input)
 Read current negative input channel setting. More...
 
uint8_t FDC_ReadRawMeasurement (uint8_t channel, uint32_t *capacitance)
 Read capacitance measurement in raw format. More...
 
uint8_t FDC_ReadMeasurement (uint8_t channel, double *capacitance)
 Read capacitance measurement in double format. More...
 
double FDC_ConvertRawMeasurement (uint32_t capacitance)
 Convert raw capacitance measurement in double format. More...
 
uint8_t FDC_HasNewData (uint8_t *done)
 Check if new measurement data are available to be read. More...
 
uint8_t FDC_ReadManufacturerId (uint16_t *id)
 Read the manufacturer ID from the sensor. More...
 
uint8_t FDC_ReadDeviceId (uint16_t *id)
 Read the device ID from the sensor. More...
 
uint8_t FDC_ReadRegister (uint8_t reg_addr, uint8_t *data)
 Read a register from the FDC1004Q. More...
 
uint8_t FDC_WriteRegister (uint8_t reg_addr, uint8_t *data)
 Write a register to the FDC1004Q. More...
 

Detailed Description

Header file for the FDC1004Q driver.

This file contains function declarations and type definitions for the FDC1004Q driver.

Author
Davide Marzorati
Date
June 30, 2020

Definition in file FDC1004Q.h.

Function Documentation

uint8_t FDC_ConfigureMeasurement ( uint8_t  meas_channel,
uint8_t  pos_channel,
uint8_t  neg_channel,
uint8_t  capdac,
int16_t  offset,
uint16_t  gain 
)

Configure measurement settings.

This function allows to configure the settings for a given channel of the measurement.

Parameters
meas_channelthe measurement channel to be configured.
pos_channelthe positive input channel to capacitance digital converter.
neg_channelthe negative input channel to capacitance digital converter.
capdacvalue of CAPDAC, that is the capacitance offset (this value is multiplied by 3.125 pF).
offsetvalue of capacitance offset.
gainvalue of capacitance gain.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif error in the settings.

Definition at line 400 of file FDC1004Q.c.

uint8_t FDC_ConfigureMeasurementInput ( uint8_t  meas_channel,
uint8_t  pos_channel,
uint8_t  neg_channel,
uint8_t  capdac 
)

Configure measurement input settings.

This function allows to configure the input settings for a given channel of the measurement.

Parameters
meas_channelthe measurement channel to be configured.
pos_channelthe positive input channel to capacitance digital converter.
neg_channelthe negative input channel to capacitance digital converter.
capdacvalue of CAPDAC, that is the capacitance offset (this value is multiplied by 3.125 pF).
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif error in the settings.

Definition at line 364 of file FDC1004Q.c.

double FDC_ConvertRawMeasurement ( uint32_t  capacitance)

Convert raw capacitance measurement in double format.

This function converts a raw measurement in dobule format. CAPDAC value is not added to the measurement, so it is necessary to add it after the conversion is completed.

Parameters
capacitancethe raw capacitance value
Returns
capacitance value converted in double format

Definition at line 470 of file FDC1004Q.c.

uint8_t FDC_DisableRepeatMeasurement ( void  )

Disable repated measurement.

This function disables repeated measurements.

Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication

Definition at line 349 of file FDC1004Q.c.

uint8_t FDC_EnableRepeatMeasurement ( uint8_t  channel_flags)

Enable repeated measurement.

This function enables repeated measurements for a single channel or for the set of channels.

Parameters
channel_flagsthe channels for which to enable repeated measurements. It is possible to OR together the following values:
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication

Definition at line 321 of file FDC1004Q.c.

uint8_t FDC_HasNewData ( uint8_t *  done)

Check if new measurement data are available to be read.

This function checks whether new data are available in the measurement registers to be read.

Return values
FDC_OKif no error occurred
FDC_COMM_ERRif communication error occurred.

Definition at line 547 of file FDC1004Q.c.

uint8_t FDC_InitMeasurement ( uint8_t  channel)

Init measurement for given channel.

This function inits the capacitance measurement for a given channel.

Parameters
channelthe channel for which the measurement must be started. Possible values are:
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication
FDC_CONF_ERRif channel value not correct

Definition at line 272 of file FDC1004Q.c.

uint8_t FDC_IsDeviceConnected ( void  )

Check if device is connected on the I2C bus.

This function sends a write request on the I2C bus to check it it is acknowledged by the sensor. If the sensor acknowledges it, then it means that it is connected.

Return values
FDC_OKif device was found on I2C bus.
FDC_DEV_NOT_FOUNDif device was not found on I2C bus.

Definition at line 73 of file FDC1004Q.c.

uint8_t FDC_IsMeasurementDone ( uint8_t  channel,
uint8_t *  done 
)

Check if measurement for a given channel is complete.

This function check if the capacitance measurement for a given channel is complete.

Parameters
[in]channelthe channel for which the measurement must be started.
[out]donepointer to variable where the result of the check will be stored.
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication
FDC_CONF_ERRif channel value not correct

Definition at line 307 of file FDC1004Q.c.

uint8_t FDC_ReadCapdacSetting ( uint8_t  channel,
float *  capdac 
)

Read current capdac setting in float format.

This function reads the current value of capdac set in the register. The value returned is in float format.

Parameters
[in]channelthe channel for which the capdac setting must be retrieved. Possible values are:
[out]capdacpointer to variable where the capdac value will be stored.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.

Definition at line 497 of file FDC1004Q.c.

uint8_t FDC_ReadDeviceId ( uint16_t *  id)

Read the device ID from the sensor.

This function reads the device ID from the sensor, so that the device can be distinguished from other sensors on the same I2C bus.

Parameters
idthe manufacturer id read from the sensor
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication

Definition at line 580 of file FDC1004Q.c.

uint8_t FDC_ReadGainCalibration ( uint8_t  channel,
float *  gain 
)

Read gain calibration register in float format.

This function reads the current gain calibration value in the register for the channel passed in as parameter to the function. A detailed description of the gain calibration register can be found at FDC1004Q_GAIN_CAL_CIN1.

Parameters
[in]channelthe channel from which to read the calibration gain. Possible values are:
[out]gainpointer to variable where the gain will be stored.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif channel value not correct.

Definition at line 240 of file FDC1004Q.c.

uint8_t FDC_ReadManufacturerId ( uint16_t *  id)

Read the manufacturer ID from the sensor.

This function reads the manufacturer ID from the sensor, so that the device can be distinguished from other sensors on the same I2C bus.

Parameters
idthe manufacturer id read from the sensor
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication

Definition at line 566 of file FDC1004Q.c.

uint8_t FDC_ReadMeasurement ( uint8_t  channel,
double *  capacitance 
)

Read capacitance measurement in double format.

This function reads the content of the measurement registers, converting it and adding the offset specified by the capdac setting.

Parameters
[in]channelthe channel for which the measurement must be read. Possible values are:
[out]capacitancepointer to variable where the result will be stored.
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication

Definition at line 439 of file FDC1004Q.c.

uint8_t FDC_ReadNegativeChannelSetting ( uint8_t  channel,
uint8_t *  input 
)

Read current negative input channel setting.

This function reads the current value configured as negative input channel for the measurement channel of interest.

Parameters
[in]channelthe channel for which the setting must be retrieved. Possible values are:
[out]inputpointer to variable where the negative input channel value will be stored.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.

Definition at line 530 of file FDC1004Q.c.

uint8_t FDC_ReadOffsetCalibration ( uint8_t  channel,
float *  offset 
)

Read channel offset calibration register as float value.

This function reads the current offset calibration set in the register for the channel passed in as parameter to the function. A detailed description of the offset calibration register can be found at FDC1004Q_OFFSET_CAL_CIN1. This function converts the stored value in float format.

Parameters
[in]channelthe channel from which to read the calibration offset. Possible values are:
[out]offsetpointer to variable where the value of the offset will be stored
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication
FDC_CONF_ERRif wrong value for channel.

Definition at line 184 of file FDC1004Q.c.

uint8_t FDC_ReadPositiveChannelSetting ( uint8_t  channel,
uint8_t *  input 
)

Read current positive input channel setting.

This function reads the current value configured as positive input channel for the measurement channel of interest.

Parameters
[in]channelthe channel for which the setting must be retrieved. Possible values are:
[out]inputpointer to variable where the positive input channel value will be stored.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.

Definition at line 513 of file FDC1004Q.c.

uint8_t FDC_ReadRawCapdacSetting ( uint8_t  channel,
uint8_t *  capdac 
)

Read current capdac setting.

This function reads the current value of capdac set in the configuration register. The value returned is in raw format, without multiplication by a factor of 3.125.

Parameters
[in]channelthe channel for which the capdac setting must be retrieved. Possible values are:
[out]capdacpointer to variable where the capdvac value will be stored.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.

Definition at line 481 of file FDC1004Q.c.

uint8_t FDC_ReadRawGainCalibration ( uint8_t  channel,
uint16_t *  gain 
)

Read gain calibration register in fixed point Q2.14 formta.

This function reads the current gain calibration value in the register for the channel passed in as parameter to the function and return the value in raw format. A detailed description of the gain calibration register can be found at FDC1004Q_GAIN_CAL_CIN1.

Parameters
[in]channelthe channel from which to read the calibration gain. Possible values are:
[out]gainpointer to variable where the gain will be stored.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif channel value not correct.

Definition at line 254 of file FDC1004Q.c.

uint8_t FDC_ReadRawMeasurement ( uint8_t  channel,
uint32_t *  capacitance 
)

Read capacitance measurement in raw format.

This function reads the content of the measurement registers, without doing any conversion of the result or adding the capacitance offset to the read value.

Parameters
[in]channelthe channel for which the measurement must be read. Possible values are:
[out]capacitancepointer to variable where the result will be stored.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif channel value not correct.

Definition at line 420 of file FDC1004Q.c.

uint8_t FDC_ReadRawOffsetCalibration ( uint8_t  channel,
int16_t *  offset 
)

Read channel offset calibration register as Q5.11 format.

This function reads the current offset calibration set in the register for the channel passed in as parameter to the function. A detailed description of the offset calibration register can be found at FDC1004Q_OFFSET_CAL_CIN1.

Parameters
[in]channelthe channel from which to read the calibration offset Possible values are:
[out]offsetpointer to variable where the value of the offset will be stored in Q5.11 format
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication
FDC_CONF_ERRif wrong value for channel.

Definition at line 202 of file FDC1004Q.c.

uint8_t FDC_ReadRegister ( uint8_t  reg_addr,
uint8_t *  data 
)

Read a register from the FDC1004Q.

This function reads the content of a 16-bit register and return its value.

Parameters
[in]reg_addrthe address of the register to be read.
[out]data16-bit to be written.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.

Definition at line 597 of file FDC1004Q.c.

uint8_t FDC_ReadSampleRate ( uint8_t *  sampleRate)

Read current sample rate.

This function reads the current sample rate configured for the FDC1004Q to be used in case continuous measurements is set up.

Parameters
[out]sampleRatepointer to variable storing sample rate
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication

Definition at line 144 of file FDC1004Q.c.

uint8_t FDC_Reset ( void  )

Perform a software reset of the sensor.

This function performs a software reset of the sensor by setting the RST bit in the FDC1004Q_FDC_CONF to 1.

Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_DEV_NOT_FOUNDif device was not found on I2C bus.

Definition at line 95 of file FDC1004Q.c.

uint8_t FDC_SetGainCalibration ( uint8_t  channel,
float  gain 
)

Set gain calibration register.

This function sets the gain calibration value in the register for the channel passed in as parameter to the function with the value in float format. A detailed description of the gain calibration register can be found at FDC1004Q_GAIN_CAL_CIN1.

Parameters
channelthe channel from which to read the calibration gain. Possible values are:
gainvalue to be set as gain in float format.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif channel value not correct or gain value too high.

Definition at line 216 of file FDC1004Q.c.

uint8_t FDC_SetOffsetCalibration ( uint8_t  channel,
float  offset 
)

Set channel offset calibration register in float format.

This function sets the offset calibration in the register for the channel passed in as parameter to the function. A detailed description of the offset calibration register can be found at FDC1004Q_OFFSET_CAL_CIN1.

Parameters
channelthe channel for which to set the calibration offset. Possible values are:
offsetvalue to be set as capacitance offset.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif offset value is not between limits or channel not correct.

Definition at line 156 of file FDC1004Q.c.

uint8_t FDC_SetRawGainCalibration ( uint8_t  channel,
uint16_t  gain 
)

Set gain calibration register in Q2.14 format.

This function sets the gain calibration value in the register for the channel passed in as parameter to the function with the value in raw format. A detailed description of the gain calibration register can be found at FDC1004Q_GAIN_CAL_CIN1.

Parameters
channelthe channel for which to set the calibration gain. Possible values are:
gainvalue to be set as gain in Q2.14 format.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif channel value not correct or gain value too high.

Definition at line 228 of file FDC1004Q.c.

uint8_t FDC_SetRawOffsetCalibration ( uint8_t  channel,
int16_t  offset 
)

Set channel offset calibration register in raw format.

This function sets the offset calibration in the register for the channel passed in as parameter to the function. A detailed description of the offset calibration register can be found at FDC1004Q_OFFSET_CAL_CIN1.

Parameters
channelthe channel for which to set the calibration offset. Possible values are:
offsetvalue to be set as capacitance offset.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif offset value is not between limits or channel not correct.

Definition at line 172 of file FDC1004Q.c.

uint8_t FDC_SetSampleRate ( uint8_t  sampleRate)

Set up sample rate for continuous measurements.

This function sets up the sample rate of the FDC1004Q to be used in case continuous measurements is set up.

Parameters
[in]sampleRatethe desired sample rate. Possible values:
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.
FDC_CONF_ERRif sample rate value is not among possible values.

Definition at line 125 of file FDC1004Q.c.

uint8_t FDC_Start ( void  )

Start the FDC1004Q.

This function starts the underlying I2C peripheral that needs to be used for communication purposes. It also checks if the device is present on the I2C bus.

Return values
FDC_OKinitialization successful and device present on bus.
FDC_DEV_NOT_FOUNDdevice not present on the bus.

Definition at line 58 of file FDC1004Q.c.

uint8_t FDC_StopMeasurement ( uint8_t  channel)

Stop measurement for given channel.

This function stops the capacitance measurement for a given channel.

Parameters
channelthe channel for which the measurement must be stopped.
Return values
FDC_OKif everything ok
FDC_COMM_ERRif error occurred during communication
FDC_CONF_ERRif channel value not correct

Definition at line 290 of file FDC1004Q.c.

uint8_t FDC_WriteRegister ( uint8_t  reg_addr,
uint8_t *  data 
)

Write a register to the FDC1004Q.

This function writes a 16-bit register.

Parameters
[in]reg_addrthe address of the register to be written.
[in]datathe data to be written to the register.
Return values
FDC_OKif everything ok.
FDC_COMM_ERRif error occurred during communication.

Definition at line 611 of file FDC1004Q.c.