LTC2498 Module - smartel99/NilaiTFO GitHub Wiki

Refer to the datasheet for more informations.

  • Location: shared/interfaces/LTC2498Module.*
  • Brief: Interface layer for the LTC2498 Analog-to-Digital Converter used to read the 4 strain-guage sensors, feedback of the 5VSEN power rail, feedback of the 3.3V power rail and the temperature measured by a thermocouple.

Uses:

Types

LTC2498::Channels

Enum listing all possible channels Members:

  • CH0
  • CH1
  • CH2
  • CH3
  • CH4
  • CH5
  • CH6
  • CH7
  • CH8
  • CH9
  • CH10
  • CH11
  • CH12
  • CH13
  • CH14
  • CH15

LTC2498::AcquisitionType

Enum listing the possible types of acquisition. Members:

  • Differential
  • SingleEnded

LTC2498::Polarity 

Enum listing the possible polarities. Members:

  • Positive
  • Negative

LTC2498::InputType

Enum listing the possible types of input. Members:

  • External
  • TempSensor

LTC2498::Filters

Enum listing the possible filter configuration options. Members:

  • None
  • Hz50
  • Hz60
  • All

LTC2498::Speed

Enum listing the possible acquisition speeds. Members:

  • x1
  • x2

LTC2498::ConversionSettings

Structure used to configure a conversion. Members:

LTC2498::Reading

Structure containing the value read on a channel. Members:

  • LTC2498::ConversionSettings config: Settings used for this conversion
  • float reading: Value read by the conversion, in volts

Operation

Initialisation

No special operations are required to initialize the ADC. On power up, the configuration is:

  • Input: CH0-CH1 (differential mode)
  • Frequency rejection to simultaneous 50Hz/60Hz
  • 1x output rate
  • Auto-calibration enabled This cannot be changed for it is how the chip is built. However, pin PA0 (LTC2498_CS) of the STM32 must be set to a low output state (0), and pin PA6 (SDI) of the STM32 must be configured as an extrenal interrupt (EXTI6) which triggers on a falling edge.

POST

Procedure for the Power-On Self-Test. To pass the POST, all of the following operations must succeed:

  • We are able to communicate with the ADC
  • All 4 sensors read a value that is non-null
  • The 5VSen channel reads a value of 5V +/- 10%
  • The Temperature channel reads a value that is non-null
  • The 3.3V feedback channel reads a value of 3.3V +/- 10%

Run Loop

The values of each channels is constantly refreshed through interrupts using the following principle:

  • When a falling edge is detected on SDI, do:
    1. Configure PA6 as serial data input for the SPI peripheral using HAL_GPIO_Init
    2. Prepare the data to be sent to ADC for the next conversion it should do (See Conversion Configurations)
    3. Exchange the data with the ADC. The next conversion is automatically started at the end of the transaction
    4. Verify that the EOC bit is set to 0
    5. Check for under/over range
    6. Convert the received data into volts (See Data Conversion)
    7. Reconfigure PA6 as an external interrupt that triggers on a falling edge

Public Functions

LTC2498Module::LTC2498Module(const std::string& label, SpiModule* spi, const Pin& inPin, const Pin& csPin)

Constructor of the module.

Parameters:

  • const std::string& label: Label to be used for the module
  • SpiModule* spi: Pointer to an already existing SpiModule
  • const Pin& inPin: Pin that will be configured as an external interrupt input and as the serial data input pin
  • const Pin& csPin: Chip select Pin

Return: The created instance.

bool LTC2498Module::QueueConversions(const std::vector<LTC2498::ConversionSettings>& conversions, bool repeat = false)

Queues a list of conversions to be done sequentially.

If repeat is set to false, the list of conversions will be cleared once they are all completed, otherwise they are looped until the next call to QueueConversions.

Parameters:

  • const std::vector<LTC2498::ConversionSettings>& conversions: A list of all the conversion to do. Can be empty if no conversions are desired
  • bool repeat: Flag that, if set, indicates to the module that the list of conversions should be executed in loops. Defaults to false

Returns: true if the list of conversions was successfully queued, false otherwise.

const LTC2498::Reading& LTC2498Module::GetLastReading()

Gets the last reading that was accomplished by the ADC.

Parameters: None

Returns: The last successful reading.

bool LTC2498Module::IsConversionInProgress()

Check if a conversion is currently ongoing or if the ADC is in standby mode.

Parameters: None

Returns: true if a conversion is in progress, false otherwise.

bool LTC2498Module::StartConversion(const LTC2498::ConversionSettings& config)

Starts a single conversion with the provided settings.

Parameters:

  • const LTC2498::ConversionSettings& config: The conversion's configuration

Returns: true if the conversion was successfully started, false otherwise.

Misc

Conversion Configurations

List of the configuration data for each channels of the ADC:

byte 0.7 byte 0.6 byte 0.5 byte 0.4 byte 0.3 byte 0.2 byte 0.1 byte 0.0 byte 1.7 byte 1.6 byte 1.5 byte 1.4 byte 1.3
PRE_EN1 PRE_EN2 EN SGL ODD A2 A1 A0 EN2 IM FA FB SPD

Bit Description:

  • PRE_EN1: Pre-enable bit 1. If set to 0, the rest of the data is ignored by the ADC.
  • PRE_EN2: Pre-enable bit 2. Must be set to 0
  • EN: Channel configuration enable bit. If set to 1, the ADC will use the values of SGL, ODD, A2, A1 and A0 to select the input channel for the next conversion cycle.
  • SLG: Determines if the input selection is differential (SGL = 0) or single-ended (SGL = 1).
  • ODD: Determines the polarity of a differential input, only useful when SGL is set to 0. For example, with SGL = 0, A2 = 0, A1 = 0 and A0 = 0, if ODD is set to 0, channel 0 will be the positive input and channel 1 the negative input. With ODD set to 1, channel 0 will be the negative input and channel 1 will be the positive input.
  • Ax: Channel selection bits
  • EN2: Enable bit for the conversion configuration. If set to 0, the next conversion is performed using the previosuly selected converter configuration. If set to one, a new configuration will be loaded using the values of IM, FA, FB and SPD.
  • IM: If set to 1, the next conversion will be performed on the internal temperature sensor instead of the select input channel.
  • FA: Toggles the 50Hz rejection filter. Set to 0 to enable the filter.
  • FB: Toggles the 60Hz rejection filter. Set to 0 to enable the filter.
  • SPD: Selects the output rate. Set to 0 for 1x output rate (with auto-calibration and offset removed), or set to 1 for 2x output rate with auto-calibration disabled.
Channel Byte 0 Byte 1 Byte 2 Byte 3
Sensor 1 0xA0 0x80 0x00 0x00
Sensor 2 0xA1 0x80 0x00 0x00
Sensor 3 0xA2 0x80 0x00 0x00
Sensor 4 0xA3 0x80 0x00 0x00
5V Sensor 0xB4 0x80 0x00 0x00
Temperature 0xB5 0x80 0x00 0x00
3.3V 0xB6 0x80 0x00 0x00

Data Format

The ADC's output data packet is always made out of 4 bytes (32 bits), assembled as such:

  • Bit 31: End of conversion indicator. If it has a value of 1, a conversion is currently in process
  • Bit 30: dummy bit, always 0
  • Bit 29: Conversion result sign indicator. If the selected input (Vin = INp - INn) is greater than 0, this bit is set to 1. Otherwise, it is set to 0
  • Bit 28: Most significant bit of the result. Also used to provide underrange and overrange indication (see Status Bits)
  • Bits 28 to 5: Conversion result, MSB first
  • Bit 5: Least significant bit
  • Bit 4 to 0: Sub-LSBs, should be discarded

Data Conversion

  1. Extract the 24 bits of data from the 32 bits packet
  2. Convert into volts using the formula $V = V_{hex} \times \frac{5}{2^{24}}$
  3. Apply the sign depending on the state of bit 29

Status Bits

Input Range Bit 31 EOC Bit 30 DMY Bit 29 SIG Bit 28 MSB
$V_{IN} \geq 0.5 \times V_{REF}$ 0 0 1 1
$0V \leq V_{IN} < 0.5 \times V_{REF}$ 0 0 1/0 0
$-0.5 \times V_{REF} \leq V_{IN} < 0V$ 0 0 0 1
$V_{IN} < -0.5 \times V_{REF}$ 0 0 0 0