DIY Auto-Correlator 1.0
Auto-Correlator Card implementation using Teensy 4.x microcontrollers.
interarrival.hpp
Go to the documentation of this file.
1#pragma once
2#include <type_traits>
3#include "./../software/monitor_channel.hpp"
4
5
6#define INTERARRIVALTIME_MINMAX_STATISTICS 0
7template <typename CounterType, typename CPUTickType>
9{
10private:
11 CounterType get_counter() __attribute__((always_inline))
12 {
13 return Cntr;
14 }
15
16public:
17 CounterType* Cntr;
18 CounterType CountDiff = 0;
19 CounterType LastCntr = 0;
20 CounterType Now = 0;
22
23 #if INTERARRIVALTIME_MINMAX_STATISTICS == 1
24 CounterType Max = 0;
25 CounterType Min = 100;
26 #endif
27
28
31 constexpr InterArrivalTime(const CounterType* cntr_location): Cntr(cntr_location)
32 {
33 static_assert(std::is_unsigned<CounterType>::value, "The CounterType must be an unsigned integer type.");
34
35 }
36
39 void measure() __attribute__((flatten))
40 {
41
42 Now = get_counter();
44
45 if(CountDiff > 0)
46 {
48
49 #if INTERARRIVALTIME_MINMAX_STATISTICS == 1
50 //if(CountDiff < Min && CountDiff != 0) {Min = CountDiff;}
51 //if (CountDiff > Max) {Max = CountDiff;}
52 #endif
53
54 LastCntr = Now;
55 }
56 }
57
59 void output() __attribute__((always_inline))
60 {
61 float_t mean = Mean.mean();
62 Serial.write((uint8_t*)&(mean), sizeof(float_t));
63 //Serial.send_now();
64
65 #if INTERARRIVALTIME_MINMAX_STATISTICS == 1
66 //Serial.write((uint8_t*)&(Min), constexpr sizeof(CounterType));
67 //Serial.write((uint8_t*)&(Max), constexpr sizeof(CounterType));
68 #endif
69 }
70};
Definition: interarrival.hpp:9
MonitorChannel< true > Mean
Mean Inter-arrival time.
Definition: interarrival.hpp:21
constexpr InterArrivalTime(const CounterType *cntr_location)
Constructor that accepts the counter location, that it frequently samples. It only accepts unsigned i...
Definition: interarrival.hpp:31
void measure() __attribute__((flatten))
Measures the difference between two observable counts. If the mean is closer to 1,...
Definition: interarrival.hpp:39
CounterType get_counter() __attribute__((always_inline))
Definition: interarrival.hpp:11
CounterType * Cntr
Saves the address of the counter location.
Definition: interarrival.hpp:17
void output() __attribute__((always_inline))
Outputs the calculated statistics as a binary struct.
Definition: interarrival.hpp:59
CounterType LastCntr
Last Counter value recorded.
Definition: interarrival.hpp:19
CounterType Now
Current Counter value storage.
Definition: interarrival.hpp:20
CounterType CountDiff
The difference between the arrival time of last two photons.
Definition: interarrival.hpp:18
Template specialization.
Definition: monitor_channel.hpp:14
void push_back(DataType data)
Adds datum to the channel.
Definition: monitor_channel.hpp:23
float_t mean() const __attribute__((always_inline))
Returns the estimated mean.
Definition: monitor_channel.hpp:31