11/*
22
33 Open Gamma Detector Sketch
4- Only works on the Raspberry Pi Pico with arduino-pico!
4+ Only works on the Raspberry Pi Pico 2 (!) with arduino-pico!
55
66 Triggers on newly detected pulses and measures their energy.
77
8- 2023 , NuclearPhoenix. Open Gamma Project.
8+ 2024 , NuclearPhoenix. Open Gamma Project.
99 https://github.com/OpenGammaProject/Open-Gamma-Detector
1010
1111 ## NOTE:
1212 ## Only change the highlighted USER SETTINGS below
1313 ## except you know exactly what you are doing!
1414 ## Flash with default settings and
15- ## Flash Size: "2MB (Sketch: 1MB, FS: 1MB )"
15+ ## Flash Size: "4MB (Sketch: 1MB, FS: 3MB )"
1616
1717
1818 TODO: Add cps line trend to geiger mode
@@ -68,13 +68,12 @@ struct Config {
6868 bool enable_display = false ; // Enable I2C Display, see settings above
6969 bool enable_trng = false ; // Enable the True Random Number Generator
7070 bool subtract_baseline = true ; // Subtract the DC bias from each pulse
71- bool cps_correction = false ; // Correct the cps for the DNL compensation
7271 bool enable_ticker = false ; // Enable the buzzer to be used as a ticker for pulses
7372 size_t tick_rate = 20 ; // Buzzer ticks once every tick_rate pulses
7473
7574 // Do NOT modify the following operator function
7675 bool operator ==(const Config &other) const {
77- return (tick_rate == other.tick_rate && enable_ticker == other.enable_ticker && cps_correction == other. cps_correction && ser_output == other.ser_output && geiger_mode == other.geiger_mode && print_spectrum == other.print_spectrum && meas_avg == other.meas_avg && enable_display == other.enable_display && enable_trng == other.enable_trng && subtract_baseline == other.subtract_baseline );
76+ return (tick_rate == other.tick_rate && enable_ticker == other.enable_ticker && ser_output == other.ser_output && geiger_mode == other.geiger_mode && print_spectrum == other.print_spectrum && meas_avg == other.meas_avg && enable_display == other.enable_display && enable_trng == other.enable_trng && subtract_baseline == other.subtract_baseline );
7877 }
7978};
8079/*
@@ -83,7 +82,7 @@ struct Config {
8382 =================
8483*/
8584
86- const String FW_VERSION = " 4.2.2 " ; // Firmware Version Code
85+ const String FW_VERSION = " 4.3.0 " ; // Firmware Version Code
8786
8887const uint8_t GND_PIN = A2; // GND meas pin
8988const uint8_t VSYS_MEAS = A3; // VSYS/3
@@ -653,26 +652,6 @@ void toggleBaseline(String *args) {
653652}
654653
655654
656- void toggleCPSCorrection (String *args) {
657- String command = *args;
658- command.replace (" set correction" , " " );
659- command.trim ();
660-
661- if (command == " on" ) {
662- conf.cps_correction = true ;
663- println (" Enabled CPS correction." );
664- } else if (command == " off" ) {
665- conf.cps_correction = false ;
666- println (" Disabled CPS correction." );
667- } else {
668- println (" Invalid input '" + command + " '." , true );
669- println (" Must be 'on' or 'off'." , true );
670- return ;
671- }
672- saveSettings ();
673- }
674-
675-
676655void setMeasAveraging (String *args) {
677656 String command = *args;
678657 command.replace (" set averaging" , " " );
@@ -706,19 +685,19 @@ void deviceInfo([[maybe_unused]] String *args) {
706685 println (" =========================" );
707686 println (" -- Open Gamma Detector --" );
708687 println (" By NuclearPhoenix, Open Gamma Project" );
709- println (" 2023 . https://github.com/OpenGammaProject" );
688+ println (" 2024 . https://github.com/OpenGammaProject" );
710689 println (" Firmware Version: " + FW_VERSION);
711690 println (" =========================" );
712691 println (" Runtime: \t\t " + String (millis () / 1000.0 ) + " s" );
713692 print (" Average Dead Time: \t " );
714693
715- cleanPrint ((total_events == 0 ) ? " n/a" : String (round (avg_dt), 0 ));
716-
717- cleanPrintln (" µs" );
694+ cleanPrintln ((total_events == 0 ) ? " n/a" : String (round (avg_dt), 0 ) + " µs" );
718695
719696 const float deadtime_frac = avg_dt * total_events / 1000.0 / float (millis ()) * 100.0 ;
720697
721- println (" Total Dead Time: \t " + String (deadtime_frac) + " %" );
698+ print (" Total Dead Time: \t " );
699+ cleanPrintln (isnan (deadtime_frac) ? " n/a" : String (deadtime_frac) + " %" );
700+
722701 println (" Total Pulses: \t " + String (total_events));
723702 println (" CPU Frequency: \t " + String (rp2040.f_cpu () / 1e6 ) + " MHz" );
724703 println (" Used Heap Memory: \t " + String (rp2040.getUsedHeap () / 1000.0 ) + " kB / " + String (rp2040.getUsedHeap () * 100.0 / rp2040.getTotalHeap (), 0 ) + " %" );
@@ -919,9 +898,6 @@ Config loadSettings(bool msg = true) {
919898 if (doc.containsKey (" subtract_baseline" )) {
920899 new_conf.subtract_baseline = doc[" subtract_baseline" ];
921900 }
922- if (doc.containsKey (" cps_correction" )) {
923- new_conf.cps_correction = doc[" cps_correction" ];
924- }
925901 if (doc.containsKey (" enable_ticker" )) {
926902 new_conf.enable_ticker = doc[" enable_ticker" ];
927903 }
@@ -953,7 +929,6 @@ bool writeSettingsFile() {
953929 doc[" enable_display" ] = conf.enable_display ;
954930 doc[" enable_trng" ] = conf.enable_trng ;
955931 doc[" subtract_baseline" ] = conf.subtract_baseline ;
956- doc[" cps_correction" ] = conf.cps_correction ;
957932 doc[" enable_ticker" ] = conf.enable_ticker ;
958933 doc[" tick_rate" ] = conf.tick_rate ;
959934
@@ -1192,9 +1167,10 @@ void eventInt() {
11921167 // Directly uses Core0 IRQ Ctrl (core1 does not set the interrupt).
11931168 // Thanks a lot to all the replies at
11941169 // https://github.com/earlephilhower/arduino-pico/discussions/1397!
1195- static io_rw_32 *addr = &(iobank0_hw->proc0_irq_ctrl .inte [INT_PIN / 8 ]);
1196- static uint32_t mask1 = 0b1111 << (INT_PIN % 8 ) * 4u ;
1197- hw_clear_bits (addr, mask1);
1170+ // NOTE: NOT SUPPORTED ON PICO 2 / RP2350
1171+ // static io_rw_32 *addr = &(iobank0_hw->proc0_irq_ctrl.inte[INT_PIN / 8]);
1172+ // static uint32_t mask1 = 0b1111 << (INT_PIN % 8) * 4u;
1173+ // hw_clear_bits(addr, mask1);
11981174
11991175 const unsigned long start = micros ();
12001176
@@ -1219,36 +1195,23 @@ void eventInt() {
12191195
12201196 if (!conf.geiger_mode && !adc_lock) {
12211197 uint32_t sum = 0 ;
1222- uint8_t num = 0 ;
12231198
12241199 for (size_t i = 0 ; i < conf.meas_avg ; i++) {
1225- const uint16_t m = analogRead (AIN_PIN);
1226- // Pico-ADC DNL issues, see https://pico-adc.markomo.me/INL-DNL/#dnl
1227- // Discard channels 512, 1536, 2560, and 3584. For now.
1228- // See RP2040 datasheet Appendix B: Errata
1229- if (m == 511 || m == 1535 || m == 2559 || m == 3583 ) {
1230- continue ; // Discard single measurement
1231- // break; // Completely disregard this measurement entirely
1232- }
1233- sum += m;
1234- num++;
1200+ sum += analogRead (AIN_PIN);
12351201 }
12361202
12371203 resetSampleHold ();
12381204
1239- float avg = 0.0 ; // Use median instead of average?
1240-
1241- if (num > 0 ) {
1242- avg = float (sum) / float (num);
1243- }
1205+ float avg = float (sum) / float (conf.meas_avg );
1206+ ; // Use median instead of average?
12441207
12451208 if (current_baseline <= avg) { // Catch negative numbers
12461209 // Subtract DC bias from pulse avg and then convert float --> uint16_t ADC channel
12471210 mean = round (avg - current_baseline);
12481211 }
12491212 }
12501213
1251- if ((conf.ser_output || conf.enable_display || isRecording) && (conf. cps_correction || mean != 0 || conf. geiger_mode ) ) {
1214+ if ((conf.ser_output || conf.enable_display || isRecording)) {
12521215 events[event_position] = mean;
12531216 spectrum[mean] += 1 ;
12541217 display_spectrum[mean] += 1 ;
@@ -1305,12 +1268,14 @@ void eventInt() {
13051268 dead_time.add (end - start);
13061269 }
13071270
1271+
1272+ // NOTE: NOT SUPPORTED ON PICO 2 / RP2350
13081273 // Re-enable interrupts
1309- static uint32_t mask2 = 0b0100 << (INT_PIN % 8 ) * 4u ;
1310- hw_set_bits (addr, mask2);
1274+ // static uint32_t mask2 = 0b0100 << (INT_PIN % 8) * 4u;
1275+ // hw_set_bits(addr, mask2);
13111276
13121277 // Clear all interrupts on the executing core
1313- irq_clear (15 ); // IRQ 15 = SIO_IRQ_PROC0
1278+ // irq_clear(15); // IRQ 15 = SIO_IRQ_PROC0
13141279}
13151280
13161281/*
@@ -1369,7 +1334,6 @@ void setup1() {
13691334 { toggleBaseline, " set baseline" , " <toggle> Automatically subtract the DC bias (baseline) from each signal." },
13701335 { toggleTRNG, " set trng" , " <toggle> Either 'on' or 'off' to toggle the true random number generator output." },
13711336 { toggleDisplay, " set display" , " <toggle> Either 'on' or 'off' to enable or force disable OLED support." },
1372- { toggleCPSCorrection, " set correction" , " <toggle> Either 'on' or 'off' to toggle the CPS correction for the 4 faulty ADC channels." },
13731337 { setMode, " set mode" , " <mode> Either 'geiger' or 'energy' to disable or enable energy measurements. Geiger mode only counts pulses, but is a lot faster." },
13741338 { setSerialOutMode, " set out" , " <mode> Either 'events', 'spectrum' or 'off'. 'events' prints events as they arrive, 'spectrum' prints the accumulated histogram." },
13751339 { setMeasAveraging, " set averaging" , " <number> Number of ADC averages for each energy measurement. Takes ints, minimum is 1." },
0 commit comments