Hi there
For the last few weeks I've been trying to find a good timer tutorial for my project.
I'm not going to use the "IntervalTimer" library because I need a more frequent interrupt call and I am as efficient as possible.
My goal with the Timer is:
- Creating a I2C bus which may be faster than the standard Wire library.
- Building a Special I2C parallel bus which can send data to multiple slaves at the same time:
Signals:
SCL ------> SCL slave1, slave2, slaveX
SDA1 -----> SDA slave1
SDA2 -----> SDA slave2
SDAX -----> SDA slaveX
Slaves are: 3x TLC59116 (LED Driver with 16 pwm outputs)
I currently use 3 slaves and my bus is working fine (most of the time) -> sometimes the Teensy crashes because the timer works so fast I think.
The crash won't occure on slower Timer interval settings.
I currently have a Timer working. I copied it from a forum post but I don't know how the setup works.
Current used Timer:
The question now is, is there a simple methode like descibed here?: https://www.pjrc.com/teensy/interrupts.html
With these timers I found a example code but it won't compile because stuff is not defined:
Is the first code realy the right way of using Timers on a Teensy 4.1?
Like I described above, my teensy crashes from time to time. Especialy when I recieve data over the serial Interface (BAUD = 115200).
The crashes occures only then when I don't send data to my slaves.
I have seen this with my logic analyzer.
So I thougth, its May be possible to disable/enable a timer.
So I can enable the Timer only then, when I need to send Data and disable it after the transmission.
Currently I check at first in the Interrupt, if any data is in the sending buffer and if not, return the ISR.
This is fast but it does need CPU time which can be eliminated with this disable/enable thing.
I was wondering if anyone of you can explain to me how exactly I need to use this low level timers?
I know there shuld be 4 of them available, are the setups of other timers equal/logical in naming of the registers? e.g. TMR1_CSCTRL0 (countervalue for timer 1) and TMR2_CSCTRL0 (for timer 2)?
What are all these Registers doing and how do I implement these the right way?
Is this enable/disable thing possible?
Is it possible to disable the timer 1 in the ISR of the timer 1 it self? e.g if transmission is finished, the ISR can turn the Timer off.
Why is the timer (IRQ_QTIMER1), from the first code example which is currently working, not in the Table?
Is this Page only for other Teensies?
Is dere a Page for the Teensy 4.1 Interrupt stuff?
Why is there not many Tutorials out there for this Timer interrupt stuff? =)
Thanks a lot for helping me =)
For the last few weeks I've been trying to find a good timer tutorial for my project.
I'm not going to use the "IntervalTimer" library because I need a more frequent interrupt call and I am as efficient as possible.
My goal with the Timer is:
- Creating a I2C bus which may be faster than the standard Wire library.
- Building a Special I2C parallel bus which can send data to multiple slaves at the same time:
Signals:
SCL ------> SCL slave1, slave2, slaveX
SDA1 -----> SDA slave1
SDA2 -----> SDA slave2
SDAX -----> SDA slaveX
Slaves are: 3x TLC59116 (LED Driver with 16 pwm outputs)
I currently use 3 slaves and my bus is working fine (most of the time) -> sometimes the Teensy crashes because the timer works so fast I think.
The crash won't occure on slower Timer interval settings.
I currently have a Timer working. I copied it from a forum post but I don't know how the setup works.
Current used Timer:
Code:
void interruptFunc();
void setup()
{
... // other stuff
attachInterruptVector(IRQ_QTIMER1, interruptFunc); // Arrach interrupt to my ISR function "interruptFunc"
CCM_CCGR6 |= CCM_CCGR6_QTIMER1(CCM_CCGR_ON); //don't know
TMR1_CTRL0 = 0x0000; // stop (don't know)
TMR1_LOAD0 = 0x0000; // start val after compare (don't know)
TMR1_COMP10 = 100; // count up to this val, interrupt, and start again
TMR1_CMPLD10 = 100; // (don't know) (Equal to TMR1_COMP10 ?)
TMR1_CTRL0 = TMR_CTRL_CM(1) | TMR_CTRL_PCS(8) | TMR_CTRL_LENGTH ; // prescale (don't know how this prescaler works)
TMR1_CSCTRL0 & = ~(TMR_CSCTRL_TCF1); // clears the counter, I think ^^
TMR1_CSCTRL0 |= TMR_CSCTRL_TCF1EN; // enable interrupt or so
NVIC_ENABLE_IRQ(IRQ_QTIMER1); // (don't know)
... // other stuff
}
void interruptFunc()
{
// Highspeed I2C-parallelBus which currently works at 2Mhz clk
// This Interrupt is executet at around 100ns interval
...
}
The question now is, is there a simple methode like descibed here?: https://www.pjrc.com/teensy/interrupts.html
With these timers I found a example code but it won't compile because stuff is not defined:
Code:
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define OVERFLOW_INTERRUPT_ENABLE (TIMSK0 |= (1<<TOIE0))
volatile bool value = 0;
ISR(TIMER0_OVF_vect) {
// Toggle Pin 10
if(value)
GPIO7_DR |= uint32_t(1<<CORE_PIN10_BIT); // Set Pin 10 = 1
else
GPIO7_DR &= ~uint32_t(1<<CORE_PIN10_BIT); // Set Pin 10 = 0
value = !value;
}
void setup()
{
cli();
pinMode(10,OUTPUT);
CPU_PRESCALE(0);
OVERFLOW_INTERRUPT_ENABLE;
sei(); //enable global interupts
}
void loop()
{
for(;;) {
delay(10);
}
}
Is the first code realy the right way of using Timers on a Teensy 4.1?
Like I described above, my teensy crashes from time to time. Especialy when I recieve data over the serial Interface (BAUD = 115200).
The crashes occures only then when I don't send data to my slaves.
I have seen this with my logic analyzer.
So I thougth, its May be possible to disable/enable a timer.
So I can enable the Timer only then, when I need to send Data and disable it after the transmission.
Currently I check at first in the Interrupt, if any data is in the sending buffer and if not, return the ISR.
This is fast but it does need CPU time which can be eliminated with this disable/enable thing.
I was wondering if anyone of you can explain to me how exactly I need to use this low level timers?
I know there shuld be 4 of them available, are the setups of other timers equal/logical in naming of the registers? e.g. TMR1_CSCTRL0 (countervalue for timer 1) and TMR2_CSCTRL0 (for timer 2)?
What are all these Registers doing and how do I implement these the right way?
Is this enable/disable thing possible?
Is it possible to disable the timer 1 in the ISR of the timer 1 it self? e.g if transmission is finished, the ISR can turn the Timer off.
Why is the timer (IRQ_QTIMER1), from the first code example which is currently working, not in the Table?
Is this Page only for other Teensies?
Is dere a Page for the Teensy 4.1 Interrupt stuff?
Why is there not many Tutorials out there for this Timer interrupt stuff? =)
Thanks a lot for helping me =)