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::LC_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
// Change the following line to set which connector you are testing
16
// Note that that script currently only does single ended testing, referenced to
17
// AINCOM!
18
#define TEST_CONNECTOR 3
19
20
// Change the following line to set which pin on the connector you are testing
21
// For PT/TC, set this to 1. For LC/RTD it can 1 or 2.
22
// Note that for LC, we consider the "positive" pin to be 1 and vice versa
23
#define TEST_PIN 1
24
25
using namespace
sense_board_pins
;
26
27
static
ADS126X
ads126x
;
28
29
float
convert_code_to_voltage
(int32_t code) {
30
// Assumes the 2.5V internal reference is being used!
31
return
((
float
)code * 2.5f) / 2147483648.0f;
32
}
33
34
void
setup
() {
35
Serial
.begin(115200);
36
37
// Setup SPI
38
SPI.begin(
Pins
.ADC_SCLK,
Pins
.ADC_MISO,
Pins
.ADC_MOSI,
Pins
.ADC_CS_1);
39
40
// You can set the freq if you want, or just use the default
41
// SPI.setFrequency(1'000'000);
42
43
// Due to the ADC output having valid data on FALLING CLK edges
44
SPI.setDataMode(
SPI_MODE1
);
45
pinMode
(
Pins
.ADC_DRDY_1,
INPUT
);
46
47
// Setup ADC
48
ads126x
.begin(
Pins
.ADC_CS_1);
49
50
ads126x
.enablePGA();
51
ads126x
.setGain(
ADS126X_GAIN_8
);
52
53
// Stop it while we config it, as suggested by datasheet
54
ads126x
.stopADC1();
55
56
// Set the input to ADC1 to be the whatever pin you want
57
ads126x
.setInputMux(
getAdcChannel
(7, 1),
getAdcChannel
(7, 2));
58
59
// Set the filter. You can change this to try different filters
60
ads126x
.setFilter(
ADS126X_SINC4
);
61
62
// Set the datarate. You can change this, but the options depends on the
63
// filter I do not know what happens if you program an invalid data rate for
64
// a given filter
65
ads126x
.setRate(
ADS126X_RATE_1200
);
66
67
// Start ADC now that configuration is done
68
ads126x
.startADC1();
69
}
70
71
void
loop
() {
72
// Wait for DRDY pin
73
while
(
digitalRead
(
Pins
.ADC_DRDY_1) !=
LOW
) {
74
delayMicroseconds
(10);
75
}
76
77
delayMicroseconds
(25);
78
79
// Get the most recent value
80
const
auto
reading =
ads126x
.readADC1();
81
Serial
.print(F(
"Current reading: "
));
82
Serial
.print(
convert_code_to_voltage
(reading.value), 6);
83
Serial
.println(
" V"
);
84
85
// Checks for invalid checksums, which signal corruption
86
if
(!reading.checksumValid) {
87
Serial
.println(
"Bad checksum!"
);
88
}
89
}
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
SPI.h
ADS126X_GAIN_8
#define ADS126X_GAIN_8
Definition
STAR_ADS126X_definitions.h:121
ADS126X_RATE_1200
#define ADS126X_RATE_1200
Definition
STAR_ADS126X_definitions.h:133
ADS126X_SINC4
#define ADS126X_SINC4
Definition
STAR_ADS126X_definitions.h:100
ADS126X
Definition
STAR_ADS126X.h:25
connector_adc_map.h
ads126x
static ADS126X ads126x
Definition
main.cpp:20
setup
void setup()
Definition
main.cpp:34
convert_code_to_voltage
float convert_code_to_voltage(int32_t code)
Definition
main.cpp:29
loop
void loop()
Definition
main.cpp:71
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
LC_Board
LC_Simple_Test
src
main.cpp
Generated by
1.15.0