Analog Devices / mbed-drivers
Embed: (wiki syntax)

« Back to documentation index

CN0216 Class Reference

CN0216 Class Reference

EVAL-CN0216 weigh scale measurement shield. More...

#include <CN0216.h>

Public Types

enum  CalibrationStep_t { ZERO_SCALE_CALIBRATION, FULL_SCALE_CALIBRATION, COMPUTE_UNITS_PER_BIT }

Public Member Functions

 CN0216 (PinName CSAD7791=D8, PinName MOSI=SPI_MOSI, PinName MISO=SPI_MISO, PinName SCK=SPI_SCK)
 CN0216 constructor.
void init (float cal_weight=_DEFAULT_CAL_WEIGHT, uint8_t mode_val=_DEFAULT_MODE_VAL, uint8_t filter_val=_DEFAULT_FILTER_VAL)
 Initializes the mode and filter values of the AD7791 and sets the weight to be used in calibration.
void calibrate (CalibrationStep_t cal)
 Calibrates the CN0216 weigh scale.
float compute_weight (uint32_t data)
 Computes the weight based on the formula weight = (data - zeroscale) * weight_units_per_bit.
uint32_t read_u32 ()
 Reads the AD7791.
float read_weight ()
 Reads the ADC and computes the weight based on the formula described above.

Detailed Description

EVAL-CN0216 weigh scale measurement shield.

Definition at line 57 of file CN0216.h.


Member Enumeration Documentation

Enumerator:
ZERO_SCALE_CALIBRATION 

Calibration of the zero scale value.

FULL_SCALE_CALIBRATION 

Calibration of the full scale value.

COMPUTE_UNITS_PER_BIT 

Units per LSB computation.

Definition at line 60 of file CN0216.h.


Constructor & Destructor Documentation

CN0216 ( PinName  CSAD7791 = D8,
PinName  MOSI = SPI_MOSI,
PinName  MISO = SPI_MISO,
PinName  SCK = SPI_SCK 
)

CN0216 constructor.

Parameters:
CSAD7791- Chipselect of the AD7791
MOSI- MOSI line of the SPI bus
MISO- MISO line of the SPI bus
SCK- SCK line of the SPI bus

Definition at line 60 of file CN0216.cpp.


Member Function Documentation

void calibrate ( CalibrationStep_t  cal )

Calibrates the CN0216 weigh scale.

Parameters:
cal- calibration step. Step CN0216::ZERO_SCALE_CALIBRATION will take CN0216::_NUMBER_OF_SAMPLES samples and use the minimum as value for the zero scale Step CN0216::FULL_SCALE_CALIBRATION will take CN0216::_NUMBER_OF_SAMPLES samples and use the average as value for the full scale Step COMPUTE_UNITS_PER_BIT will compute the grams per bit used in weight computation.

Definition at line 94 of file CN0216.cpp.

float compute_weight ( uint32_t  data )

Computes the weight based on the formula weight = (data - zeroscale) * weight_units_per_bit.

Parameters:
dataread from the ADC
Returns:
weight based on data

Definition at line 134 of file CN0216.cpp.

void init ( float  cal_weight = _DEFAULT_CAL_WEIGHT,
uint8_t  mode_val = _DEFAULT_MODE_VAL,
uint8_t  filter_val = _DEFAULT_FILTER_VAL 
)

Initializes the mode and filter values of the AD7791 and sets the weight to be used in calibration.

Parameters:
cal_weight- weight used in calibration
mode_val- value of the mode register
filter_val- value of the filter register

Definition at line 74 of file CN0216.cpp.

uint32_t read_u32 ( void   )

Reads the AD7791.

Returns:
value read by the ADC

Definition at line 147 of file CN0216.cpp.

float read_weight ( void   )

Reads the ADC and computes the weight based on the formula described above.

Returns:
weight

Definition at line 156 of file CN0216.cpp.