-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathABE_ADCDACPi.h
108 lines (88 loc) · 2.57 KB
/
ABE_ADCDACPi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
================================================
ABElectronics UK ADC-DAC Pi
Version 1.0 Created 23/06/2017
================================================
*/
#ifndef ADCDACPI_ABE_ADCDACPI_H_
#define ADCDACPI_ABE_ADCDACPI_H_
#endif /* ADCDACPI_ABE_ADCDACPI_H_ */
namespace ABElectronics_CPP_Libraries
{
class ADCDACPi
{
// public methods
public:
ADCDACPi();
/**
* Open the ADC SPI bus channel
* This needs to be called before using the DAC
*/
int open_adc();
/**
* Close the ADC SPI bus channel
*/
void close_adc();
/**
* Open the DAC SPI bus channel
* This needs to be called before using the DAC
*/
int open_dac();
/**
* Close the DAC SPI bus channel
*/
void close_dac();
/**
* Read the voltage from the ADC
* @param channel - 1 or 2
* @param mode - 0 = Single Ended or 1 = Differential
* When in differential mode setting channel to 1 will make IN1 = IN+ and IN2 = IN-
* When in differential mode setting channel to 2 will make IN1 = IN- and IN2 = IN+
* @returns between 0V and the reference voltage
*/
double read_adc_voltage(int channel, int mode);
/**
* Read the raw value from the ADC
* @param channel - 1 to 8
* @param mode - 0 = Single Ended or 1 = Differential
* When in differential mode setting channel to 1 will make IN1 = IN+ and IN2 = IN-
* When in differential mode setting channel to 2 will make IN1 = IN- and IN2 = IN+
* @returns 12 bit value between 0 and 4096
*/
int read_adc_raw(int channel, int mode);
/**
* Set the reference voltage for the adc
* @param ref - Set this value to be the same as the voltage measured on the 3.3V GPIO pin
*/
void set_adc_refvoltage(double ref);
/**
* Set the DAC voltage
* @param voltage - between 0 and 2.048 when gain is set to 1, 0 and 3.3 when gain is set to 2
* @param channel - 1 or 2
*/
void set_dac_voltage(double voltage, int channel);
/**
* Set the raw value from the selected channel on the DAC
* @param raw - between 0 and 4095
* @param channel - 1 or 2
*/
void set_dac_raw(uint16_t raw, int channel);
/**
* Set the DAC gain
* @param gain - 1 or 2 - The output voltage will be between 0 and 2.048V when gain is set to 1, 0 and 3.3V when gain is set to 2
*/
void set_dac_gain(int gain);
private:
// private variables
uint8_t mode; // SPI_MODE_0
uint32_t speed; // SPI bus speed
uint8_t adctx[3]; // transmit buffer for the ADC
uint8_t adcrx[3]; // receive buffer for the ADC
uint8_t dactx[2]; // transmit buffer for the DAC
int adc; // adc object
int dac; // dac object
double adcrefvoltage; // reference voltage for the ADC chip.
int dacgain; // gain setting for the DAC chip.
double dacvoltage; // maximum voltage for the DAC output
};
}