6template <
unsigned int ChID>
21{
static_assert(ChID <=3,
"No such PIT channel exists!"); }
38 PIT_MCR ^= PIT_MCR_FRZ;
43 void start() __attribute__((always_inline))
45 IMXRT_PIT_CHANNELS[ChID].TCTRL |= PIT_TCTRL_TEN;
49 void stop() __attribute__((always_inline))
51 IMXRT_PIT_CHANNELS[ChID].TCTRL &= ~PIT_TCTRL_TEN;
60 double ldval_ = gt_microseconds * this->Clk_freq * 1e-6;
61 uint32_t ldval = ceil(ldval_);
63 this->Req_period = gt_microseconds;
68 IMXRT_PIT_CHANNELS[ChID].LDVAL =
LoadVal;
69 this->Actual_period = ((this->LoadVal+1) * this->
tick_period_us());
77 IMXRT_PIT_CHANNELS[ChID].LDVAL =
LoadVal;
78 this->Actual_period = ((this->LoadVal+1) * this->
tick_period_us());
84 this->LoadVal = uint32_t((ldval)) - 1;
85 IMXRT_PIT_CHANNELS[ChID].LDVAL =
LoadVal;
86 this->Actual_period = ((this->LoadVal+1) * this->
tick_period_us());
95 return (this->Req_period - this->Actual_period);
101 return 1e6 / double(this->Clk_freq);
126 IMXRT_PIT_CHANNELS[ChID].TCTRL |= PIT_TCTRL_TIE;
132 IMXRT_PIT_CHANNELS[ChID].TCTRL &= ~PIT_TCTRL_TIE;
140 NVIC_ENABLE_IRQ(IRQ_PIT);
141 NVIC_SET_PRIORITY(IRQ_PIT, priority);
142 attachInterruptVector(IRQ_PIT,
isr_fn);
148 IMXRT_PIT_CHANNELS[ChID].TFLG = 1;
156 CCM_CSCMR1 &= ~CCM_CSCMR1_PERCLK_CLK_SEL;
164 CCM_CSCMR1 |= CCM_CSCMR1_PERCLK_CLK_SEL;
165 this->Clk_freq = uint32_t(24*1e6);
Interface for PIT timers on Teensy 4.x microcontrollers.
Definition: pit.hpp:8
static void pause_resume_PITs() __attribute__((always_inline))
Pause/Resume - Toggle all PIT Channels.
Definition: pit.hpp:36
double tick_period_us() __attribute__((always_inline))
Returns the value of one Tick - Minimum resolution of the timer.
Definition: pit.hpp:99
double period_error_us() const __attribute__((always_inline))
Returns the error in the gate timing period due to the finite resolution of the timers....
Definition: pit.hpp:93
void start() __attribute__((always_inline))
Start counting on the timer.
Definition: pit.hpp:43
double Actual_period
Actual Time Period set by the device due to finite resolution.
Definition: pit.hpp:13
void stop() __attribute__((always_inline))
stop counting on the timer.
Definition: pit.hpp:49
static void disable_PITs() __attribute__((always_inline))
Disable all PIT Channels.
Definition: pit.hpp:30
void sel_FBUS_clock() __attribute__((always_inline))
Sets the clock source frequency of all PIT channels to the value F_BUS_ACTUAL (= F_CPU_ACTUAL / 4 ) w...
Definition: pit.hpp:154
void no_interrupt() __attribute__((always_inline))
Disable Interrupts that are triggered after one gate time completion.
Definition: pit.hpp:130
unsigned static int get_xbar_in_pin() __attribute__((always_inline))
Returns the correspoding XBAR1-A Input Pins for the corresponding channel TRIGGER signal.
Definition: pit.hpp:108
double Req_period
Time Period requested by the user.
Definition: pit.hpp:14
static constexpr const uint32_t PIT_MAX_COUNTER
Constant - Maximum possible counter value. 32 bit counter.
Definition: pit.hpp:18
static void enable_PITs() __attribute__((always_inline))
Enable all PIT channels.
Definition: pit.hpp:24
static void set_interrupt(void(*isr_fn)(), unsigned int priority) __attribute__((always_inline))
Sets a common ISR and its priority for all PIT Channels.
Definition: pit.hpp:137
Error_t set_gate_time(double gt_microseconds) __attribute__((flatten))
Sets the gate time after which the counter returns to zero and marks the end of onegate interval.
Definition: pit.hpp:58
uint32_t LoadVal
The value loaded in to the counter during after overflow.
Definition: pit.hpp:17
PITController()
Definition: pit.hpp:20
void sel_24MHz_clock() __attribute__((always_inline))
Sets the source clock frequency of all PIT channels to 24 MHz which is the default oscillator clock....
Definition: pit.hpp:162
uint32_t Clk_freq
Clock frequency used by the timer. Initalized to 24MHz → default oscillator clock.
Definition: pit.hpp:16
void clear_interrupt_flag() __attribute__((always_inline))
Clears the interrupt flag and hence prepares the timer for the next gate interval....
Definition: pit.hpp:146
void interrupt() __attribute__((always_inline))
Enable Interruptsthat are triggered after one gate time completion.
Definition: pit.hpp:124
Error_t
Enumarates the error codes thrown by the different modules.
Definition: errors.hpp:17
@ Counter_Underflow
Passed Value caused a counter underflow.
@ Counter_Overflow
Passed Value caused a counter overflow.
void isr_fn()
ISR function used for processing counter values.
Definition: featureline1.hpp:31