Skyward boardcore
Loading...
Searching...
No Matches
ADS131M08Defs.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
25#include <stdint.h>
26
27namespace Boardcore
28{
29
30namespace ADS131M08Defs
31{
32
33static constexpr int CHANNELS_NUM = 8;
34static constexpr int CALIBRATION_SAMPLES = 250;
35static constexpr int SELF_TEST_SAMPLES = 250;
36static constexpr int FULL_FRAME_SIZE = 30;
37static constexpr uint16_t RESET_CMD_RESPONSE = 0xFF28;
38static constexpr uint16_t WRITE_CMD_RESPONSE = 0x4000;
39
41constexpr float PGA_LSB_SIZE[8] = {143.0511e-9, 71.5256e-9, 35.7628e-9,
42 17.8814e-9, 8.9407e-9, 4.4703e-9,
43 2.2352e-9, 1.1176e-9};
44
45static constexpr float V_REF = 1.2;
46static constexpr float TEST_SIGNAL_FACTOR = 2.0 / 15.0;
47static constexpr float TEST_SIGNAL_SLACK = 0.1; // Not defined in DS
48
59enum class OversamplingRatio : uint16_t
60{
61 OSR_128 = 0, // ODR is 32KHz
62 OSR_256 = 0x1 << 2, // ODR is 16KHz
63 OSR_512 = 0x2 << 2, // ODR is 8KHz
64 OSR_1024 = 0x3 << 2, // ODR is 4KHz
65 OSR_2048 = 0x4 << 2, // ODR is 2KHz
66 OSR_4096 = 0x5 << 2, // ODR is 1KHz
67 OSR_8192 = 0x6 << 2, // ODR is 500Hz
68 OSR_16256 = 0x7 << 2 // ODR is 250Hz
69};
70
71enum class PGA : uint16_t
72{
73 PGA_1 = 0,
74 PGA_2 = 0x1,
75 PGA_4 = 0x2,
76 PGA_8 = 0x3,
77 PGA_16 = 0x4,
78 PGA_32 = 0x5,
79 PGA_64 = 0x6,
80 PGA_128 = 0x7
81};
82
83enum class Channel : uint8_t
84{
85 CHANNEL_0 = 0,
86 CHANNEL_1 = 1,
87 CHANNEL_2 = 2,
88 CHANNEL_3 = 3,
89 CHANNEL_4 = 4,
90 CHANNEL_5 = 5,
91 CHANNEL_6 = 6,
92 CHANNEL_7 = 7
93};
94
95enum class Input : uint8_t
96{
97 DEFAULT = 0, // AINxP and AINxN (default)
98 SHORTED = 1, // ADC inputs shorted
99 POSITIVE_DC_TEST = 2, // Positive DC test signal
100 NEGATIVE_DC_TEST = 3 // Negative DC test signal
101};
102
103enum class Register : uint16_t
104{
105 // Device settings and indicators
106 REG_ID = 0,
107 REG_STATUS = 0x1,
108
109 // Global settings across channels
110 REG_MODE = 0x2,
111 REG_CLOCK = 0x3,
112 REG_GAIN_1 = 0x4,
113 REG_GAIN_2 = 0x5,
114 REG_CFG = 0x6,
115 REG_THRSHLD_MSB = 0x7,
116 REG_THRSHLD_LSB = 0x8,
117
118 // Channel specific settings
119 REG_CH0_CFG = 0x9,
120 REG_CH0_OCAL_MSB = 0xA,
121 REG_CH0_OCAL_LSB = 0xB,
122 REG_CH0_GCAL_MSB = 0xC,
123 REG_CH0_GCAL_LSB = 0xD,
124 REG_CH1_CFG = 0xE,
125 REG_CH1_OCAL_MSB = 0xF,
126 REG_CH1_OCAL_LSB = 0x10,
127 REG_CH1_GCAL_MSB = 0x11,
128 REG_CH1_GCAL_LSB = 0x12,
129 REG_CH2_CFG = 0x13,
130 REG_CH2_OCAL_MSB = 0x14,
131 REG_CH2_OCAL_LSB = 0x15,
132 REG_CH2_GCAL_MSB = 0x16,
133 REG_CH2_GCAL_LSB = 0x17,
134 REG_CH3_CFG = 0x18,
135 REG_CH3_OCAL_MSB = 0x19,
136 REG_CH3_OCAL_LSB = 0x1A,
137 REG_CH3_GCAL_MSB = 0x1B,
138 REG_CH3_GCAL_LSB = 0x1C,
139 REG_CH4_CFG = 0x1D,
140 REG_CH4_OCAL_MSB = 0x1E,
141 REG_CH4_OCAL_LSB = 0x1F,
142 REG_CH4_GCAL_MSB = 0x20,
143 REG_CH4_GCAL_LSB = 0x21,
144 REG_CH5_CFG = 0x22,
145 REG_CH5_OCAL_MSB = 0x23,
146 REG_CH5_OCAL_LSB = 0x24,
147 REG_CH5_GCAL_MSB = 0x25,
148 REG_CH5_GCAL_LSB = 0x26,
149 REG_CH6_CFG = 0x27,
150 REG_CH6_OCAL_MSB = 0x28,
151 REG_CH6_OCAL_LSB = 0x29,
152 REG_CH6_GCAL_MSB = 0x2A,
153 REG_CH6_GCAL_LSB = 0x2B,
154 REG_CH7_CFG = 0x2C,
155 REG_CH7_OCAL_MSB = 0x2D,
156 REG_CH7_OCAL_LSB = 0x2E,
157 REG_CH7_GCAL_MSB = 0x2F,
158 REG_CH7_GCAL_LSB = 0x30,
159
160 // Register map CRC
161 REG_REGMAP_CRC = 0x3E
162};
163
164enum class Command : uint16_t
165{
166 NULL_CMD = 0x0000,
167 RESET = 0x0011,
168 STANDBY = 0x0022,
169 WAKEUP = 0x0033,
170 LOCK = 0x0555,
171 UNLOCK = 0x0655,
172 RREG = 0xA000,
173 WREG = 0x6000
174};
175
176namespace RegStatusMasks
177{
178constexpr uint16_t LOCK = 0x1 << 15;
179constexpr uint16_t F_RESYNC = 0x1 << 14;
180constexpr uint16_t REG_MAP = 0x1 << 13;
181constexpr uint16_t CRC_ERR = 0x1 << 12;
182constexpr uint16_t CRC_TYPE = 0x1 << 11;
183constexpr uint16_t RESET = 0x1 << 10;
184constexpr uint16_t WLENGTH = 0x3 << 8;
185constexpr uint16_t DRDY3 = 0x1 << 3;
186constexpr uint16_t DRDY2 = 0x1 << 2;
187constexpr uint16_t DRDY1 = 0x1 << 1;
188constexpr uint16_t DRDY0 = 0x1 << 0;
189} // namespace RegStatusMasks
190
191namespace RegModeMasks
192{
193constexpr uint16_t REG_CRC_EN = 0x1 << 13;
194constexpr uint16_t RX_CRC_EN = 0x1 << 12;
195constexpr uint16_t CRC_TYPE = 0x1 << 11;
196constexpr uint16_t RESET = 0x1 << 10;
197constexpr uint16_t WLENGTH = 0x3 << 8;
198constexpr uint16_t TIMEOUT = 0x1 << 4;
199constexpr uint16_t DRDY_SEL = 0x3 << 2;
200constexpr uint16_t DRDY_HiZ = 0x1 << 1;
201constexpr uint16_t DRDY_FMT = 0x1 << 0;
202} // namespace RegModeMasks
203
204namespace RegClockMasks
205{
206constexpr uint16_t CH3_EN = 0x1 << 11;
207constexpr uint16_t CH2_EN = 0x1 << 10;
208constexpr uint16_t CH1_EN = 0x1 << 9;
209constexpr uint16_t CH0_EN = 0x1 << 8;
210constexpr uint16_t OSR = 0x7 << 2;
211constexpr uint16_t POWER_MODE = 0x3 << 0;
212} // namespace RegClockMasks
213
214namespace RegGainMasks
215{
216constexpr uint16_t PGA_GAIN_3 = 0x7 << 12;
217constexpr uint16_t PGA_GAIN_2 = 0x7 << 8;
218constexpr uint16_t PGA_GAIN_1 = 0x7 << 4;
219constexpr uint16_t PGA_GAIN_0 = 0x7 << 0;
220} // namespace RegGainMasks
221
222namespace RegConfigurationMasks
223{
224constexpr uint16_t GC_DLY = 0xF << 9;
225constexpr uint16_t GC_EN = 0x1 << 8;
226constexpr uint16_t CD_ALLCH = 0x1 << 7;
227constexpr uint16_t CD_NUM = 0x7 << 4;
228constexpr uint16_t CD_LEN = 0x7 << 1;
229constexpr uint16_t CD_EN = 0x1 << 0;
230} // namespace RegConfigurationMasks
231
232namespace RegChannelMasks
233{
234constexpr uint16_t CFG_PHASE = 0x3FF << 6;
235constexpr uint16_t CFG_DCBLK_DIS = 0x001 << 2;
236constexpr uint16_t CFG_MUX = 0x003 << 0;
237} // namespace RegChannelMasks
238
239} // namespace ADS131M08Defs
240
241} // namespace Boardcore
OversamplingRatio
ADC's oversampling ratio configurations.
constexpr float PGA_LSB_SIZE[8]
@ PGA_2
Full scale resolution is ±600mV.
@ PGA_4
Full scale resolution is ±300mV.
@ PGA_16
Full scale resolution is ±75mV.
@ PGA_64
Full scale resolution is ±18.75mV.
@ PGA_1
Full scale resolution is ±1.2V.
@ PGA_128
Full scale resolution is ±9.375mV.
@ PGA_8
Full scale resolution is ±150mV.
@ PGA_32
Full scale resolution is ±37.5mV.
This file includes all the types the logdecoder script will decode.