STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
sense.cpp
Go to the documentation of this file.
1
#ifdef RUN_SENSE_TEST
2
#include <ADS126X.h>
3
#include <
Arduino.h
>
4
#include <
SPI.h
>
5
6
#define DRDY_PIN 22
7
#define DOUT 21
// MISO
8
#define DIN 19
// MOSI
9
#define SCLK 20
10
#define CS 17
11
12
#define DRDY_PIN 22
// brown 15
13
// #define AINCOM 3
14
// #define AVSS 5
15
#define DOUT 21
// purple 14
16
#define DIN 19
// yellow 7
17
#define SCLK 20
// green 13
18
#define CS 17
// blue 6
19
int
i = 0;
// ADS126X pin AIN0, for positive input
20
int
pos_pin = 0;
// ADS126X pin AIN0, for positive input
21
// int pos_pin = ADS126X_AIN0;
22
23
int
neg_pin
= 0xA;
// ADS1263 pin AINCOM, for negative input
24
25
unsigned
long
totalReadTime = 0;
26
unsigned
long
minReadTime = ULONG_MAX;
27
unsigned
long
maxReadTime = 0;
28
int
readCount = 0;
29
unsigned
long
readTime = 0;
30
unsigned
long
start_time
= 0;
31
32
void
setup
() {
33
ADS126X
adc
;
34
Serial
.begin(115200);
35
Serial
.println(
"Here:"
);
36
SPI.begin(SCLK, DOUT, DIN, CS);
37
38
adc
.begin(CS);
// setup with chip select pin
39
adc
.startADC1();
// start conversion on ADC1
40
adc
.setRate(
ADS126X_RATE_38400
);
41
42
pinMode
(DRDY_PIN,
INPUT
);
43
44
Serial
.println(
"Reading Voltages:"
);
45
}
46
47
void
loop
() {
48
ADS126X
adc
;
49
// REAL FOR LOOP
50
for
(
int
i = 0; i < 10; i++) {
51
totalReadTime += readTime;
52
readCount++;
53
start_time
=
micros
();
54
unsigned
long
readTime = 0;
55
56
long
volt_reader =
adc
.readADC1(i,
neg_pin
);
// read the voltage
57
float
voltage
= (float)(volt_reader) * 5 / 8388608;
// 2^23 = 8388608
58
59
while
(
digitalRead
(DRDY_PIN) ==
HIGH
) {
60
// wait
61
}
62
delayMicroseconds
(150);
63
// if drdy doesnt work, use this and comment out drdy
64
65
volt_reader =
adc
.readADC1(i,
neg_pin
);
// read the voltage
66
Serial
.print(i);
67
Serial
.print(
": "
);
68
Serial
.println(volt_reader);
// send voltage through serial
69
voltage
= (float)(volt_reader) * 5 / 8388608;
70
Serial
.print(i);
71
Serial
.print(
": "
);
72
Serial
.print(voltage, 6);
73
Serial
.println(
" V"
);
74
75
while
(
digitalRead
(DRDY_PIN) ==
HIGH
) {
76
// wait
77
}
78
79
delayMicroseconds
(150);
80
// if drdy doesnt work, use this and comment out drdy
81
82
readTime =
micros
() -
start_time
;
83
Serial
.println(
"\nTiming statistics:"
);
84
Serial
.print(
"Current read time: "
);
85
Serial
.print(readTime);
86
Serial
.println(
" Aµs"
);
87
88
// Calculate effective sampling rate
89
float
samplesPerSecond = 10000000.0 / readTime;
90
Serial
.print(
"Effective sampling rate: "
);
91
Serial
.print(samplesPerSecond, 2);
92
Serial
.println(
" samples per second"
);
93
94
Serial
.print(
"Total samples read: "
);
95
Serial
.println(readCount * 10);
96
}
97
}
98
#endif
// RUN_SENSE_TEST
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
HIGH
#define HIGH
Definition
Arduino.h:19
pinMode
void pinMode(int, int)
Definition
Arduino.h:46
micros
unsigned long micros()
Definition
Arduino.h:37
delayMicroseconds
void delayMicroseconds(unsigned int)
Definition
Arduino.h:58
SPI.h
ADS126X_RATE_38400
#define ADS126X_RATE_38400
Definition
STAR_ADS126X_definitions.h:139
ADS126X
Definition
STAR_ADS126X.h:25
neg_pin
uint8_t neg_pin
Definition
constants.h:6
setup
void setup()
Definition
main.cpp:571
loop
void loop()
Definition
main.cpp:621
adc
static STAR_MCP3201 adc(MCP3201_CS_PIN, &mcp_spi)
autonomous_calibration_engine.voltage
float voltage
Definition
autonomous_calibration_engine.py:729
capture_raw_packets.start_time
start_time
Definition
capture_raw_packets.py:28
firmware
PT_Board
Old_PT_2
src
sense.cpp
Generated by
1.15.0