Hello
I'm struggling with the ESP32 and so far the MCU is winning. I want to use Flowcode's Timer Component Macro, but it doesn't return a value, I only read 0 from it with the TIMER_0 hardware timer. If I use other hardware timers (TIMER_1, TIMER_2, TIMER_3) in the component macro, the program keeps restarting. In the attached program, I wanted to measure the time elapsed between state changes of pin 36 in x10ms resolution.
Am I doing something wrong or is this a bug?
Regards,
Sasi
"Timer" Component Makro Problem
-
- Posts: 107
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 12:11 pm
- Has thanked: 37 times
- Been thanked: 14 times
Re: "Timer" Component Makro Problem
Hello,
I would like to ask if I can expect an answer on this topic in the near future.
I want to solve a university competition task with Flowcode, but now I'm stuck here and the deadline is approaching.
If this program bug and it takes longer to solve the "Timer" Component problem, that would be useful information for me.
If I did something wrong and that's why it doesn't work, I want to know that too.
Thank you in advance for your answers,
Sasi
I would like to ask if I can expect an answer on this topic in the near future.
I want to solve a university competition task with Flowcode, but now I'm stuck here and the deadline is approaching.
If this program bug and it takes longer to solve the "Timer" Component problem, that would be useful information for me.
If I did something wrong and that's why it doesn't work, I want to know that too.
Thank you in advance for your answers,
Sasi
-
- Valued Contributor
- Posts: 456
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 82 times
- Been thanked: 244 times
Re: "Timer" Component Makro Problem
Hi
It looks like the Timer component might not be compatible with ESP32.
You might have more success using a Timer Interrupt instead.
e.g. use that to increment a counter at say 1mS intervals.
Also see this post ...
viewtopic.php?p=16064#p16064
It looks like the Timer component might not be compatible with ESP32.
You might have more success using a Timer Interrupt instead.
e.g. use that to increment a counter at say 1mS intervals.
Also see this post ...
viewtopic.php?p=16064#p16064
-
- Valued Contributor
- Posts: 1514
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 138 times
- Been thanked: 725 times
Re: "Timer" Component Makro Problem
Hi Sasi,
While not wanting to do your Uni work for you (unless we share the prize?)
A few pointers:
Your code will crash every few seconds - the WDT will timeout and reset the MCU - you need to have a delay in the loop to allow the RTOS to handle the co-operative multitasking (and there are other tasks running) This needs to be ~50ms and means this 'loop timing' method probably won't work easily.
It's a good idea to open a COM port (using PuTTY or other terminal program) - and lots of errors like this are indicated to the user..
One technique would be to have an interrupt on pin change (though beware of bounce if it's a switch) combined with:
You could create your own timer - using a timer interrupt running every 1ms (or other time span) and incrementing a 'time' variable.
You are currently attempting to write 'pulses' to your display on every loop - this is probably not a good idea - just write it if has changed?
You don't start the timer - first 'query' it isn't running..
Having said which - a simple test with the Timer component does seem to just return 0 (I tried ms) - so there is maybe a bug in there too?
Martin
While not wanting to do your Uni work for you (unless we share the prize?)
A few pointers:
Your code will crash every few seconds - the WDT will timeout and reset the MCU - you need to have a delay in the loop to allow the RTOS to handle the co-operative multitasking (and there are other tasks running) This needs to be ~50ms and means this 'loop timing' method probably won't work easily.
It's a good idea to open a COM port (using PuTTY or other terminal program) - and lots of errors like this are indicated to the user..
One technique would be to have an interrupt on pin change (though beware of bounce if it's a switch) combined with:
You could create your own timer - using a timer interrupt running every 1ms (or other time span) and incrementing a 'time' variable.
You are currently attempting to write 'pulses' to your display on every loop - this is probably not a good idea - just write it if has changed?
You don't start the timer - first 'query' it isn't running..
Having said which - a simple test with the Timer component does seem to just return 0 (I tried ms) - so there is maybe a bug in there too?
Martin
Re: "Timer" Component Makro Problem
Hi Leigh and Martin
Thank you very much for the tips and ideas.
I created the attached program for testing purposes only.
I don't think this component macro currently works with ESP32 MCU. Although probably tested with ESP32 before: In the project, the speed control of 2 motors must be solved with a PID controller. The rotation sensors are connected to the interrupt inputs and currently the program reads the counted pulses every 50ms for feedback. When the motor is rotating at full speed, the rotation sensor sends 19 pulses in 50 ms.
The rotation is uneven at low speed, as the rotation sensor rarely sends pulses and large jumps in value can follow one another at the feedback input.
So for finer control I wanted to measure the period time between pulses for the feedback.
If you have any ideas on how to fine-tune the motor, please share them with me.
Martin,
Thanks for the help.
We will surely engrave your name on the cup if we win the competition.
Regards,
Sasi
Thank you very much for the tips and ideas.
I created the attached program for testing purposes only.
I don't think this component macro currently works with ESP32 MCU. Although probably tested with ESP32 before: In the project, the speed control of 2 motors must be solved with a PID controller. The rotation sensors are connected to the interrupt inputs and currently the program reads the counted pulses every 50ms for feedback. When the motor is rotating at full speed, the rotation sensor sends 19 pulses in 50 ms.
The rotation is uneven at low speed, as the rotation sensor rarely sends pulses and large jumps in value can follow one another at the feedback input.
So for finer control I wanted to measure the period time between pulses for the feedback.
If you have any ideas on how to fine-tune the motor, please share them with me.
Martin,
Thanks for the help.
We will surely engrave your name on the cup if we win the competition.

Regards,
Sasi
-
- Valued Contributor
- Posts: 1514
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 138 times
- Been thanked: 725 times
Re: "Timer" Component Makro Problem
There are several options:
1) Count encoder pulses over a set period (so say 20 pulses over 1s -> pulse-time is 1000/20 ms).
Interrupt on rising pin (for each pin)
Clear counters
Wait 1s
Obviously you could wait for a different time period - and if you want to be fancy you could move the 'counts' to a seperate task (search for xTaskCreate)
Note that both pins are measured at the same time,
2) Measure individual pulses.
Set a timer interrupt to increment a counter (every 100us perhaps)
On each pin interrupt add timer counter to time - and average over a number of pulses.
3) Use the RMT hardware to measure the pulses
Adjust the motor and repeat ..
1) Count encoder pulses over a set period (so say 20 pulses over 1s -> pulse-time is 1000/20 ms).
Interrupt on rising pin (for each pin)
Clear counters
Wait 1s
Obviously you could wait for a different time period - and if you want to be fancy you could move the 'counts' to a seperate task (search for xTaskCreate)
Note that both pins are measured at the same time,
2) Measure individual pulses.
Set a timer interrupt to increment a counter (every 100us perhaps)
On each pin interrupt add timer counter to time - and average over a number of pulses.
3) Use the RMT hardware to measure the pulses
Adjust the motor and repeat ..
-
- Matrix Staff
- Posts: 1936
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 506 times
- Been thanked: 688 times
Re: "Timer" Component Makro Problem
Hello,
The timer and timed interval component should now work correctly with ESP32 hardware. Just be sure to use the latest library updates.
The timer and timed interval component should now work correctly with ESP32 hardware. Just be sure to use the latest library updates.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 1012
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 193 times
- Been thanked: 217 times
Re: "Timer" Component Makro Problem
Hi to All
With an interrupt I sample with 50miliseconds.
I used the timer to test if my logger sample with 20Hz (0.05 sec)
The recording was about 1 minute. The timer shows a a time of 0.1second and a total time of 118 seconds!
But I get 1185 samples in 1 minutes. So I divided in excel the timer value by 2 and then it look very good.
would it be possible for the timer to run twice as fast as it should?
regards
Stefan
Excel result:
interrupt in the programm;
With an interrupt I sample with 50miliseconds.
I used the timer to test if my logger sample with 20Hz (0.05 sec)
The recording was about 1 minute. The timer shows a a time of 0.1second and a total time of 118 seconds!
But I get 1185 samples in 1 minutes. So I divided in excel the timer value by 2 and then it look very good.
would it be possible for the timer to run twice as fast as it should?
regards
Stefan
Excel result:
interrupt in the programm;
-
- Valued Contributor
- Posts: 1012
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 193 times
- Been thanked: 217 times
Re: "Timer" Component Makro Problem
Hi to All
I tested all the tree timer.
That the time varies a little is not a problem but that sometimes the time is twice as long and that timer 3 sometimes works great but with the other two timer together, the timer 3 does not work I set them in my sample macro so they should test the time between samples.
The correct time is 0.05 sec First I tested each timer (turned off the another two):
Then I tested timer 1 and timer 2 together:
and then all tree timer together:
I tested all the tree timer.
That the time varies a little is not a problem but that sometimes the time is twice as long and that timer 3 sometimes works great but with the other two timer together, the timer 3 does not work I set them in my sample macro so they should test the time between samples.
The correct time is 0.05 sec First I tested each timer (turned off the another two):
Then I tested timer 1 and timer 2 together:
and then all tree timer together:
-
- Valued Contributor
- Posts: 1012
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 193 times
- Been thanked: 217 times
Re: "Timer" Component Makro Problem
Hi to All
On my recoder I connected with USB C and Instead of the desired data, I have continuously received these characters.
Only when I took all 3 timers out of my programme did USB work again.
On my recoder I connected with USB C and Instead of the desired data, I have continuously received these characters.
Only when I took all 3 timers out of my programme did USB work again.
ëÿ=ÿ<17><16>}<\0>éÿõÿ×<\0>ëÿ¸þ:<\b>ƒÿšÿÄ<15>n<\0>ä<\0>”<\0>¡<4><1><2>‚þž<\b><27>[0;31mE (33502) gptimer: gptimer_register_to_group(136): no free timer<27>[0m<\r><\n>
<27>[0;31mE (33502) gptimer: gptimer_new_timer(183): register timer failed<27>[0m<\r><\n>
<27>[0;31mE (33502) gptimer: gptimer_register_event_callbacks(260): invalid argument<27>[0m<\r><\n>
<27>[0;31mE (33512) gptimer: gptimer_enable(330): invalid argument<27>[0m<\r><\n>
<27>[0;31mE (33512) gptimer: gptimer_set_alarm_action(299): invalid argument<27>[0m<\r><\n>
<27>[0;31mE (33512) gptimer: gptimer_start(370): invalid argument<27>[0m<\r><\n>