-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAC_Prog.ino
67 lines (60 loc) · 1.52 KB
/
DAC_Prog.ino
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
/*
Programs thresholds on MTCA Plus
...assuming you have the correct chunks of vector board
*/
// Thresholds in Volts
float thresh_h = 4.5;
float thresh_m = 4.5;
float thresh_l = 4.92;
// Arduino pins to use
int dac_clk = 13;
int dac_sel = 11;
int dac_l = 12;
int dac_m = 10;
int dac_h = 9;
const int clk_delay = 50;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(dac_clk, OUTPUT);
pinMode(dac_sel, OUTPUT);
pinMode(dac_l, OUTPUT);
pinMode(dac_m, OUTPUT);
pinMode(dac_h, OUTPUT);
digitalWrite(dac_sel, HIGH);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(dac_sel, LOW);
digitalWrite(dac_clk, HIGH);
unsigned int l = (thresh_l + 5)*(4095/10);;
unsigned int m = (thresh_m + 5)*(4095/10);;
unsigned int h = (thresh_h + 5)*(4095/10);;
// First 4 bits are unused
for(int i=0; i < 4; i++) {
digitalWrite(dac_l, (l>>i) & 1);
digitalWrite(dac_l, LOW);
digitalWrite(dac_m, LOW);
digitalWrite(dac_h, LOW);
digitalWrite(dac_clk, LOW);
delay(50);
digitalWrite(dac_clk, HIGH);
delay(50);
}
for(int i = 11;i>=0;i--)
{
digitalWrite(dac_l, (l>>i) & 1);
digitalWrite(dac_m, (m>>i) & 1);
digitalWrite(dac_h, (h>>i) & 1);
delay(20);
printf("%u\n", (l>>i) & 1);
digitalWrite(dac_clk, LOW);
delay(clk_delay);
digitalWrite(dac_clk, HIGH);
delay(clk_delay);
}
digitalWrite(dac_sel,HIGH);
while(1) {
delay(3600);
}
}