Skyward boardcore
Loading...
Searching...
No Matches
ADS131M04Defs.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 ADS131M04Defs
31{
32
33static constexpr int CHANNELS_NUM = 4;
34static constexpr int CALIBRATION_SAMPLES = 250;
35static constexpr int SELF_TEST_SAMPLES = 250;
36static constexpr int FULL_FRAME_SIZE = 18;
37static constexpr uint16_t RESET_CMD_RESPONSE = 0xFF24;
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};
90
91enum class Input : uint8_t
92{
93 DEFAULT = 0, // AINxP and AINxN (default)
94 SHORTED = 1, // ADC inputs shorted
95 POSITIVE_DC_TEST = 2, // Positive DC test signal
96 NEGATIVE_DC_TEST = 3 // Negative DC test signal
97};
98
99enum class Register : uint16_t
100{
101 // Device settings and indicators
102 REG_ID = 0,
103 REG_STATUS = 0x1,
104
105 // Global settings across channels
106 REG_MODE = 0x2,
107 REG_CLOCK = 0x3,
108 REG_GAIN = 0x4,
109 REG_CFG = 0x6,
110 REG_THRSHLD_MSB = 0x7,
111 REG_THRSHLD_LSB = 0x8,
112
113 // Channel specific settings
114 REG_CH0_CFG = 0x9,
115 REG_CH0_OCAL_MSB = 0xA,
116 REG_CH0_OCAL_LSB = 0xB,
117 REG_CH0_GCAL_MSB = 0xC,
118 REG_CH0_GCAL_LSB = 0xD,
119 REG_CH1_CFG = 0xE,
120 REG_CH1_OCAL_MSB = 0xF,
121 REG_CH1_OCAL_LSB = 0x10,
122 REG_CH1_GCAL_MSB = 0x11,
123 REG_CH1_GCAL_LSB = 0x12,
124 REG_CH2_CFG = 0x13,
125 REG_CH2_OCAL_MSB = 0x14,
126 REG_CH2_OCAL_LSB = 0x15,
127 REG_CH2_GCAL_MSB = 0x16,
128 REG_CH2_GCAL_LSB = 0x17,
129 REG_CH3_CFG = 0x18,
130 REG_CH3_OCAL_MSB = 0x19,
131 REG_CH3_OCAL_LSB = 0x1A,
132 REG_CH3_GCAL_MSB = 0x1B,
133 REG_CH3_GCAL_LSB = 0x1C,
134
135 // Register map CRC
136 REG_REGMAP_CRC = 0x3E
137};
138
139enum class Command : uint16_t
140{
141 NULL_CMD = 0x0000,
142 RESET = 0x0011,
143 STANDBY = 0x0022,
144 WAKEUP = 0x0033,
145 LOCK = 0x0555,
146 UNLOCK = 0x0655,
147 RREG = 0xA000,
148 WREG = 0x6000
149};
150
151namespace RegStatusMasks
152{
153constexpr uint16_t LOCK = 0x1 << 15;
154constexpr uint16_t F_RESYNC = 0x1 << 14;
155constexpr uint16_t REG_MAP = 0x1 << 13;
156constexpr uint16_t CRC_ERR = 0x1 << 12;
157constexpr uint16_t CRC_TYPE = 0x1 << 11;
158constexpr uint16_t RESET = 0x1 << 10;
159constexpr uint16_t WLENGTH = 0x3 << 8;
160constexpr uint16_t DRDY3 = 0x1 << 3;
161constexpr uint16_t DRDY2 = 0x1 << 2;
162constexpr uint16_t DRDY1 = 0x1 << 1;
163constexpr uint16_t DRDY0 = 0x1 << 0;
164} // namespace RegStatusMasks
165
166namespace RegModeMasks
167{
168constexpr uint16_t REG_CRC_EN = 0x1 << 13;
169constexpr uint16_t RX_CRC_EN = 0x1 << 12;
170constexpr uint16_t CRC_TYPE = 0x1 << 11;
171constexpr uint16_t RESET = 0x1 << 10;
172constexpr uint16_t WLENGTH = 0x3 << 8;
173constexpr uint16_t TIMEOUT = 0x1 << 4;
174constexpr uint16_t DRDY_SEL = 0x3 << 2;
175constexpr uint16_t DRDY_HiZ = 0x1 << 1;
176constexpr uint16_t DRDY_FMT = 0x1 << 0;
177} // namespace RegModeMasks
178
179namespace RegClockMasks
180{
181constexpr uint16_t CH3_EN = 0x1 << 11;
182constexpr uint16_t CH2_EN = 0x1 << 10;
183constexpr uint16_t CH1_EN = 0x1 << 9;
184constexpr uint16_t CH0_EN = 0x1 << 8;
185constexpr uint16_t OSR = 0x7 << 2;
186constexpr uint16_t POWER_MODE = 0x3 << 0;
187} // namespace RegClockMasks
188
189namespace RegGainMasks
190{
191constexpr uint16_t PGA_GAIN_3 = 0x7 << 12;
192constexpr uint16_t PGA_GAIN_2 = 0x7 << 8;
193constexpr uint16_t PGA_GAIN_1 = 0x7 << 4;
194constexpr uint16_t PGA_GAIN_0 = 0x7 << 0;
195} // namespace RegGainMasks
196
197namespace RegConfigurationMasks
198{
199constexpr uint16_t GC_DLY = 0xF << 9;
200constexpr uint16_t GC_EN = 0x1 << 8;
201constexpr uint16_t CD_ALLCH = 0x1 << 7;
202constexpr uint16_t CD_NUM = 0x7 << 4;
203constexpr uint16_t CD_LEN = 0x7 << 1;
204constexpr uint16_t CD_EN = 0x1 << 0;
205} // namespace RegConfigurationMasks
206
207namespace RegChannelMasks
208{
209constexpr uint16_t CFG_PHASE = 0x3FF << 6;
210constexpr uint16_t CFG_DCBLK_DIS = 0x001 << 2;
211constexpr uint16_t CFG_MUX = 0x003 << 0;
212} // namespace RegChannelMasks
213
214} // namespace ADS131M04Defs
215
216} // namespace Boardcore
constexpr float PGA_LSB_SIZE[8]
OversamplingRatio
ADC's oversampling ratio configurations.
@ 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.