Skyward boardcore
Loading...
Searching...
No Matches
ADS131M04.h
Go to the documentation of this file.
1/* Copyright (c) 2023 Skyward Experimental Rocketry
2 * Author: Alberto Nidasio
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
27#include <sensors/Sensor.h>
28
29#include "ADS131M04Data.h"
30#include "ADS131M04Defs.h"
31
32namespace Boardcore
33{
34
75class ADS131M04 : public Sensor<ADS131M04Data>
76{
77public:
94
95 ADS131M04(SPIBusInterface& bus, miosix::GpioPin cs, SPIBusConfig spiConfig,
96 const Config& config);
97
98 bool init() override;
99
100 bool reset();
101
111 void applyConfig(Config config);
112
118
125 bool selfTest() override;
126
127protected:
128 ADS131M04Data sampleImpl() override;
129
130private:
140 void applyChannelConfig(ADS131M04Defs::Channel channel,
141 Config::ChannelConfig config);
142
153 void setOversamplingRatio(ADS131M04Defs::OversamplingRatio ratio);
154
161 void setChannelPGA(ADS131M04Defs::Channel channel, ADS131M04Defs::PGA gain);
162
168 void setChannelOffset(ADS131M04Defs::Channel channel, uint32_t offset);
169
176 void setChannelGain(ADS131M04Defs::Channel channel, double gain);
177
178 void enableChannel(ADS131M04Defs::Channel channel);
179
180 void disableChannel(ADS131M04Defs::Channel channel);
181
196 void enableGlobalChopMode();
197
203 void disableGlobalChopMode();
204
205 void setChannelInput(ADS131M04Defs::Channel channel,
207
208 ADS131M04Defs::Register getChannelConfigRegister(
209 ADS131M04Defs::Channel channel);
210
211 ADS131M04Defs::Register getChannelOffsetRegisterMSB(
212 ADS131M04Defs::Channel channel);
213
214 ADS131M04Defs::Register getChannelOffsetRegisterLSB(
215 ADS131M04Defs::Channel channel);
216
217 ADS131M04Defs::Register getChannelGainRegisterMSB(
218 ADS131M04Defs::Channel channel);
219
220 ADS131M04Defs::Register getChannelGainRegisterLSB(
221 ADS131M04Defs::Channel channel);
222
229 bool readSamples(int32_t rawValues[ADS131M04Defs::CHANNELS_NUM]);
230
231 uint16_t readRegister(ADS131M04Defs::Register reg);
232
233 void writeRegister(ADS131M04Defs::Register reg, uint16_t data);
234
235 void changeRegister(ADS131M04Defs::Register reg, uint16_t newValue,
236 uint16_t mask);
237
238 void sendCommand(SPITransaction& transaction, ADS131M04Defs::Command cmd,
239 uint8_t data[ADS131M04Defs::FULL_FRAME_SIZE]);
240
245 float getLSBSizeFromGain(ADS131M04Defs::PGA gain);
246
247 SPISlave spiSlave;
248
249 // Current device configuration
250 Config config;
251
252 PrintLogger logger = Logging::getLogger("ads131m04");
253};
254
255} // namespace Boardcore
Driver for ADS131M04 4 simultaneous channels adc.
Definition ADS131M04.h:76
bool init() override
Initialize the sensor.
Definition ADS131M04.cpp:43
ADS131M04Data sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
bool selfTest() override
The self test samples internally connects each channel to known test signals and verifies if the samp...
void calibrateOffset(ADS131M04Defs::Channel channel)
Samples each channel, averages the samples and applies offset compensation in the device.
Definition ADS131M04.cpp:92
ADS131M04(SPIBusInterface &bus, miosix::GpioPin cs, SPIBusConfig spiConfig, const Config &config)
Definition ADS131M04.cpp:35
void applyConfig(Config config)
Overwrites the sensor settings.
Definition ADS131M04.cpp:77
static PrintLogger getLogger(const string &name)
Interface for low level access of a SPI bus as a master.
Provides high-level access to the SPI Bus for a single transaction.
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
OversamplingRatio
ADC's oversampling ratio configurations.
@ PGA_1
Full scale resolution is ±1.2V.
This file includes all the types the logdecoder script will decode.
ChannelConfig channelsConfig[ADS131M04Defs::CHANNELS_NUM]
Definition ADS131M04.h:88
ADS131M04Defs::OversamplingRatio oversamplingRatio
Definition ADS131M04.h:90
SPI Bus configuration for a specific slave.
Contains information about a single SPI slave device.