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::PT_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
// Stop it while we config it, as suggested by datasheet
51
ads126x
.stopADC1();
52
53
// Set the input to ADC1 to be the whatever pin you want
54
ads126x
.setInputMux(
getAdcChannel
(
TEST_CONNECTOR
,
TEST_PIN
),
55
ADS126X_AINCOM
);
56
57
// Bypas the PGA, so it does not affect measurements
58
ads126x
.bypassPGA();
59
60
// Set the filter. You can change this to try different filters
61
ads126x
.setFilter(
ADS126X_SINC4
);
62
63
// Set the datarate. You can change this, but the options depends on the
64
// filter I do not know what happens if you program an invalid data rate for
65
// a given filter
66
ads126x
.setRate(
ADS126X_RATE_1200
);
67
68
// Start ADC now that configuration is done
69
ads126x
.startADC1();
70
}
71
72
void
loop
() {
73
// Wait for DRDY pin
74
while
(
digitalRead
(
Pins
.ADC_DRDY_1) !=
LOW
) {
75
delayMicroseconds
(10);
76
}
77
78
delayMicroseconds
(25);
79
80
// Get the most recent value
81
const
auto
reading =
ads126x
.readADC1();
82
Serial
.print(F(
"Current reading: "
));
83
Serial
.print(
convert_code_to_voltage
(reading.value), 6);
84
Serial
.println(
" V"
);
85
86
// Checks for invalid checksums, which signal corruption
87
if
(!reading.checksumValid) {
88
Serial
.println(
"Bad checksum!"
);
89
}
90
}
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_AINCOM
#define ADS126X_AINCOM
Definition
STAR_ADS126X_definitions.h:152
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
TEST_PIN
#define TEST_PIN
Definition
main.cpp:23
setup
void setup()
Definition
main.cpp:34
convert_code_to_voltage
float convert_code_to_voltage(int32_t code)
Definition
main.cpp:29
TEST_CONNECTOR
#define TEST_CONNECTOR
Definition
main.cpp:18
loop
void loop()
Definition
main.cpp:72
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
Simple_Test
src
main.cpp
Generated by
1.15.0