PAS CO2 Sensor  1.0.3
C++ library for Infineon Photoacoustic Spectroscopy (PAS) XENSIV™ CO2 miniaturized sensor
PASCO2Serial Class Reference

#include <pas-co2-serial.hpp>

Inheritance diagram for PASCO2Serial:
Collaboration diagram for PASCO2Serial:

Public Member Functions

 PASCO2Serial (pasco2::SBus *const sbus, pasco2::Timer *const timer=nullptr, pasco2::GPIO *const interrupt=nullptr, pasco2::GPIO *const protoSelect=nullptr, pasco2::GPIO *const power3V3=nullptr, pasco2::GPIO *const power12V=nullptr)
 PAS CO2 Serial Constructor. More...
 
virtual ~PASCO2Serial ()
 PAS CO2 Serial Destructor. More...
 
Error_t enable ()
 Enables the sensor. More...
 
Error_t disable ()
 Disables the sensor. More...
 
Error_t startMeasure (int16_t periodInSec=0, int16_t alarmTh=0, void(*cback)(void *)=nullptr)
 Triggers the internal measuring of the sensor. More...
 
Error_t stopMeasure ()
 Stops the internal measuring of the sensor. More...
 
Error_t getCO2 (int16_t &CO2PPM)
 Gets the CO2 concentration measured. More...
 
Error_t getDiagnosis (Diag_t &diagnosis)
 Gets diagnosis information. More...
 
Error_t calibrate (ABOC_t aboc, int16_t abocRef, uint16_t pressRef)
 Calibrates the sensor. More...
 
Error_t reset ()
 Resets the sensor. More...
 
Error_t getDeviceID (uint8_t &prodID, uint8_t &revID)
 Gets device product identifier. More...
 

Constructor & Destructor Documentation

◆ PASCO2Serial()

PASCO2Serial::PASCO2Serial ( pasco2::SBus *const  sbus,
pasco2::Timer *const  timer = nullptr,
pasco2::GPIO *const  interrupt = nullptr,
pasco2::GPIO *const  protoSelect = nullptr,
pasco2::GPIO *const  power3V3 = nullptr,
pasco2::GPIO *const  power12V = nullptr 
)

PAS CO2 Serial Constructor.

Mandatory arguments:

  • The SBus needs to be provided
  • A timer instance (currently default as nullptr.TODO: Needs to be changed!)

Optional arguments:

  • All GPIO instances.

Most of the GPIO will be fixed by hardware. In particular those enabling the sensor main power and the emitter power. They are part of the sensor library to provide potential absolute control by software. The hardware interface and its features, are also provided in the library. But it can be as well handled externally

Parameters
[in]*sbusSerial bus instance
[in]*timerTimer instance
[in]*interruptInterrupt GPIO instance. Default is nullptr
[in]*protoSelectProtocol select GPIO instance. Default is nullptr
[in]*power3V3Power 3V3 control GPIO instance. Default is nullptr
[in]*power12VPower 12V control GPIO instance. Default is nullptr
Precondition
None

◆ ~PASCO2Serial()

PASCO2Serial::~PASCO2Serial ( )
virtual

PAS CO2 Serial Destructor.

Precondition
None

Member Function Documentation

◆ enable()

Error_t PASCO2Serial::enable ( )

Enables the sensor.

Initializes the controller peripheral interfaces and enable VDD and IR emitter power of the sensor.

Note
Optional call. Each API function will set internally the required status for its operation
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
IC_POWERON_ERRORif power-on error
Precondition
None
Here is the call graph for this function:

◆ disable()

Error_t PASCO2Serial::disable ( )

Disables the sensor.

Initializes the controller peripheral interfaces and enable VDD and IR emitter power of the sensor

Note
Optional call. Each API function will set internally the required status for its operation
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ startMeasure()

Error_t PASCO2Serial::startMeasure ( int16_t  periodInSec = 0,
int16_t  alarmTh = 0,
void(*)(void *)  cback = nullptr 
)

Triggers the internal measuring of the sensor.

The function start the measurement controlling the different sensor modes and features depending on the configured arguments.

Single shot

If the function is called with no arguments, the sensor will be trigger to perform a single shot measurement. The users needs to poll with getCO2() until the CO2 value is available and has been readed from the sensor. The CO2 concentration value read will be zero as long as no value is avaiable, of -1 if any error occurred in the readout attempt. Polling example:

int16_t co2ppm;
cotwo.startMeasure();
do{ cotwo.getCO2(co2ppm); } while (co2ppm <= 0);

Periodic measurement

Periodic measurements (periodInSec) will configure the sensor to perform a measurements every desired period. Between 5 and 4095 seconds. Without further arguments, the user has to poll with getCO2() until the value is available. Any super loop or thread routine, can just consist on reading the CO2 (getCO2()). For example, measure every 5 minutes:

int16_t co2ppm;
cotwo.startMeasure(300);
while(1)
{
delay(300);
do{ cotwo.getCO2(co2ppm); } while (co2ppm <= 0);
// ... do something with the co2 value ...
}

Synching readouts with the hardware interrupt

In order not to saturate the sensor with constant serial requests, especially in periodic mode, it is recommended to synch the readout with a timer. Or even better using the hardware GPIO hardware interrupt. If the interrupt GPIO interface has been provided, passing a callback function will enable the interrupt mode. The type of interrupt is decided depending on the value of the rest of the arguments and operations modes. Some example:

volatile bool intFlag = false;
void cback(void *)
{
intFlag = true;
}
int16_t co2ppm;
cotwo.startMeasure(300,0,cback);
while(1)
{
while(!intFlag) { // block or yield() };
cotwo.getCO2(co2ppm);
// ... do something with the co2 value ...
intFlag = false;
}

Alarm mode

If the alarm threshold argument is non-zero, the alarm mode is activated, and an the sensor internal flag will be eanbled if the concentration of CO2 goes above the specified value. This option is better combined with the interupt mode. Thus, if the interrupt mode is available and a callback function is passed, the interrupt will occurr only when the co2 concentration goes above the threshold. This makes mostly sense for periodic measurement configuration. But it can be used as well for a single shot configuration

Parameters
[in]periodInSecEnables periodic measurement with the specified period. The default, value is 0, meaning single shot operation. The valid period range goes between 5 and 4095 seconds
[in]alarmThEnables upper alarm threshold mode for the specified value. The default value is 0, meaning no alarm mode. For any non-zero value, the sensor will internally set the alarm flag. If an interrupt callback function is provided, then the interrupt will occurr only when the defined threshold has been tresspassed
[in]*cbackPointer to the callback function to be called upon interrupt
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
CONFIG_ERRORif invalid configuration parameter
Precondition
None
Here is the call graph for this function:

◆ stopMeasure()

Error_t PASCO2Serial::stopMeasure ( )

Stops the internal measuring of the sensor.

Sets operation mode to idle

Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ getCO2()

Error_t PASCO2Serial::getCO2 ( int16_t &  co2ppm)

Gets the CO2 concentration measured.

The value read is zero when no measurement is yet available. In case of error, the read value is set to -1. Before reading the co2 value, the measurement status register is read to know if a new measurement data is available.

Parameters
[out]co2ppmCO2 concentration read (in ppm)
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ getDiagnosis()

Error_t PASCO2Serial::getDiagnosis ( Diag_t diagnosis)

Gets diagnosis information.

The sensor status registers includes the following flags:

  • Sensor ready
  • PWM pin enabled
  • Temperature out of range error
  • IR emitter voltage out of range error
  • Communication error which will be stored in the Diag_t struct varible passed by argument. After reading the flags, these are cleared in the device writing in the corresponding clear flag bitfields.
Parameters
[out]diagnosisStruct to store the diagnosis flags values
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

◆ calibrate()

Error_t PASCO2Serial::calibrate ( ABOC_t  aboc,
int16_t  abocRef,
uint16_t  pressRef 
)

Calibrates the sensor.

Configures the automatic baseline and the reference pressure compensation

Parameters
[in]abocAutomatic baseline compenstation mode
[in]abocRefAutomatic baseline compensation reference
[in]pressRefPressure reference value. Min value is 600, and max 1600.
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
CONFIG_ERRORif pressure reference value is invalid
Precondition
None
Here is the call graph for this function:

◆ reset()

Error_t PASCO2Serial::reset ( )

Resets the sensor.

The software reset performs the following operations:

  • Read the current sensor memory register map configuration
  • Send the corresponding software reset serial command
  • Rewrite the previous memory map configuration after reset
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
RESET_ERRORif the device reset error
Precondition
None
Here is the call graph for this function:

◆ getDeviceID()

Error_t PASCO2Serial::getDeviceID ( uint8_t &  prodID,
uint8_t &  revID 
)

Gets device product identifier.

Parameters
[out]prodIDProduct identifier
[out]revIDVersion identifier
Returns
PAS CO2 error code
Return values
OKif success
INTF_ERRORif interface error
Precondition
None
Here is the call graph for this function:

The documentation for this class was generated from the following files: