Mihaly Vadai
/
muonhunter-K8
MH K8 firmware with HV control.
Fork of muonhunter-K8 by
main.cpp@11:5a5f16e09f10, 2019-04-22 (annotated)
- Committer:
- mihaly
- Date:
- Mon Apr 22 14:00:08 2019 +0000
- Revision:
- 11:5a5f16e09f10
- Parent:
- 10:534172e71f4f
K8 fimrware initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mva111 | 0:52895a475820 | 1 | #include "mbed.h" |
mva111 | 0:52895a475820 | 2 | #include "hvcontrol.cpp" |
mva111 | 0:52895a475820 | 3 | #include "detection.cpp" |
mihaly | 11:5a5f16e09f10 | 4 | #include <queue> |
OliverKeller | 7:6a0958c2be7e | 5 | #include "NOKIA_5110.h" |
mva111 | 0:52895a475820 | 6 | |
mihaly | 8:d75cc0c4c2e6 | 7 | volatile double targetVoltage1 = 400; |
mihaly | 8:d75cc0c4c2e6 | 8 | volatile double targetVoltage2 = 400; |
mihaly | 8:d75cc0c4c2e6 | 9 | |
mihaly | 8:d75cc0c4c2e6 | 10 | |
mihaly | 8:d75cc0c4c2e6 | 11 | //set the initial frequency of the oscillators below |
mihaly | 8:d75cc0c4c2e6 | 12 | volatile int f1 = 4000; //3500; |
mihaly | 8:d75cc0c4c2e6 | 13 | volatile int f2 = 4000; |
mihaly | 10:534172e71f4f | 14 | volatile int prevVoltage1; |
mihaly | 10:534172e71f4f | 15 | volatile int prevVoltage2; |
mihaly | 8:d75cc0c4c2e6 | 16 | int deltaF = 20; |
mihaly | 8:d75cc0c4c2e6 | 17 | int deltaV = 2; |
mihaly | 8:d75cc0c4c2e6 | 18 | bool hv1Ready = 0; |
mihaly | 8:d75cc0c4c2e6 | 19 | bool hv2Ready = 0; |
mva111 | 5:9c7c88f8f800 | 20 | |
mva111 | 5:9c7c88f8f800 | 21 | //set the coincidence times in us below |
OliverKeller | 7:6a0958c2be7e | 22 | int coincidence_wait = 50; //150; |
mihaly | 11:5a5f16e09f10 | 23 | bool buzzer = 0; |
mihaly | 11:5a5f16e09f10 | 24 | bool muonLED = 0; |
mva111 | 5:9c7c88f8f800 | 25 | |
mva111 | 5:9c7c88f8f800 | 26 | /* NO USER CONFIGURABLE OPTIONS BELOW |
mva111 | 5:9c7c88f8f800 | 27 | */ |
mva111 | 5:9c7c88f8f800 | 28 | |
mva111 | 0:52895a475820 | 29 | //typically around 2 min data |
mva111 | 0:52895a475820 | 30 | //assuming normal background |
OliverKeller | 7:6a0958c2be7e | 31 | #define DETECTION_MEMORY_LIMIT 32 //128 |
mva111 | 0:52895a475820 | 32 | |
mva111 | 0:52895a475820 | 33 | //doesn't log the GM hits with a timestamp |
mva111 | 0:52895a475820 | 34 | //only counts them when set to 1 |
OliverKeller | 7:6a0958c2be7e | 35 | #define DETECT_MUONS_ONLY 1 |
mva111 | 5:9c7c88f8f800 | 36 | |
mva111 | 0:52895a475820 | 37 | bool mdet = 0; |
OliverKeller | 7:6a0958c2be7e | 38 | /*volatile*/ int muon_total; |
OliverKeller | 7:6a0958c2be7e | 39 | /*volatile*/ int gm1_total; |
OliverKeller | 7:6a0958c2be7e | 40 | /*volatile*/ int gm2_total; |
OliverKeller | 7:6a0958c2be7e | 41 | int minutes = 0; //global minutes counter |
mva111 | 0:52895a475820 | 42 | |
mva111 | 0:52895a475820 | 43 | //storing a detections in a FIFO queue |
mihaly | 11:5a5f16e09f10 | 44 | queue<Detection> detections; |
mva111 | 0:52895a475820 | 45 | |
mva111 | 0:52895a475820 | 46 | //High voltage controls |
mva111 | 0:52895a475820 | 47 | HVControl hv1(PA_3, PA_0); |
mva111 | 0:52895a475820 | 48 | HVControl hv2(PB_1, PA_1); |
mva111 | 0:52895a475820 | 49 | |
OliverKeller | 7:6a0958c2be7e | 50 | //Serial rpi(PA_9,PA_10); |
mva111 | 0:52895a475820 | 51 | |
mva111 | 0:52895a475820 | 52 | Timer coincidence_timer; |
mva111 | 0:52895a475820 | 53 | Timer main_t; |
mva111 | 0:52895a475820 | 54 | |
mva111 | 0:52895a475820 | 55 | Serial pc(USBTX, USBRX); |
mva111 | 0:52895a475820 | 56 | // Ticker debug; |
mva111 | 0:52895a475820 | 57 | Ticker hv1monitor; |
mva111 | 0:52895a475820 | 58 | Ticker hv2monitor; |
OliverKeller | 7:6a0958c2be7e | 59 | //Ticker memory_checker; |
mva111 | 0:52895a475820 | 60 | |
mva111 | 0:52895a475820 | 61 | DigitalOut led(LED1); |
mva111 | 0:52895a475820 | 62 | DigitalOut GM1_led(PA_12); |
mva111 | 0:52895a475820 | 63 | DigitalOut GM2_led(PA_8); |
mva111 | 0:52895a475820 | 64 | DigitalOut C_led(PA_11); |
mva111 | 0:52895a475820 | 65 | DigitalOut Buzzer(PF_0); |
mva111 | 0:52895a475820 | 66 | |
mva111 | 0:52895a475820 | 67 | InterruptIn GM1(PB_0); |
mva111 | 0:52895a475820 | 68 | InterruptIn GM2(PF_1); |
mva111 | 0:52895a475820 | 69 | |
mva111 | 0:52895a475820 | 70 | //global variables for voltages |
mva111 | 0:52895a475820 | 71 | volatile float v1 = 0; |
mva111 | 0:52895a475820 | 72 | volatile float v2 = 0; |
mva111 | 0:52895a475820 | 73 | |
mva111 | 0:52895a475820 | 74 | //ui functions |
OliverKeller | 7:6a0958c2be7e | 75 | void reset_counters (void) |
OliverKeller | 7:6a0958c2be7e | 76 | { |
mva111 | 0:52895a475820 | 77 | muon_total = 0; |
mva111 | 0:52895a475820 | 78 | gm1_total = 0; |
mva111 | 0:52895a475820 | 79 | gm2_total = 0; |
OliverKeller | 7:6a0958c2be7e | 80 | } |
OliverKeller | 7:6a0958c2be7e | 81 | |
OliverKeller | 7:6a0958c2be7e | 82 | void muon_buzz(void) |
OliverKeller | 7:6a0958c2be7e | 83 | { |
mihaly | 11:5a5f16e09f10 | 84 | if(muonLED) C_led = 1; |
OliverKeller | 7:6a0958c2be7e | 85 | |
OliverKeller | 7:6a0958c2be7e | 86 | if(buzzer) { |
OliverKeller | 7:6a0958c2be7e | 87 | for(int i = 0; i < 32; i++) { |
OliverKeller | 7:6a0958c2be7e | 88 | Buzzer = !Buzzer; |
OliverKeller | 7:6a0958c2be7e | 89 | wait(0.002); |
OliverKeller | 7:6a0958c2be7e | 90 | } |
OliverKeller | 7:6a0958c2be7e | 91 | } else { |
mihaly | 10:534172e71f4f | 92 | wait(0.001); |
mva111 | 0:52895a475820 | 93 | } |
OliverKeller | 7:6a0958c2be7e | 94 | C_led = 0; |
OliverKeller | 7:6a0958c2be7e | 95 | } |
OliverKeller | 7:6a0958c2be7e | 96 | |
OliverKeller | 7:6a0958c2be7e | 97 | void GM1_buzz(void) |
OliverKeller | 7:6a0958c2be7e | 98 | { |
mva111 | 0:52895a475820 | 99 | GM1_led = 1; |
OliverKeller | 7:6a0958c2be7e | 100 | if(buzzer) { |
OliverKeller | 7:6a0958c2be7e | 101 | for(int i = 0; i < 16; i++) { |
OliverKeller | 7:6a0958c2be7e | 102 | Buzzer = !Buzzer; |
OliverKeller | 7:6a0958c2be7e | 103 | wait(0.001); |
OliverKeller | 7:6a0958c2be7e | 104 | } |
OliverKeller | 7:6a0958c2be7e | 105 | } else { |
mihaly | 10:534172e71f4f | 106 | wait(0.001); |
mva111 | 0:52895a475820 | 107 | } |
OliverKeller | 7:6a0958c2be7e | 108 | GM1_led = 0; |
OliverKeller | 7:6a0958c2be7e | 109 | } |
OliverKeller | 7:6a0958c2be7e | 110 | |
OliverKeller | 7:6a0958c2be7e | 111 | void GM2_buzz(void) |
OliverKeller | 7:6a0958c2be7e | 112 | { |
mva111 | 0:52895a475820 | 113 | GM2_led = 1; |
OliverKeller | 7:6a0958c2be7e | 114 | if(buzzer) { |
OliverKeller | 7:6a0958c2be7e | 115 | for(int i = 0; i < 16; i++) { |
OliverKeller | 7:6a0958c2be7e | 116 | Buzzer = !Buzzer; |
OliverKeller | 7:6a0958c2be7e | 117 | wait(0.001); |
OliverKeller | 7:6a0958c2be7e | 118 | } |
OliverKeller | 7:6a0958c2be7e | 119 | } else { |
mihaly | 10:534172e71f4f | 120 | wait(0.003); |
mva111 | 0:52895a475820 | 121 | } |
OliverKeller | 7:6a0958c2be7e | 122 | GM2_led = 0; |
OliverKeller | 7:6a0958c2be7e | 123 | } |
OliverKeller | 7:6a0958c2be7e | 124 | |
OliverKeller | 7:6a0958c2be7e | 125 | |
mva111 | 0:52895a475820 | 126 | //adds a detection onto the queue |
OliverKeller | 7:6a0958c2be7e | 127 | void add_detection(int channel, float time) |
OliverKeller | 7:6a0958c2be7e | 128 | { |
OliverKeller | 7:6a0958c2be7e | 129 | //Detection* det = new Detection(channel, time); |
OliverKeller | 7:6a0958c2be7e | 130 | //detections.push(*det); |
OliverKeller | 7:6a0958c2be7e | 131 | //delete det; |
OliverKeller | 7:6a0958c2be7e | 132 | } |
OliverKeller | 7:6a0958c2be7e | 133 | |
mva111 | 0:52895a475820 | 134 | //callback for GM1 detection |
OliverKeller | 7:6a0958c2be7e | 135 | void GM1_hit(void) |
OliverKeller | 7:6a0958c2be7e | 136 | { |
mva111 | 0:52895a475820 | 137 | coincidence_timer.start(); |
OliverKeller | 7:6a0958c2be7e | 138 | while(coincidence_timer.read_us() < coincidence_wait) { |
OliverKeller | 7:6a0958c2be7e | 139 | if(GM2 == 0 && !mdet) { |
OliverKeller | 7:6a0958c2be7e | 140 | add_detection(3, main_t.read_us()); |
mva111 | 0:52895a475820 | 141 | muon_buzz(); |
mva111 | 0:52895a475820 | 142 | muon_total++; |
mva111 | 6:e95598c44a7f | 143 | gm2_total++; |
mihaly | 11:5a5f16e09f10 | 144 | if(muonLED) mdet = 1; |
OliverKeller | 7:6a0958c2be7e | 145 | } |
mva111 | 0:52895a475820 | 146 | wait(1e-7); |
OliverKeller | 7:6a0958c2be7e | 147 | } |
mva111 | 0:52895a475820 | 148 | coincidence_timer.stop(); |
mva111 | 0:52895a475820 | 149 | coincidence_timer.reset(); |
mva111 | 0:52895a475820 | 150 | if(mdet == 0) GM1_buzz(); |
mva111 | 0:52895a475820 | 151 | if ( !DETECT_MUONS_ONLY ) add_detection(1, main_t.read()); |
mva111 | 0:52895a475820 | 152 | gm1_total++; |
mva111 | 0:52895a475820 | 153 | mdet = 0; |
OliverKeller | 7:6a0958c2be7e | 154 | } |
mva111 | 0:52895a475820 | 155 | |
mva111 | 0:52895a475820 | 156 | //callback for GM2 detection |
OliverKeller | 7:6a0958c2be7e | 157 | void GM2_hit(void) |
OliverKeller | 7:6a0958c2be7e | 158 | { |
OliverKeller | 7:6a0958c2be7e | 159 | coincidence_timer.start(); |
OliverKeller | 7:6a0958c2be7e | 160 | while(coincidence_timer.read_us() < coincidence_wait) { |
OliverKeller | 7:6a0958c2be7e | 161 | if(GM1 == 0 && !mdet) { |
mva111 | 0:52895a475820 | 162 | add_detection(3, main_t.read()); |
mva111 | 0:52895a475820 | 163 | muon_buzz(); |
mva111 | 0:52895a475820 | 164 | muon_total++; |
mva111 | 6:e95598c44a7f | 165 | gm1_total++; |
mihaly | 11:5a5f16e09f10 | 166 | if(muonLED) mdet = 1; |
OliverKeller | 7:6a0958c2be7e | 167 | } |
mva111 | 0:52895a475820 | 168 | wait(1e-7); |
OliverKeller | 7:6a0958c2be7e | 169 | } |
mva111 | 0:52895a475820 | 170 | coincidence_timer.stop(); |
OliverKeller | 7:6a0958c2be7e | 171 | coincidence_timer.reset(); |
mva111 | 0:52895a475820 | 172 | if(mdet == 0) GM2_buzz(); |
mva111 | 0:52895a475820 | 173 | if ( !DETECT_MUONS_ONLY ) add_detection(2, main_t.read()); |
mva111 | 0:52895a475820 | 174 | gm2_total++; |
mva111 | 0:52895a475820 | 175 | mdet = 0; |
OliverKeller | 7:6a0958c2be7e | 176 | } |
OliverKeller | 7:6a0958c2be7e | 177 | |
mva111 | 0:52895a475820 | 178 | // high voltage software monitors |
OliverKeller | 7:6a0958c2be7e | 179 | void hv1monitor_(void) |
OliverKeller | 7:6a0958c2be7e | 180 | { |
mihaly | 10:534172e71f4f | 181 | prevVoltage1 = (prevVoltage1 + v1) / 2; |
mihaly | 8:d75cc0c4c2e6 | 182 | v1 = hv1.get_voltage(); |
mihaly | 10:534172e71f4f | 183 | |
mihaly | 10:534172e71f4f | 184 | if(prevVoltage1 - v1 > 15){ |
mihaly | 10:534172e71f4f | 185 | f1 = 6000; |
mihaly | 10:534172e71f4f | 186 | hv1.set_frequency(f1); |
mihaly | 10:534172e71f4f | 187 | } |
mihaly | 10:534172e71f4f | 188 | |
mihaly | 8:d75cc0c4c2e6 | 189 | if(targetVoltage1 < 200) targetVoltage1 = 200; |
mihaly | 8:d75cc0c4c2e6 | 190 | if(targetVoltage1 > 1000) targetVoltage1 = 1000; |
mihaly | 8:d75cc0c4c2e6 | 191 | |
mihaly | 8:d75cc0c4c2e6 | 192 | if(targetVoltage1 < (v1*(100-deltaV)/100)){ |
mihaly | 8:d75cc0c4c2e6 | 193 | f1 += deltaF; |
mihaly | 8:d75cc0c4c2e6 | 194 | }else if(targetVoltage1 > (v1*(100+deltaV)/100)){ |
mihaly | 8:d75cc0c4c2e6 | 195 | f1 -= deltaF; |
mihaly | 8:d75cc0c4c2e6 | 196 | } |
mihaly | 8:d75cc0c4c2e6 | 197 | |
mihaly | 8:d75cc0c4c2e6 | 198 | if(v1 < targetVoltage1*1.05 && v1 > targetVoltage1*0.95) hv1Ready = 1; |
mihaly | 8:d75cc0c4c2e6 | 199 | else hv1Ready = 0; |
mihaly | 8:d75cc0c4c2e6 | 200 | |
mihaly | 10:534172e71f4f | 201 | hv1.set_frequency(f1); |
OliverKeller | 7:6a0958c2be7e | 202 | } |
mva111 | 0:52895a475820 | 203 | |
OliverKeller | 7:6a0958c2be7e | 204 | void hv2monitor_(void) |
OliverKeller | 7:6a0958c2be7e | 205 | { |
mihaly | 10:534172e71f4f | 206 | prevVoltage2 = (prevVoltage2 + v2) / 2; |
mihaly | 8:d75cc0c4c2e6 | 207 | v2 = hv2.get_voltage(); |
mihaly | 10:534172e71f4f | 208 | |
mihaly | 10:534172e71f4f | 209 | if(prevVoltage2 - v2 > 15){ |
mihaly | 10:534172e71f4f | 210 | f2 = 6000; |
mihaly | 10:534172e71f4f | 211 | hv2.set_frequency(f2); |
mihaly | 10:534172e71f4f | 212 | } |
mihaly | 10:534172e71f4f | 213 | |
mihaly | 8:d75cc0c4c2e6 | 214 | if(targetVoltage2 < 200) targetVoltage2 = 200; |
mihaly | 8:d75cc0c4c2e6 | 215 | if(targetVoltage2 > 1000) targetVoltage2 = 1000; |
mihaly | 8:d75cc0c4c2e6 | 216 | |
mihaly | 8:d75cc0c4c2e6 | 217 | if(targetVoltage2 < (v2*(100-deltaV)/100)){ |
mihaly | 8:d75cc0c4c2e6 | 218 | f2 += deltaF; |
mihaly | 8:d75cc0c4c2e6 | 219 | }else if(targetVoltage2 > (v2*(100-deltaV)/100)){ |
mihaly | 8:d75cc0c4c2e6 | 220 | f2 -= deltaF; |
mihaly | 8:d75cc0c4c2e6 | 221 | } |
mihaly | 8:d75cc0c4c2e6 | 222 | |
mihaly | 8:d75cc0c4c2e6 | 223 | if(v2 < targetVoltage2*1.05 && v2 > targetVoltage2*0.95) hv2Ready = 1; |
mihaly | 8:d75cc0c4c2e6 | 224 | else hv2Ready = 0; |
mihaly | 8:d75cc0c4c2e6 | 225 | |
mihaly | 8:d75cc0c4c2e6 | 226 | hv2.set_frequency(f2); |
OliverKeller | 7:6a0958c2be7e | 227 | } |
mva111 | 0:52895a475820 | 228 | |
mva111 | 0:52895a475820 | 229 | //discarding older items if buffer gets too big |
OliverKeller | 7:6a0958c2be7e | 230 | //void memory_checker_(void) |
OliverKeller | 7:6a0958c2be7e | 231 | //{ |
OliverKeller | 7:6a0958c2be7e | 232 | // if ( detections.size() > (DETECTION_MEMORY_LIMIT - (DETECTION_MEMORY_LIMIT/8)) ) { |
OliverKeller | 7:6a0958c2be7e | 233 | // while ( detections.size() > (DETECTION_MEMORY_LIMIT - (DETECTION_MEMORY_LIMIT/4)) ) { |
OliverKeller | 7:6a0958c2be7e | 234 | // detections.pop(); |
OliverKeller | 7:6a0958c2be7e | 235 | // } |
OliverKeller | 7:6a0958c2be7e | 236 | // } |
OliverKeller | 7:6a0958c2be7e | 237 | //} |
mva111 | 0:52895a475820 | 238 | |
OliverKeller | 7:6a0958c2be7e | 239 | char* itoa(int value, char* result, int base) |
OliverKeller | 7:6a0958c2be7e | 240 | { |
OliverKeller | 7:6a0958c2be7e | 241 | // check that the base if valid |
OliverKeller | 7:6a0958c2be7e | 242 | if ( base < 2 || base > 36 ) { |
OliverKeller | 7:6a0958c2be7e | 243 | *result = '\0'; |
OliverKeller | 7:6a0958c2be7e | 244 | return result; |
OliverKeller | 7:6a0958c2be7e | 245 | } |
OliverKeller | 7:6a0958c2be7e | 246 | |
OliverKeller | 7:6a0958c2be7e | 247 | char* ptr = result, *ptr1 = result, tmp_char; |
OliverKeller | 7:6a0958c2be7e | 248 | int tmp_value; |
OliverKeller | 7:6a0958c2be7e | 249 | |
OliverKeller | 7:6a0958c2be7e | 250 | do { |
OliverKeller | 7:6a0958c2be7e | 251 | tmp_value = value; |
OliverKeller | 7:6a0958c2be7e | 252 | value /= base; |
OliverKeller | 7:6a0958c2be7e | 253 | *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)]; |
OliverKeller | 7:6a0958c2be7e | 254 | } while ( value ); |
OliverKeller | 7:6a0958c2be7e | 255 | |
OliverKeller | 7:6a0958c2be7e | 256 | // Apply negative sign |
OliverKeller | 7:6a0958c2be7e | 257 | if ( tmp_value < 0 ) |
OliverKeller | 7:6a0958c2be7e | 258 | *ptr++ = '-'; |
OliverKeller | 7:6a0958c2be7e | 259 | *ptr-- = '\0'; |
OliverKeller | 7:6a0958c2be7e | 260 | |
OliverKeller | 7:6a0958c2be7e | 261 | while ( ptr1 < ptr ) { |
OliverKeller | 7:6a0958c2be7e | 262 | tmp_char = *ptr; |
OliverKeller | 7:6a0958c2be7e | 263 | *ptr-- = *ptr1; |
OliverKeller | 7:6a0958c2be7e | 264 | *ptr1++ = tmp_char; |
OliverKeller | 7:6a0958c2be7e | 265 | } |
OliverKeller | 7:6a0958c2be7e | 266 | |
OliverKeller | 7:6a0958c2be7e | 267 | return result; |
OliverKeller | 7:6a0958c2be7e | 268 | } |
OliverKeller | 7:6a0958c2be7e | 269 | |
OliverKeller | 7:6a0958c2be7e | 270 | int main() |
OliverKeller | 7:6a0958c2be7e | 271 | { |
OliverKeller | 7:6a0958c2be7e | 272 | //start main timer |
OliverKeller | 7:6a0958c2be7e | 273 | pc.baud(230400); |
OliverKeller | 7:6a0958c2be7e | 274 | main_t.start(); |
OliverKeller | 7:6a0958c2be7e | 275 | LcdPins myPins; |
OliverKeller | 7:6a0958c2be7e | 276 | |
OliverKeller | 7:6a0958c2be7e | 277 | myPins.rst = PA_6; |
OliverKeller | 7:6a0958c2be7e | 278 | myPins.sce = PA_4; |
OliverKeller | 7:6a0958c2be7e | 279 | myPins.dc = PB_4; |
OliverKeller | 7:6a0958c2be7e | 280 | myPins.mosi = PA_7;//SPI_MOSI; |
OliverKeller | 7:6a0958c2be7e | 281 | myPins.miso = NC; |
OliverKeller | 7:6a0958c2be7e | 282 | myPins.sclk = PA_5;//SPI_SCK; |
mva111 | 0:52895a475820 | 283 | |
OliverKeller | 7:6a0958c2be7e | 284 | // Start the LCD |
OliverKeller | 7:6a0958c2be7e | 285 | NokiaLcd myLcd( myPins ); |
OliverKeller | 7:6a0958c2be7e | 286 | myLcd.InitLcd(); // LCD is reset and DDRAM is cleared |
OliverKeller | 7:6a0958c2be7e | 287 | myLcd.DrawString("MUON HUNTER V2"); |
OliverKeller | 7:6a0958c2be7e | 288 | myLcd.SetXY(0,1); |
OliverKeller | 7:6a0958c2be7e | 289 | myLcd.DrawString("TIME "); |
OliverKeller | 7:6a0958c2be7e | 290 | myLcd.SetXY(0,3); |
OliverKeller | 7:6a0958c2be7e | 291 | myLcd.DrawString("MUON COUNT"); |
OliverKeller | 7:6a0958c2be7e | 292 | myLcd.SetXY(0,4); |
OliverKeller | 7:6a0958c2be7e | 293 | myLcd.DrawString("GM1 COUNT"); |
OliverKeller | 7:6a0958c2be7e | 294 | myLcd.SetXY(0,5); |
OliverKeller | 7:6a0958c2be7e | 295 | myLcd.DrawString("GM2 COUNT"); |
OliverKeller | 7:6a0958c2be7e | 296 | hv1.set_frequency(f1); |
OliverKeller | 7:6a0958c2be7e | 297 | hv2.set_frequency(f2); |
OliverKeller | 7:6a0958c2be7e | 298 | GM1.fall(&GM1_hit); |
OliverKeller | 7:6a0958c2be7e | 299 | GM2.fall(&GM2_hit); |
mva111 | 0:52895a475820 | 300 | |
OliverKeller | 7:6a0958c2be7e | 301 | //tickers to monitor the high voltage |
OliverKeller | 7:6a0958c2be7e | 302 | hv1monitor.attach(&hv1monitor_, 0.1); |
OliverKeller | 7:6a0958c2be7e | 303 | hv2monitor.attach(&hv2monitor_, 0.1); |
OliverKeller | 7:6a0958c2be7e | 304 | |
mihaly | 9:fe24e28b391a | 305 | // offset for proto board |
mihaly | 10:534172e71f4f | 306 | targetVoltage2 *= 0.79; |
mihaly | 9:fe24e28b391a | 307 | |
OliverKeller | 7:6a0958c2be7e | 308 | char number[10]; |
OliverKeller | 7:6a0958c2be7e | 309 | |
OliverKeller | 7:6a0958c2be7e | 310 | //ticker to monitor memory usage |
OliverKeller | 7:6a0958c2be7e | 311 | //memory_checker.attach(&memory_checker_, 0.2); |
OliverKeller | 7:6a0958c2be7e | 312 | while(1) { |
mihaly | 8:d75cc0c4c2e6 | 313 | |
OliverKeller | 7:6a0958c2be7e | 314 | myLcd.SetXY(5*6,1); |
OliverKeller | 7:6a0958c2be7e | 315 | unsigned int seconds = (int) main_t.read(); |
OliverKeller | 7:6a0958c2be7e | 316 | //int minutes = (seconds/60); |
OliverKeller | 7:6a0958c2be7e | 317 | if (seconds >= 60) { |
OliverKeller | 7:6a0958c2be7e | 318 | main_t.reset(); |
OliverKeller | 7:6a0958c2be7e | 319 | minutes++; |
OliverKeller | 7:6a0958c2be7e | 320 | } |
OliverKeller | 7:6a0958c2be7e | 321 | if (minutes < 10) |
OliverKeller | 7:6a0958c2be7e | 322 | myLcd.DrawChar('0'); |
OliverKeller | 7:6a0958c2be7e | 323 | itoa(minutes, number, 10); |
OliverKeller | 7:6a0958c2be7e | 324 | myLcd.DrawString(number); |
OliverKeller | 7:6a0958c2be7e | 325 | myLcd.DrawChar(':'); |
OliverKeller | 7:6a0958c2be7e | 326 | if ((seconds%60) < 10) |
OliverKeller | 7:6a0958c2be7e | 327 | myLcd.DrawChar('0'); |
OliverKeller | 7:6a0958c2be7e | 328 | itoa(seconds%60, number,10); |
OliverKeller | 7:6a0958c2be7e | 329 | myLcd.DrawString(number); |
OliverKeller | 7:6a0958c2be7e | 330 | |
OliverKeller | 7:6a0958c2be7e | 331 | myLcd.SetXY(11*6,3); |
OliverKeller | 7:6a0958c2be7e | 332 | itoa(muon_total, number, 10); |
OliverKeller | 7:6a0958c2be7e | 333 | myLcd.DrawString(number); |
OliverKeller | 7:6a0958c2be7e | 334 | |
mihaly | 8:d75cc0c4c2e6 | 335 | myLcd.SetXY(3*6,4); |
mihaly | 8:d75cc0c4c2e6 | 336 | if(hv1Ready) myLcd.DrawString(" "); |
mihaly | 8:d75cc0c4c2e6 | 337 | else myLcd.DrawString("*"); |
mihaly | 8:d75cc0c4c2e6 | 338 | |
OliverKeller | 7:6a0958c2be7e | 339 | myLcd.SetXY(11*6,4); |
OliverKeller | 7:6a0958c2be7e | 340 | itoa(gm1_total, number, 10); |
OliverKeller | 7:6a0958c2be7e | 341 | myLcd.DrawString(number); |
OliverKeller | 7:6a0958c2be7e | 342 | |
mihaly | 8:d75cc0c4c2e6 | 343 | myLcd.SetXY(3*6,5); |
mihaly | 8:d75cc0c4c2e6 | 344 | if(hv2Ready) myLcd.DrawString(" "); |
mihaly | 8:d75cc0c4c2e6 | 345 | else myLcd.DrawString("*"); |
mihaly | 8:d75cc0c4c2e6 | 346 | |
OliverKeller | 7:6a0958c2be7e | 347 | myLcd.SetXY(11*6,5); |
OliverKeller | 7:6a0958c2be7e | 348 | itoa(gm2_total, number, 10); |
OliverKeller | 7:6a0958c2be7e | 349 | myLcd.DrawString(number); |
OliverKeller | 7:6a0958c2be7e | 350 | |
OliverKeller | 7:6a0958c2be7e | 351 | |
mihaly | 11:5a5f16e09f10 | 352 | while(!detections.empty()){ |
mihaly | 11:5a5f16e09f10 | 353 | Detection temp = detections.front(); |
mihaly | 11:5a5f16e09f10 | 354 | |
mihaly | 11:5a5f16e09f10 | 355 | pc.printf("Ch: %d, Time: %.2fs, V1: %.1fV, V2: %.1fV \n\r", temp.channel, temp.time, v1, v2); |
mihaly | 11:5a5f16e09f10 | 356 | pc.printf("Total GM1: %d, Total GM2: %d, Total Coinc: %d \n\r \n\r", gm1_total, gm2_total, muon_total); |
mihaly | 11:5a5f16e09f10 | 357 | detections.pop(); |
mihaly | 11:5a5f16e09f10 | 358 | } |
OliverKeller | 7:6a0958c2be7e | 359 | |
OliverKeller | 7:6a0958c2be7e | 360 | pc.printf("%.fs, GM1: %d, GM2: %d, Muons: %d \n\r", main_t.read(), gm1_total, gm2_total, muon_total); |
OliverKeller | 7:6a0958c2be7e | 361 | pc.printf("V1: %.1fV, V2: %.1fV \n\r", v1, v2); |
mva111 | 1:549e331aefab | 362 | wait(1); |
OliverKeller | 7:6a0958c2be7e | 363 | } |
mva111 | 0:52895a475820 | 364 | } |