no-OS
Loading...
Searching...
No Matches
cn0391.h File Reference

Header file of CN0391 board support. More...

#include "ad7124.h"
#include "no_os_thermocouple.h"
#include "no_os_rtd.h"
Include dependency graph for cn0391.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cn0391_adc_ch_map
 
struct  cn0391_cache
 
struct  cn0391_dev
 
struct  cn0391_init_param
 

Macros

#define CN0391_ADC_RESOLUTION   24 /* AD7124 is a high precision 24-bit Sigma-Delta ADC */
 
#define CN0391_ADC_FULL_SCALE   (1U << CN0391_ADC_RESOLUTION) /* 2^24 */
 
#define CN0391_ADC_MIDSCALE   (CN0391_ADC_FULL_SCALE >> 1) /* 2^23, bipolar zero-code */
 
#define CN0391_GAIN   32
 
#define CN0391_RTD_GAIN   1
 
#define CN0391_THERMO_RES   1600
 
#define CN0391_ADC_REF_VOLTAGE   2.5
 
#define CN0391_SETUP_TC_IDX   0 /* Thermocouple: Gain=32, bipolar, internal ref */
 
#define CN0391_SETUP_RTD_IDX   1 /* R5 + CJC RTD: Gain=1, bipolar, internal ref */
 
#define CN0391_ADC_CLK_HZ   614400ULL
 
#define CN0391_FILTER_FS   384U
 
#define CN0391_FILTER_TYPE   0 /* Sinc4 */
 
#define CN0391_FILTER_ORDER   4U /* Sinc4: 4-period settling */
 
#define CN0391_FILTER_REG_VAL    (AD7124_FILT_REG_FILTER(CN0391_FILTER_TYPE) | AD7124_FILT_REG_FS(CN0391_FILTER_FS))
 
#define CN0391_CONV_TIME_US
 
#define CN0391_SPI_RDY_POLL_CNT(spi_hz)
 
#define CN0391_ADC_CHANNELS_PER_IIO_CH   3
 
#define CN0391_NUM_IIO_CHANNELS   4
 
#define CN0391_CH0_ID   0
 
#define CN0391_CH1_ID   1
 
#define CN0391_CH2_ID   2
 
#define CN0391_CH3_ID   3
 

Functions

int cn0391_init (struct cn0391_dev **dev, struct cn0391_init_param *init_param)
 Initialize CN0391 device: set up AD7124 and configure IOUT.
 
int cn0391_remove (struct cn0391_dev *dev)
 Remove CN0391 device and free resources.
 
int cn0391_read_temperature (struct cn0391_dev *dev, uint8_t ch_idx, double *hot_junction_temp, double *cold_junction_temp, double *thermocouple_voltage, double *rtd_resistance)
 Perform a full temperature measurement cycle. Reads all 3 ADC channels (thermocouple, reference resistor, CJC RTD), computes cold junction temperature, cold junction compensation voltage, and hot junction temperature.
 

Detailed Description

Header file of CN0391 board support.

Author
Mircea Vlasin (mirce.nosp@m.a.vl.nosp@m.asin@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2026(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ CN0391_ADC_CHANNELS_PER_IIO_CH

#define CN0391_ADC_CHANNELS_PER_IIO_CH   3

◆ CN0391_ADC_CLK_HZ

#define CN0391_ADC_CLK_HZ   614400ULL

◆ CN0391_ADC_FULL_SCALE

#define CN0391_ADC_FULL_SCALE   (1U << CN0391_ADC_RESOLUTION) /* 2^24 */

◆ CN0391_ADC_MIDSCALE

#define CN0391_ADC_MIDSCALE   (CN0391_ADC_FULL_SCALE >> 1) /* 2^23, bipolar zero-code */

◆ CN0391_ADC_REF_VOLTAGE

#define CN0391_ADC_REF_VOLTAGE   2.5

◆ CN0391_ADC_RESOLUTION

#define CN0391_ADC_RESOLUTION   24 /* AD7124 is a high precision 24-bit Sigma-Delta ADC */

◆ CN0391_CH0_ID

#define CN0391_CH0_ID   0

◆ CN0391_CH1_ID

#define CN0391_CH1_ID   1

◆ CN0391_CH2_ID

#define CN0391_CH2_ID   2

◆ CN0391_CH3_ID

#define CN0391_CH3_ID   3

◆ CN0391_CONV_TIME_US

#define CN0391_CONV_TIME_US
Value:
(((CN0391_FILTER_ORDER + 1U) * CN0391_FILTER_FS * 32ULL * 1000000ULL) \
#define CN0391_FILTER_ORDER
Definition cn0391.h:79
#define CN0391_ADC_CLK_HZ
Definition cn0391.h:55
#define CN0391_FILTER_FS
Definition cn0391.h:57

◆ CN0391_FILTER_FS

#define CN0391_FILTER_FS   384U

◆ CN0391_FILTER_ORDER

#define CN0391_FILTER_ORDER   4U /* Sinc4: 4-period settling */

◆ CN0391_FILTER_REG_VAL

◆ CN0391_FILTER_TYPE

#define CN0391_FILTER_TYPE   0 /* Sinc4 */

◆ CN0391_GAIN

#define CN0391_GAIN   32

◆ CN0391_NUM_IIO_CHANNELS

#define CN0391_NUM_IIO_CHANNELS   4

◆ CN0391_RTD_GAIN

#define CN0391_RTD_GAIN   1

◆ CN0391_SETUP_RTD_IDX

#define CN0391_SETUP_RTD_IDX   1 /* R5 + CJC RTD: Gain=1, bipolar, internal ref */

◆ CN0391_SETUP_TC_IDX

#define CN0391_SETUP_TC_IDX   0 /* Thermocouple: Gain=32, bipolar, internal ref */

◆ CN0391_SPI_RDY_POLL_CNT

#define CN0391_SPI_RDY_POLL_CNT ( spi_hz)
Value:
((CN0391_CONV_TIME_US * 2ULL * (spi_hz)) / (16ULL * 1000000ULL))
#define CN0391_CONV_TIME_US
Definition cn0391.h:99

◆ CN0391_THERMO_RES

#define CN0391_THERMO_RES   1600

Function Documentation

◆ cn0391_init()

int cn0391_init ( struct cn0391_dev ** dev,
struct cn0391_init_param * init_param )

Initialize CN0391 device: set up AD7124 and configure IOUT.

Parameters
dev- Pointer to pointer to CN0391 device descriptor.
init_param- Initialization parameters.
Returns
0 on success, negative error code otherwise.
Here is the caller graph for this function:

◆ cn0391_read_temperature()

int cn0391_read_temperature ( struct cn0391_dev * dev,
uint8_t ch_idx,
double * hot_junction_temp,
double * cold_junction_temp,
double * thermocouple_voltage,
double * rtd_resistance )

Perform a full temperature measurement cycle. Reads all 3 ADC channels (thermocouple, reference resistor, CJC RTD), computes cold junction temperature, cold junction compensation voltage, and hot junction temperature.

Parameters
dev- CN0391 device descriptor.
ch_idx- IIO channel index (CN0391_CH0_ID..CN0391_CH3_ID).
hot_junction_temp- Pointer to store hot junction temperature (°C).
cold_junction_temp- Pointer to store cold junction temperature (°C).
thermocouple_voltage- Pointer to store thermocouple voltage (mV).
rtd_resistance- Pointer to store measured RTD resistance (Ohms).
Returns
0 on success, negative error code otherwise.
Here is the caller graph for this function:

◆ cn0391_remove()

int cn0391_remove ( struct cn0391_dev * dev)

Remove CN0391 device and free resources.

Parameters
dev- CN0391 device descriptor.
Returns
0 on success, negative error code otherwise.
Here is the caller graph for this function: