STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
adcs_pulse.cpp
Go to the documentation of this file.
1
// // adc.cpp
2
// // Abstraction for adc library
3
4
// #include "adcs.h"
5
6
// #include <Arduino.h>
7
// #include "board_pins.h"
8
9
// static ADS126X ads;
10
11
// namespace adcs {
12
// //
13
// -----------------------------------------------------------------------------
14
// // init
15
// //
16
// -----------------------------------------------------------------------------
17
// bool init() {
18
// // Pins
19
// pinMode(START, OUTPUT);
20
// pinMode(DRDY, INPUT);
21
// digitalWrite(START, LOW); // START will stay low forever as START1 cmd
22
// over SPI will be used instead
23
24
// ads.begin(CS);
25
// ads.enableInternalReference(); // 2.5V
26
// delay(50); // Delay for settling
27
28
// return true;
29
// }
30
31
// //
32
// -----------------------------------------------------------------------------
33
// // configure
34
// // Default: 38.4 kSPS, SINCn ignored at this rate, CHOP off, pulse mode
35
// // Also runs self-offset calibration at the end.
36
// //
37
// -----------------------------------------------------------------------------
38
// bool configure(uint8_t negativeReference,
39
// uint8_t positiveReference,
40
// bool bypassPGA,
41
// uint8_t gainPGA,
42
// uint8_t chopMode,
43
// uint8_t sincFilter,
44
// uint8_t rate
45
// )
46
// {
47
48
// if (negativeReference != REF_SKIP && positiveReference != REF_SKIP) {
49
// ads.setReference(negativeReference, positiveReference);
50
// }
51
// if (bypassPGA) {
52
// ads.bypassPGA(); // COMMENT OUT
53
// }
54
// else if (!bypassPGA && gainPGA) {
55
// ads.enablePGA();
56
// ads.setGain(gainPGA);
57
// }
58
// else {
59
// ads.bypassPGA();
60
// }
61
// ads.setChopMode(chopMode);
62
63
// if (sincFilter != FILT_SKIP) {
64
// ads.setFilter(sincFilter);
65
// }
66
// ads.setRate(rate);
67
// // ads.setPulseMode(); cts
68
// ads.calibrateSelfOffsetADC1();
69
70
// return true;
71
// }
72
73
// ADS126X& device() {
74
// return ads;
75
// }
76
77
// void setChannel(uint8_t channel) {
78
// ads.readADC1(channel, neg_pin);
79
// }
80
81
// ReadResult read(uint8_t channel) {
82
// uint32_t read_start = micros();
83
// adcs::setChannel(channel);
84
// uint32_t conv_start = micros();
85
// ads.startADC1();
86
87
// // Data Ready
88
// uint32_t t_wait = micros();
89
// while (digitalRead(DRDY) == HIGH) {
90
// if (micros() - t_wait > 100000) { // 100 ms timeout guard
91
// return {INT32_MIN, 0u, 0u, 0u, false};
92
// }
93
// }
94
// uint32_t conv_time_dur = micros() - conv_start;
95
96
// long raw = ads.readADC1(channel, neg_pin);
97
98
// uint32_t read_time_dur = micros() - read_start;
99
// uint32_t sample_time = t_wait + (conv_time_dur >> 1);
100
101
// return ReadResult{raw, sample_time, read_time_dur, conv_time_dur, true};
102
// }
103
104
// AllResults readAll(const uint8_t* channels, size_t num_channels) {
105
// AllResults results{};
106
// const uint32_t read_start = micros();
107
108
// const size_t results_size = (num_channels <= MAX_CHANNELS) ? num_channels
109
// : MAX_CHANNELS; results.count = results_size;
110
111
// // Sweep channels
112
113
// for (size_t i = 0; i < results_size; ++i) {
114
// const uint8_t ch = channels[i];
115
// results.samples[i].channel = ch;
116
// results.samples[i].result = read(ch);
117
// if (!results.samples[i].result.ok) {
118
// results.failures++;
119
// }
120
// }
121
122
// results.total_time = micros() - read_start;
123
124
// return results;
125
// }
126
127
// }
firmware
ADC_Testing
Noise_Characterization
test
Old
adcs_pulse.cpp
Generated by
1.15.0