#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer myTimer(GPT1);
//PeriodicTimer myTimer;
//IntervalTimer myTimer;
//#include "TeensyTimerTool.h"
//
//using namespace TeensyTimerTool;
//PeriodicTimer myTimer(GPT1);
//PeriodicTimer myTimer;
IntervalTimer myTimer;
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer myTimer(GPT1);
//PeriodicTimer myTimer;
//IntervalTimer myTimer;
unsigned char StreamData = 0;
unsigned long time1,time2,time3,time4 = 0;
unsigned char count = 0;
void TimerFunction()
{
time2 = micros();
Serial1.println(time2 - time1);
time1 = time2;
if(StreamData == 1)
{
Serial.println(count);
count++;
if(count >= 10)
{
count = 0;
}
}
}
void setup()
{
Serial1.begin(115200);
myTimer.begin(TimerFunction,1'000'000); // 1 Sec
}
void loop()
{
}
void serialEvent1()
{
char RxByte;
while(Serial1.available() > 0)
{
RxByte = Serial1.read();
Serial.write(RxByte);
if(RxByte == 'S')
{
Serial1.println("Started");
StreamData = 1;
}
else if(RxByte == 'E')
{
Serial1.println("Stopped");
StreamData = 0;
}
}
}
Sorry for that. The reason is that the TeensyTimerTool overrides the yield function which is also taking care of the SerialEvent stuff. I'll make that configurable and update the lib later today.
Exactly, thats the idea
That would be really great if we have options
#define YIELD_NONE 0 // Doesn't override yield at all, make sure to call TeensyTimerTool::Tick as often as possible
#define YIELD_STANDARD 1 // Uses the standard yield function and adds a call to TeensyTimerTool::Tick() lots of overhead in yield...
#define YIELD_OPTIMIZED 2 // Generate an optimized yield which only calls TeensyTimerTool::Tick()
#define YIELD_TYPE YIELD_OPTIMIZED // Select the required yield strategy here
I implemented the feature in version v0.1.4 on GitHub (should be available in the Arduino library manager in a couple of hours). You can find the complete config documentation here: https://github.com/luni64/TeensyTimerTool/wiki/Configuration
You can select between the following options (Standard: YIELD_OPTIMIZED)
Code:#define YIELD_NONE 0 // Doesn't override yield at all, make sure to call TeensyTimerTool::Tick as often as possible #define YIELD_STANDARD 1 // Uses the standard yield function and adds a call to TeensyTimerTool::Tick() lots of overhead in yield... #define YIELD_OPTIMIZED 2 // Generate an optimized yield which only calls TeensyTimerTool::Tick() #define YIELD_TYPE YIELD_OPTIMIZED // Select the required yield strategy here
- None: Doesn't touch the stock yield()
- Standard: Adds a call to tick() to the end of the stock yield() (lots of overhead, I suggest to use this only if you really use SerialEvents or the EventManager ...)
- Optimized: Replaces the stock yield by a yield which only calls the tick() function (default setting, same behaviour as before)
You can change the settings globally or in your project scope. For the project scope settings you need to do a clean build. If you feel insecure about that try the global setting first.
Hope that helps, let me know if you need support.
void TimerFunction()
{
time2 = micros();
Serial1.println(time2 - time1);
time1 = time2;
if(StreamData == 1)
{
Serial.println(count);
count++;
if(count >= 10)
{
count = 0;
}
}
yield();
}
I didn't understand the real use of yield/tick function.
No, don't do that. Here an example how to call tick manually, i.e., if you want to use YIELD_NONE and want to use the software timers (of course, if you don't use the software timers you don't have to tick the library).If I changed the settings to NONE then I need to call yield in timer function as well correct?
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer t1(TCK);
void isr()
{
Serial.printf("ISR called at t = %d ms\n", millis());
}
void setup()
{
t1.begin(isr, 100'000);
}
void loop()
{
TeensyTimerTool::tick();
}
PIT Timers
The TeensyTimerTool now also supports the PIT timers of the T4.0 boards. This might come in handy if you want to use the generic timer interface including one shot timers, the advanced capabilities of the callback system or the possibiltiy to easily switch to a 150MHz clock instead of the standard 24MHz clock. Other than this, there is no advantage to using the Teensyduino IntervalTimers.
Please note that the T4 boards only have one PIT module with 4 channels (The T3.x boards had 4 independent modules with 1 channel each). Thus, using the Teensy 4 PITs in the TeensyTimerTool will interfere with all Teensyduino Interval timers. Of course, if you don't declare a PIT timer it won't touch the standard Interval timers at all.
Is 0.1.6 the version which supports PIT timers?
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer t1(PIT);
OneShotTimer t2(PIT);
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
t1.begin([] {digitalWriteFast(LED_BUILTIN, HIGH); t2.trigger(25'000); }, 750'000);
t2.begin([] {digitalWriteFast(LED_BUILTIN, LOW); });
}
void loop()
{
}
IT IS BLINKING FINE! Had a make error breaking defines ...
I know... it is not a good idea to have too terse code in examples but this time I couldn't resist ).Hard to parse the "({,(;, …});" in p#139! Nice and functional - and compact and cryptic
T:\tCode\FORUM\TeTimer_CallBack\TeTimer_CallBack.ino Apr 9 2020 13:30:07
952003
1452003
1952003
2452003
2952003
3452003
…
99952003
100452003
100952003
101452003
101952003
t1.begin([] {digitalWriteFast(LED_BUILTIN, HIGH); t2.trigger(25000); }, [B][U]500000[/U][/B]);
t2.begin([] {digitalWriteFast(LED_BUILTIN, LOW); Serial.printf("%lu\n", [B][U]micros()[/U][/B]); });
PeriodicTimer t1(TCK);
OneShotTimer t2(TCK);
/*
* TeensyTimerTool --> 0.1.6
* timer library updated to 0.1.6
*/
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer myTimer(PIT);
//PeriodicTimer myTimer(GPT1);
//PeriodicTimer myTimer(TCK);
//PeriodicTimer myTimer;
//IntervalTimer myTimer;
unsigned char StreamData = 0;
unsigned long time1,time2,time3,time4 = 0;
unsigned char count = 0;
void TimerFunction2()
{
Serial1.println(micros() - time2);
if(StreamData == 1)
{
Serial.print(".");
}
time2 = micros();
}
void TimerFunction()
{
Serial1.println(micros() - time1);
if(StreamData == 1)
{
Serial.println(count);
count++;
if(count >= 10)
{
count = 0;
}
}
time1 = micros();
}
void setup()
{
Serial1.begin(115200);
myTimer.begin(TimerFunction,1'000'000); // 1 Sec
//myTimer2.begin(TimerFunction2,500'000); // 500 mSec
}
void loop()
{
//serial1Check();
delay(5000);
Serial.println(".");
}
void serialEvent1()
//void serial1Check()
{
char RxByte;
while(Serial1.available() > 0)
{
RxByte = Serial1.read();
Serial.write(RxByte);
if(RxByte == 'S')
{
Serial1.println("Started");
StreamData = 1;
}
else if(RxByte == 'E')
{
Serial1.println("Stopped");
StreamData = 0;
}
}
}
I was looking for the notes/examples on yield like : #define YIELD_TYPE YIELD_OPTIMIZED
Arrgh … now the docs are out of date :: luni64/TeensyTimerTool/wiki/Configuration
like :: #if defined(T4_0)
You may as well add for the future " #if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) " while you are working as Paul is adding in CORES and to the boards.txt and none of that will change with the same 1062 in use.
Sorry, I introduced a silly error in 0.1.6, should be fixed in v0.1.7. Can you give it a try?
-------------------------------
Sorted by pin number
Pin | GPIO Reg | PWM timer
----|------------|-------------
00 | GPIO6_03 | FLEX_PWM1
01 | GPIO6_02 | FLEX_PWM1
02 | GPIO9_04 | FLEX_PWM4
03 | GPIO9_05 | FLEX_PWM4
04 | GPIO9_06 | FLEX_PWM2
05 | GPIO9_08 | FLEX_PWM2
06 | GPIO7_10 | FLEX_PWM2
07 | GPIO7_17 | FLEX_PWM1
08 | GPIO7_16 | FLEX_PWM1
09 | GPIO7_11 | FLEX_PWM2
10 | GPIO7_00 | QUAD1
11 | GPIO7_02 | QUAD1
12 | GPIO7_01 | QUAD1
13 | GPIO7_03 | QUAD2
14 | GPIO6_18 | QUAD3
15 | GPIO6_19 | QUAD3
16 | GPIO6_23 | no pwm
17 | GPIO6_22 | no pwm
18 | GPIO6_17 | QUAD3
19 | GPIO6_16 | QUAD3
20 | GPIO6_26 | no pwm
21 | GPIO6_27 | no pwm
22 | GPIO6_24 | FLEX_PWM4
23 | GPIO6_25 | FLEX_PWM4
24 | GPIO6_12 | FLEX_PWM1
25 | GPIO6_13 | FLEX_PWM1
26 | GPIO6_30 | no pwm
27 | GPIO6_31 | no pwm
28 | GPIO8_18 | FLEX_PWM3
29 | GPIO9_31 | FLEX_PWM3
30 | GPIO8_23 | no pwm
31 | GPIO8_22 | no pwm
32 | GPIO7_12 | no pwm
33 | GPIO9_07 | FLEX_PWM2
34 | GPIO8_15 | FLEX_PWM1
35 | GPIO8_14 | FLEX_PWM1
36 | GPIO8_13 | FLEX_PWM1
37 | GPIO8_12 | FLEX_PWM1
38 | GPIO8_17 | FLEX_PWM1
39 | GPIO8_16 | FLEX_PWM1
-------------------------------
Sorted by PWM timer
Pin | GPIO Reg | PWM timer
----|------------|-------------
12 | GPIO7_01 | QUAD1
11 | GPIO7_02 | QUAD1
10 | GPIO7_00 | QUAD1
13 | GPIO7_03 | QUAD2
18 | GPIO6_17 | QUAD3
15 | GPIO6_19 | QUAD3
14 | GPIO6_18 | QUAD3
19 | GPIO6_16 | QUAD3
24 | GPIO6_12 | FLEX_PWM1
01 | GPIO6_02 | FLEX_PWM1
25 | GPIO6_13 | FLEX_PWM1
34 | GPIO8_15 | FLEX_PWM1
35 | GPIO8_14 | FLEX_PWM1
36 | GPIO8_13 | FLEX_PWM1
37 | GPIO8_12 | FLEX_PWM1
38 | GPIO8_17 | FLEX_PWM1
39 | GPIO8_16 | FLEX_PWM1
00 | GPIO6_03 | FLEX_PWM1
08 | GPIO7_16 | FLEX_PWM1
07 | GPIO7_17 | FLEX_PWM1
09 | GPIO7_11 | FLEX_PWM2
04 | GPIO9_06 | FLEX_PWM2
05 | GPIO9_08 | FLEX_PWM2
06 | GPIO7_10 | FLEX_PWM2
33 | GPIO9_07 | FLEX_PWM2
28 | GPIO8_18 | FLEX_PWM3
29 | GPIO9_31 | FLEX_PWM3
23 | GPIO6_25 | FLEX_PWM4
22 | GPIO6_24 | FLEX_PWM4
03 | GPIO9_05 | FLEX_PWM4
02 | GPIO9_04 | FLEX_PWM4
27 | GPIO6_31 | no pwm
17 | GPIO6_22 | no pwm
26 | GPIO6_30 | no pwm
30 | GPIO8_23 | no pwm
31 | GPIO8_22 | no pwm
32 | GPIO7_12 | no pwm
21 | GPIO6_27 | no pwm
20 | GPIO6_26 | no pwm
16 | GPIO6_23 | no pwm
-------------------------------
Sorted by GPIO register:
Pin | GPIO Reg | PWM timer
----|------------|-------------
01 | GPIO6_02 | FLEX_PWM1
00 | GPIO6_03 | FLEX_PWM1
24 | GPIO6_12 | FLEX_PWM1
25 | GPIO6_13 | FLEX_PWM1
19 | GPIO6_16 | QUAD3
18 | GPIO6_17 | QUAD3
14 | GPIO6_18 | QUAD3
15 | GPIO6_19 | QUAD3
17 | GPIO6_22 | no pwm
16 | GPIO6_23 | no pwm
22 | GPIO6_24 | FLEX_PWM4
23 | GPIO6_25 | FLEX_PWM4
20 | GPIO6_26 | no pwm
21 | GPIO6_27 | no pwm
26 | GPIO6_30 | no pwm
27 | GPIO6_31 | no pwm
10 | GPIO7_00 | QUAD1
12 | GPIO7_01 | QUAD1
11 | GPIO7_02 | QUAD1
13 | GPIO7_03 | QUAD2
06 | GPIO7_10 | FLEX_PWM2
09 | GPIO7_11 | FLEX_PWM2
32 | GPIO7_12 | no pwm
08 | GPIO7_16 | FLEX_PWM1
07 | GPIO7_17 | FLEX_PWM1
37 | GPIO8_12 | FLEX_PWM1
36 | GPIO8_13 | FLEX_PWM1
35 | GPIO8_14 | FLEX_PWM1
34 | GPIO8_15 | FLEX_PWM1
39 | GPIO8_16 | FLEX_PWM1
38 | GPIO8_17 | FLEX_PWM1
28 | GPIO8_18 | FLEX_PWM3
31 | GPIO8_22 | no pwm
30 | GPIO8_23 | no pwm
02 | GPIO9_04 | FLEX_PWM4
03 | GPIO9_05 | FLEX_PWM4
04 | GPIO9_06 | FLEX_PWM2
33 | GPIO9_07 | FLEX_PWM2
05 | GPIO9_08 | FLEX_PWM2
29 | GPIO9_31 | FLEX_PWM3