Maximum possible machine.Timer period
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Maximum possible machine.Timer period
With soft timers the rules for hardware interrupts don't apply: callbacks occur when the VM is idle. Using .schedule won't do any harm and will enable you to use a hardware timer without changing code.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Maximum possible machine.Timer period
That doesn't help him solve his problem.pythoncoder wrote: ↑Tue Sep 04, 2018 5:39 pmWith soft timers the rules for hardware interrupts don't apply: callbacks occur when the VM is idle. Using .schedule won't do any harm and will enable you to use a hardware timer without changing code.
Re: Maximum possible machine.Timer period
They occur when the bytecode is "jump" which is not the same as "idle".
Re: Maximum possible machine.Timer period
I looked in the C-source.neurino wrote: ↑Tue Sep 04, 2018 3:30 pmSorry, no debugger,
haven't anyone out there been able to reproduce the issue?
I mean someone with an ESP8266 ruing these few lines and seeing if he gets timer_cb called or not after 6 minutes (480000ms)
On my side, I started relying on a DS3231 alarm to trigger my hourly job, however getting this fixed would really help in other projects.Code: Select all
import machine import micropython def timer_cb(timer): print('here', timer) period = 480000 timer = machine.Timer(-1) timer.init(period=period, callback=lambda timer: micropython.schedule(timer_cb, timer), mode=machine.Timer.PERIODIC)
(1) a virtual timer isn't supported. Note how the code below doesn't care about your (-1).
Code: Select all
STATIC mp_obj_t esp_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
esp_timer_obj_t *tim = m_new_obj(esp_timer_obj_t);
tim->base.type = &esp_timer_type;
return tim;
}
Re: Maximum possible machine.Timer period
Hi. Was a maximum Period value found (It needs to be added to the documentation!)? I'm experiencing the same with the difference of using a hw timer. I started off with the equiv of 12 hours (callback function not called), and then 21610000 (~6 hours) with the same result. It works when I use a short period such as the equiv of a few minutes. Thanks
Re: Maximum possible machine.Timer period
Hi all
The MAXIMUM value is 6870947 (1:54:30.947). I tested and verified on uPython 1.9.4 ESP8266. >=6870948 does NOT work. (My source came from Lua: https://nodemcu.readthedocs.io/en/maste ... mer-module. Lua Timer (tmr.interval) initialises in a similar way to uPython.)
I wanted a 12 hour timer (~42610000).
What I'd like to know and understand is what is limiting it.
By my reading (and I'm not a C coder), "period" is defined as a 32bit integer. That makes the decimal number approx 4.3G, somewhat larger than necessary.
https://github.com/micropython/micropyt ... dmachine.c
STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {
ARG_mode,
ARG_callback,
ARG_period,
ARG_tick_hz,
ARG_freq,
};
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
{ MP_QSTR_tick_hz, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
So, perhaps there's a hardware limit somewhere, but I couldn't find anything about it at Espressif or their forums. Hopefully someone knows the significance of this hard limit, and is willing to explain.
Looking at the MicroPython C code for the ESP32 Timers, looks like the Timer Periods are 64 bit integers:
https://github.com/micropython/micropyt ... ne_timer.c
typedef struct _machine_timer_obj_t {
mp_obj_base_t base;
mp_uint_t group;
mp_uint_t index;
mp_uint_t repeat;
// ESP32 timers are 64-bit
uint64_t period;
mp_obj_t callback;
intr_handle_t handle;
Has anyone discovered a hard limit to the Timer Period on the ESP32?
Peter
The MAXIMUM value is 6870947 (1:54:30.947). I tested and verified on uPython 1.9.4 ESP8266. >=6870948 does NOT work. (My source came from Lua: https://nodemcu.readthedocs.io/en/maste ... mer-module. Lua Timer (tmr.interval) initialises in a similar way to uPython.)
I wanted a 12 hour timer (~42610000).
What I'd like to know and understand is what is limiting it.
By my reading (and I'm not a C coder), "period" is defined as a 32bit integer. That makes the decimal number approx 4.3G, somewhat larger than necessary.
https://github.com/micropython/micropyt ... dmachine.c
STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {
ARG_mode,
ARG_callback,
ARG_period,
ARG_tick_hz,
ARG_freq,
};
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
{ MP_QSTR_tick_hz, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
So, perhaps there's a hardware limit somewhere, but I couldn't find anything about it at Espressif or their forums. Hopefully someone knows the significance of this hard limit, and is willing to explain.
Looking at the MicroPython C code for the ESP32 Timers, looks like the Timer Periods are 64 bit integers:
https://github.com/micropython/micropyt ... ne_timer.c
typedef struct _machine_timer_obj_t {
mp_obj_base_t base;
mp_uint_t group;
mp_uint_t index;
mp_uint_t repeat;
// ESP32 timers are 64-bit
uint64_t period;
mp_obj_t callback;
intr_handle_t handle;
Has anyone discovered a hard limit to the Timer Period on the ESP32?
Peter
Re: Maximum possible machine.Timer period
I have faced this error too. I`m trying to set timer 4200000 ms (70 minutes), but it happens almost immediately after about 256 ms. As a try I changed the period to 42000 ms and I got proper behavior of the timer. What the reason of this malfunction?
I use STM32f411 plate.
I use STM32f411 plate.
Re: Maximum possible machine.Timer period
Some of the timers are 16-bit and some are 32-bit. If you try to store too large a value then it's probably getting truncated.
The documentation for the `period` field: https://docs.micropython.org/en/latest/ ... Timer.init shows which timers are 16-bit and which are 32-bit.
The documentation for the `period` field: https://docs.micropython.org/en/latest/ ... Timer.init shows which timers are 16-bit and which are 32-bit.