GP_timer not working properly

Baldhead
Posts: 468
Joined: Sun Mar 31, 2019 5:16 am

Re: GP_timer not working properly

Postby Baldhead » Tue Oct 22, 2024 11:40 pm

Hi @MicroController,

I did some modifications in my code and all is working ok, but the message:
"E (669) gptimer: gptimer_start(399): timer is not enabled yet"
in idf monitor now appears, all the time i call "gptimer_start(timer_handle)".
I called "gptimer_enable(timer_handle);" at gp_timer initialization.

Little piece of my state machine code inside isr:

Code: Select all

    gptimer_set_raw_count(timer_handle, 0);           
                        
    static gptimer_alarm_config_t gptimer_alarm;
    gptimer_alarm.alarm_count = 4167;  // this value can change at run time 
    gptimer_alarm.flags.auto_reload_on_alarm = false;            
    gptimer_set_alarm_action(timer_handle, &gptimer_alarm);

    gptimer_start(timer_handle);  // Start GPTimer (internal counter starts counting).
I put static in "gptimer_alarm_config_t" because in documentation say that:

Code: Select all

If CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is enabled, this function will be placed in the IRAM by linker, makes it possible to execute even when the Flash Cache is disabled. In this case, please also ensure the gptimer_alarm_config_t instance is placed in the static data section instead of in the read-only data section. e.g.: static gptimer_alarm_config_t alarm_config = { ... };
I enabled CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM.
I tried removing static, just to test, but nothing changed in relation to this problem.

Some suggestion on why this message( "E (669) gptimer: gptimer_start(399): timer is not enabled yet" ) is appearing ?

Baldhead
Posts: 468
Joined: Sun Mar 31, 2019 5:16 am

Re: GP_timer not working properly

Postby Baldhead » Wed Oct 23, 2024 7:04 pm

@MicroController,

There is some order to set gptimer_set_alarm_action inside isr ?

I need do disable or stop the timer first ?

And then reenable or start the timer.

Thank's.

Baldhead
Posts: 468
Joined: Sun Mar 31, 2019 5:16 am

Re: GP_timer not working properly

Postby Baldhead » Wed Oct 23, 2024 7:37 pm

Baldhead wrote:
Wed Oct 23, 2024 7:04 pm
@MicroController,

There is some order to set gptimer_set_alarm_action inside isr ?

I need do disable or stop the timer first ?

And then reenable or start the timer.

Thank's.
I tried here, but without success.

Baldhead
Posts: 468
Joined: Sun Mar 31, 2019 5:16 am

Re: GP_timer not working properly

Postby Baldhead » Wed Oct 23, 2024 10:02 pm


MicroController
Posts: 1724
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: GP_timer not working properly

Postby MicroController » Thu Oct 24, 2024 7:16 pm

As per the docs gptimer_set_alarm_action() is not allowed to be used in an ISR.
How about initially (once) setting up the alarm to some high value, like 1000000, and then only adjust the count value appropriately? Like

Code: Select all

static const uint32_t ALARM_VALUE = 1000000;

static void isr() {
  ...
  gp_timer_stop(timer_handle);
  gptimer_set_raw_count(timer_handle, ALARM_VALUE - ticksUntilNextAlarm);
  gp_timer_start(timer_handle);
  ...
}
Or, even more simple, set the alarm value to 0 and let the GPTIMER_COUNT_DOWN.

Baldhead
Posts: 468
Joined: Sun Mar 31, 2019 5:16 am

Re: GP_timer not working properly

Postby Baldhead » Fri Oct 25, 2024 2:45 am

MicroController wrote:
Thu Oct 24, 2024 7:16 pm
As per the docs gptimer_set_alarm_action() is not allowed to be used in an ISR.
How about initially (once) setting up the alarm to some high value, like 1000000, and then only adjust the count value appropriately? Like

Code: Select all

static const uint32_t ALARM_VALUE = 1000000;

static void isr() {
  ...
  gp_timer_stop(timer_handle);
  gptimer_set_raw_count(timer_handle, ALARM_VALUE - ticksUntilNextAlarm);
  gp_timer_start(timer_handle);
  ...
}
Or, even more simple, set the alarm value to 0 and let the GPTIMER_COUNT_DOWN.
Hi @MicroController,

In documentation here: https://docs.espressif.com/projects/esp ... m_config_t,
says that it is allowed to use this function within ISR.

I actually have another problem now.
I need that the rising edge interrupt and gptimer interrupt have the highest isr priority within the system, because i am having problem with the system not responding in time.

I'm thinking I'll have to use some hardware module to do this, maybe mcpwm or rmt or whatever.

I need to control 3 triacs at the same time.

Some sugestion ?

Thank's.
Last edited by Baldhead on Fri Oct 25, 2024 6:29 pm, edited 1 time in total.

User avatar
ok-home
Posts: 78
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: GP_timer not working properly

Postby ok-home » Fri Oct 25, 2024 3:33 am


MicroController
Posts: 1724
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: GP_timer not working properly

Postby MicroController » Fri Oct 25, 2024 7:17 am

Baldhead wrote:
Fri Oct 25, 2024 2:45 am
I need that the rising edge interrupt and gptimer interrupt have the high highest isr priority within the system
Interrupt priority is almost never the problem or solution in these cases.
I'm thinking I'll have to use some hardware module to do this, maybe mcpwm or rmt or whatever.

I need to control 3 triacs at the same time.
Using hardware when possible is the best option.
What response times do you need?

Baldhead
Posts: 468
Joined: Sun Mar 31, 2019 5:16 am

Re: GP_timer not working properly

Postby Baldhead » Fri Oct 25, 2024 5:01 pm

MicroController wrote:
Fri Oct 25, 2024 7:17 am
Baldhead wrote:
Fri Oct 25, 2024 2:45 am
I need that the rising edge interrupt and gptimer interrupt have the high highest isr priority within the system
Interrupt priority is almost never the problem or solution in these cases.
I'm thinking I'll have to use some hardware module to do this, maybe mcpwm or rmt or whatever.

I need to control 3 triacs at the same time.
Using hardware when possible is the best option.
What response times do you need?
Hi @MicroController,

i am using wifi, https server, lcd and so on.

The gp_timer is "noisy" ie, the pulse width keeps changing when other things are happening behind the scenes, i think
its the problem, that the timer "task group" and timer isr and maybe the rising edge interrupt is not processed in the appropriate time.

And for now i'm only testing with one triac, ie, only one gp_timer is registered and working.

Video to show you:
https://youtu.be/g3YADEUWFwo

The yellow signal is an external to esp32-s3 sync signal and the blue signal is the output signal using gp_timer.

*************************************
Same signal here:
http://esp32.io/viewtopic.php?f=12&t=42 ... c3f2c56fb1

The yellow signal is an external to esp32-s3 sync signal and the blue signal is an i/o output when rising edge isr occurs.
Last edited by Baldhead on Fri Oct 25, 2024 8:34 pm, edited 3 times in total.

Baldhead
Posts: 468
Joined: Sun Mar 31, 2019 5:16 am

Re: GP_timer not working properly

Postby Baldhead » Fri Oct 25, 2024 5:27 pm


Who is online

Users browsing this forum: No registered users and 188 guests