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
25using namespace sense_board_pins;
26
28
29float 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
34void 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
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
67
68 // Start ADC now that configuration is done
69 ads126x.startADC1();
70}
71
72void loop() {
73 // Wait for DRDY pin
74 while (digitalRead(Pins.ADC_DRDY_1) != LOW) {
76 }
77
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}
static SerialStub Serial
Definition Arduino.h:128
#define INPUT
Definition Arduino.h:21
int digitalRead(int)
Definition Arduino.h:50
void pinMode(int, int)
Definition Arduino.h:46
#define SPI_MODE1
Definition Arduino.h:131
#define LOW
Definition Arduino.h:20
void delayMicroseconds(unsigned int)
Definition Arduino.h:58
#define ADS126X_AINCOM
#define ADS126X_RATE_1200
#define ADS126X_SINC4
static ADS126X ads126x
Definition main.cpp:20
#define TEST_PIN
Definition main.cpp:23
void setup()
Definition main.cpp:34
float convert_code_to_voltage(int32_t code)
Definition main.cpp:29
#define TEST_CONNECTOR
Definition main.cpp:18
void loop()
Definition main.cpp:72
constexpr int getAdcChannel(uint8_t connector, uint8_t pin)
constexpr const Layout & Pins