-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.h
202 lines (181 loc) · 4.37 KB
/
counter.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*counter.h - Include file for SN74LV8154 IC driver
Copyright (c) 2020 Justin Holland. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
#ifndef COUNTER_H_
#define COUNTER_H_
#include "Arduino.h"
class ShiftRegIC;
class CounterIC {
public:
const char* mode;
ShiftRegIC* serial_output;
uint8_t GAL_pin;
uint8_t GAU_pin;
uint8_t GBL_pin;
uint8_t GBU_pin;
uint8_t CCLR_pin;
uint8_t RCLK_pin;
uint8_t RCOA_pin;
uint8_t CLKBEN_pin;
uint8_t Y0_pin;
uint8_t Y1_pin;
uint8_t Y2_pin;
uint8_t Y3_pin;
uint8_t Y4_pin;
uint8_t Y5_pin;
uint8_t Y6_pin;
uint8_t Y7_pin;
uint8_t a_trig_pin;
uint8_t b_trig_pin;
uint32_t a_freq;
uint32_t b_freq;
//Initialization argument:
//mode = "single" for single 32-bit counter configuration
//mode = "dual" for dual 16-bit counters configuration
CounterIC(const char* m) : mode(m)
{
GAL_pin = 255;
GAU_pin = 255;
GBL_pin = 255;
GBU_pin = 255;
CCLR_pin = 255;
RCLK_pin = 255;
RCOA_pin = 255;
CLKBEN_pin = 255;
Y0_pin = 255;
Y1_pin = 255;
Y2_pin = 255;
Y3_pin = 255;
Y4_pin = 255;
Y5_pin = 255;
Y6_pin = 255;
Y7_pin = 255;
a_trig_pin = 255;
b_trig_pin = 255;
a_freq = 0;
b_freq = 0;
serial_output = NULL;
_clkBenable = false;
_updateRunning = false;
_single = false;
_overflow = false;
_toggle = false;
_shift = false;
_clear = false;
_testA = false;
_testB = false;
_resetTimers = false;
_resetTimer1 = false;
_resetTimer2 = false;
_resetTimer3 = false;
t0_1 = 0;
t0_2 = 0;
t0_3 = 0;
tf_1 = 0;
tf_2 = 0;
tf_3 = 0;
testA_delay = 0;
testB_delay = 0;
}
CounterIC(const char* m, ShiftRegIC* s) : mode(m), serial_output(s)
{
GAL_pin = 255;
GAU_pin = 255;
GBL_pin = 255;
GBU_pin = 255;
CCLR_pin = 255;
RCLK_pin = 255;
RCOA_pin = 255;
CLKBEN_pin = 255;
Y0_pin = 255;
Y1_pin = 255;
Y2_pin = 255;
Y3_pin = 255;
Y4_pin = 255;
Y5_pin = 255;
Y6_pin = 255;
Y7_pin = 255;
a_trig_pin = 255;
b_trig_pin = 255;
a_freq = 0;
b_freq = 0;
_clkBenable = false;
_updateRunning = false;
_single = false;
_overflow = false;
_toggle = false;
_shift = false;
_clear = false;
_testA = false;
_testB = false;
_resetTimers = false;
_resetTimer1 = false;
_resetTimer2 = false;
_resetTimer3 = false;
t0_1 = 0;
t0_2 = 0;
t0_3 = 0;
tf_1 = 0;
tf_2 = 0;
tf_3 = 0;
testA_delay = 0;
testB_delay = 0;
}
//Pin setting functions
void set_data_pins(uint8_t pins[8]);
void set_gate_pins(uint8_t gau, uint8_t gal);
void set_gate_pins(uint8_t gau, uint8_t gal, uint8_t gbu, uint8_t gbl);
void set_clear_pin(uint8_t cclr);
void set_regclock_pin(uint8_t rclk);
void set_rcoa_pin(uint8_t rcoa);
void set_clkben_pin(uint8_t clkben);
void set_test_pins(uint8_t a);
void set_test_pins(uint8_t a, uint8_t b);
//Configuration functions
void set_testA_freq(uint32_t fa);
void set_testB_freq(uint32_t fb);
void set_serial_conn(ShiftRegIC* s);
//Initialization function
void init();
//Update function
void update();
//Counter functions
uint32_t readCounter(const char* ab);
uint32_t readCounter_32bit();
void clearCounters();
void toggleCounterB();
bool enabledCounterB();
bool overFlow();
private:
bool _clkBenable;
bool _updateRunning;
bool _single;
bool _overflow;
bool _toggle;
bool _shift;
bool _clear;
bool _testA;
bool _testB;
bool _resetTimers;
bool _resetTimer1;
bool _resetTimer2;
bool _resetTimer3;
uint32_t t0_1;
uint32_t t0_2;
uint32_t t0_3;
uint32_t tf_1;
uint32_t tf_2;
uint32_t tf_3;
uint32_t testA_delay;
uint32_t testB_delay;
uint32_t readDataPins();
};
#endif /* COUNTER_H_ */