DIY Auto-Correlator 1.0
Auto-Correlator Card implementation using Teensy 4.x microcontrollers.
Lin_ACorr_RT_Teensy.hpp
Go to the documentation of this file.
1#pragma once
2
3
4#include "./../types.hpp"
6#ifdef CORR_SIMULATOR
7 #include "pseudoSerial.hpp"
8#else
9 #include <Arduino.h>
10#endif
11
15template <index_t Series_Size, bool hasMonitorChannel>
17{
18
19public:
20
22 //MonitorChannel<float_t, hasMonitorChannel> Monitor;
23
24 //MonitorChannel<hasMonitorChannel> Mean_monitor; //!< Mean monitor object
25 channel_t Channel_array[Series_Size] = {0};
27
29
30 //0
33 {
34 }
35
36 //1
38 void inline push_datum(counter_t datum)
39 {
40 Series_array.push_back(datum);
41
42 unsigned int LoopFor = (Series_index > Series_Size) ? Series_Size-1 : Series_index;
43 //LoopFor = (Series_index > Series_Size) * Series_Size +
44 // !(Series_index > Series_Size) * Series_index;
45
46 for(unsigned int i = 0; i <= LoopFor; i++)
47 {
48 //Channel_array[i] += (Series_array[Series_index] *
49 // Series_array[Series_index - i]);
50
51 Channel_array[i] += (datum * Series_array[Series_index - i]);
52 }
53
55 }
56
57
58 //2
60 void push_data(const counter_t *container, const index_t size) __attribute__((flatten))
61 {
62 for (int i = 0; i < size; i++)
63 {
64 push_datum(container[i]);
65 }
66 }
67
68
69 //3
72 float_t inline norm() {return 1;}
73
74
75 //4
77 void ch_out() const __attribute__((always_inline))
78 {
79 // ↓ Which is usually uint32_t.
80 Serial.write((char8cast_t*)&(Channel_array), sizeof(channel_t)*Series_Size);
81 }
82
83
84
85 //5
87 void ch_out_norm() const __attribute__((flatten))
88 {
89 // TODO - Try to unroll
90 for(unsigned int i = 0; i < Series_Size; i++)
91 {
92 Serial.write((char8cast_t*)&(float_t(Channel_array[i])/norm()), sizeof(float_t));
93 }
94 }
95
96
97 //6
99/* channel_t* get_ch_array()
100 {
101 return (Channel_array);
102 }*/
103
104};
This is an implementation of Lin_ACorr_RT_Base for Teensy with (No normalisation or baseline subtract...
Definition: Lin_ACorr_RT_Teensy.hpp:17
channel_t Channel_array[Series_Size]
Defines a run-time polymorphic MonitorChannel object, which decomposes to ghost channel (UnitMeanChan...
Definition: Lin_ACorr_RT_Teensy.hpp:25
void ch_out_norm() const __attribute__((flatten))
Outputs the channel array to the Serial port after normalising it.
Definition: Lin_ACorr_RT_Teensy.hpp:87
Simpler_Circular_Buffer< counter_t, Series_Size > Series_array
Stores the data points in a circular Buffer.
Definition: Lin_ACorr_RT_Teensy.hpp:26
void ch_out() const __attribute__((always_inline))
Outputs the complete channel to the Serial port.
Definition: Lin_ACorr_RT_Teensy.hpp:77
float_t norm()
Returns the accumulate of the channel so far.
Definition: Lin_ACorr_RT_Teensy.hpp:72
void push_datum(counter_t datum)
Adds new single data point and processes it to the Channel.
Definition: Lin_ACorr_RT_Teensy.hpp:38
index_t Series_index
Stores the last active index → Post-increment.
Definition: Lin_ACorr_RT_Teensy.hpp:28
void push_data(const counter_t *container, const index_t size) __attribute__((flatten))
Repeatedly calls push_datum() on the given container of values, one at a time.
Definition: Lin_ACorr_RT_Teensy.hpp:60
LinACorrRTTeensy()
Default Constructor.
Definition: Lin_ACorr_RT_Teensy.hpp:32
Definition: simpler_circular_buffer.hpp:6
uint32_t counter_t
Data type received from the pulse counter. It is the fundamental type used for representing series da...
Definition: types.hpp:7
uint_fast8_t index_t
It is used as the array indices and thus determine the maximum size of the Channel_array and the Seri...
Definition: types.hpp:10