Shield Code 6.0
Loading...
Searching...
No Matches
PipController.hpp
Go to the documentation of this file.
1#ifndef PIP_CONTROLLER_HPP
2#define PIP_CONTROLLER_HPP
3
4#include <Arduino.h>
5#include <Pip.hpp>
11 private:
14 public:
19 void sweep(){
20 double value1 = pip1.sweep_min;
21 double value2 = pip2.sweep_min;
22 double step1 = (double)(pip1.sweep_max - pip1.sweep_min) / (double)(pip1.num_samples - 1);
23 double step2 = (double)(pip2.sweep_max - pip2.sweep_min) / (double)(pip2.num_samples - 1);
24
25 //set delay to max delay between the pips - should always be the same since
26 //both pips are configured the same
27 uint16_t delay = (pip1.delay_us < pip2.delay_us) ? pip1.delay_us : pip2.delay_us;
28 SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE));
29 for (int i = 0; i < pip1.num_samples; i++){
30 analogWrite(pip1.dac_pin, (int)value1);
31 analogWrite(pip2.dac_pin, (int)value2);
32 value1 += step1;
33 value2 += step2;
34 //preamp settling time - experimentally derived
35 delayMicroseconds(delay);
36 int total_data1 = 0;
37 int total_data2 = 0;
38 //avg_num should be same across both pips.
39 for (int i=0; i < pip1.avg_num; i++){
40 total_data1 += pip1.read_adc();
41 total_data2 += pip2.read_adc();
42 }
43 pip1.data[i] = (uint16_t)(total_data1 / pip1.avg_num);
44 pip2.data[i] = (uint16_t)(total_data2 / pip2.avg_num);
45 }
46 analogWrite(pip1.dac_pin, pip1.sweep_min);
47 analogWrite(pip2.dac_pin, pip2.sweep_min);
48 SPI.endTransaction();
49 }
50};
51#endif
#define SPI_SPEED
Definition: Max1148.hpp:32
#define SPI_MODE
Definition: Max1148.hpp:33
Header file for the Pip library for Dartmouth's 317 Lab.
Manages simultaneous sweep for two Pip sensors. A bit hacky, but allows easily managing simultaneous ...
PipController(Pip &pip1, Pip &pip2)
void sweep()
Sweeps both DACs simultaneously, reads both ADC channels. Note that ADC sampling alternates between e...
Manages the Pip sensor sweep and associated data.
Definition: Pip.hpp:33
uint16_t sweep_max
Definition: Pip.hpp:61
uint16_t sweep_min
The minimum and maximum values for the sweep.
Definition: Pip.hpp:60
int delay_us
The delay between steps in the sweep. Measured in microseconds.
Definition: Pip.hpp:43
uint8_t dac_pin
The pin for the DAC output.
Definition: Pip.hpp:39
uint16_t avg_num
The number of samples to average when querying the ADC.
Definition: Pip.hpp:52
uint16_t read_adc()
Definition: Pip.cpp:20
uint16_t num_samples
The number of samples to take during the sweep. AKA the number of steps in the sweep.
Definition: Pip.hpp:56
uint16_t data[SWEEP_MAX_SAMPLES]
The data array for the sweep.
Definition: Pip.hpp:81