STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
#include <
Arduino.h
>
2
#include <
SPI.h
>
3
4
#include "STAR_ADS126X.h"
5
6
// Change the following line to automatically use the correct pins for the board
7
// being tested (PT_Board, LC_Board, RTD_Board, or TC_Board)
8
#define PINS_ACTIVE_LAYOUT sense_board_pins::RTD_Board
9
10
// These lines MUST be after the #define PINS_ACTIVE_LAYOUT or they will
11
// overwrite it with the default value!
12
#include "
connector_adc_map.h
"
13
#include "
sense_board_pins.h
"
14
15
using namespace
sense_board_pins
;
16
17
static
ADS126X
ads126x
;
18
19
float
convert_code_to_voltage
(int32_t code) {
20
// Assumes the 2.5V internal reference is being used!
21
return
((
float
)code * 2.5f) / 2147483648.0f;
22
}
23
24
void
setup
() {
25
Serial
.begin(115200);
26
while
(!
Serial
) {
27
delay
(10);
28
}
29
30
delay
(1000);
31
32
// Setup SPI
33
SPI.begin(
Pins
.ADC_SCLK,
Pins
.ADC_MISO,
Pins
.ADC_MOSI,
Pins
.ADC_CS_1);
34
35
// You can set the freq if you want, or just use the default
36
// SPI.setFrequency(1'000'000);
37
38
// Due to the ADC output having valid data on FALLING CLK edges
39
SPI.setDataMode(
SPI_MODE1
);
40
pinMode
(
Pins
.ADC_DRDY_1,
INPUT
);
41
42
// Setup ADC
43
ads126x
.begin(
Pins
.ADC_CS_1);
44
45
// Stop it while we config it, as suggested by datasheet
46
ads126x
.stopADC1();
47
48
// Set the input to ADC1 to be the whatever pin you want
49
ads126x
.setInputMux(
getAdcChannel
(2, 1),
getAdcChannel
(2, 2));
50
51
// Bypas the PGA, so it does not affect measurements
52
ads126x
.bypassPGA();
53
54
// Set the filter. You can change this to try different filters
55
ads126x
.setFilter(
ADS126X_SINC4
);
56
57
// Set the datarate. You can change this, but the options depends on the
58
// filter I do not know what happens if you program an invalid data rate for
59
// a given filter
60
ads126x
.setRate(
ADS126X_RATE_1200
);
61
62
ads126x
.setBiasMagnitude(
ADS126X_BIAS_MAG_10M
);
63
64
// Start ADC now that configuration is done
65
ads126x
.startADC1();
66
}
67
68
void
loop
() {
69
// Wait for DRDY pin
70
while
(
digitalRead
(
Pins
.ADC_DRDY_1) !=
LOW
) {
71
delayMicroseconds
(10);
72
}
73
74
delayMicroseconds
(25);
75
76
// Get the most recent value
77
const
auto
reading =
ads126x
.readADC1();
78
Serial
.print(F(
"Current reading: "
));
79
Serial
.print(
convert_code_to_voltage
(reading.value), 6);
80
Serial
.println(
" V"
);
81
82
// Checks for invalid checksums, which signal corruption
83
if
(!reading.checksumValid) {
84
Serial
.println(
"Bad checksum!"
);
85
}
86
}
Arduino.h
Serial
static SerialStub Serial
Definition
Arduino.h:128
INPUT
#define INPUT
Definition
Arduino.h:21
digitalRead
int digitalRead(int)
Definition
Arduino.h:50
pinMode
void pinMode(int, int)
Definition
Arduino.h:46
SPI_MODE1
#define SPI_MODE1
Definition
Arduino.h:131
LOW
#define LOW
Definition
Arduino.h:20
delayMicroseconds
void delayMicroseconds(unsigned int)
Definition
Arduino.h:58
ADS126X_BIAS_MAG_10M
#define ADS126X_BIAS_MAG_10M
Definition
STAR_ADS126X.h:13
SPI.h
ADS126X_RATE_1200
#define ADS126X_RATE_1200
Definition
STAR_ADS126X_definitions.h:133
ADS126X_SINC4
#define ADS126X_SINC4
Definition
STAR_ADS126X_definitions.h:100
delay
void delay(int ms)
Definition
actuator_nc.cpp:30
ADS126X
Definition
STAR_ADS126X.h:25
connector_adc_map.h
ads126x
static ADS126X ads126x
Definition
main.cpp:20
setup
void setup()
Definition
main.cpp:24
convert_code_to_voltage
float convert_code_to_voltage(int32_t code)
Definition
main.cpp:19
loop
void loop()
Definition
main.cpp:68
sense_board_pins
Definition
connector_adc_map.h:35
sense_board_pins::getAdcChannel
constexpr int getAdcChannel(uint8_t connector, uint8_t pin)
Definition
connector_adc_map.h:122
sense_board_pins::Pins
constexpr const Layout & Pins
Definition
sense_board_pins.h:161
sense_board_pins.h
firmware
ADC_Testing
Sensor_Bias_Testing
src
main.cpp
Generated by
1.15.0