STM32F405RG Hardware timer period to 6h
STM32F405RG Hardware timer period to 6h
Hello,
Im using a STM32F405RG board from Aliexpress.
I set up a hardware timer with a callback function in the REPL.
And it works for timer.freq(1) to run the callback function every second.
But I need a callback every six hours.
If I call timer.freq(1/(60*60*6)), it sets the freq:=0 and manipulates the period and the prescaler, not to a total of 6h, but to a few second.
When I try to change the freq via timer.init( prescaler=168000000, period=6*60*60), it also doesn't take my values, but lower one's. Which also results in running the callback function every few second( ~5sec).
Is it possible to set up a hardware timer to callback every six hours?
Or are hardware timers only available for shorter periods?
How are max and min values for the frequency, or period and prescaler, of a hardware timer?
Im using a STM32F405RG board from Aliexpress.
I set up a hardware timer with a callback function in the REPL.
And it works for timer.freq(1) to run the callback function every second.
But I need a callback every six hours.
If I call timer.freq(1/(60*60*6)), it sets the freq:=0 and manipulates the period and the prescaler, not to a total of 6h, but to a few second.
When I try to change the freq via timer.init( prescaler=168000000, period=6*60*60), it also doesn't take my values, but lower one's. Which also results in running the callback function every few second( ~5sec).
Is it possible to set up a hardware timer to callback every six hours?
Or are hardware timers only available for shorter periods?
How are max and min values for the frequency, or period and prescaler, of a hardware timer?
Last edited by Mikki on Sun Feb 23, 2020 2:52 pm, edited 2 times in total.
Re: STM32F405RG Hardware timer period to 3h
What stops you from trying something like:
import machine
tim = machine.Timer(-1)
tim.init(tick_hz = 1, mode = machine.Timer.PERIODIC, period=6*3600, callback = my_callback)
import machine
tim = machine.Timer(-1)
tim.init(tick_hz = 1, mode = machine.Timer.PERIODIC, period=6*3600, callback = my_callback)
Re: STM32F405RG Hardware timer period to 6h
Thanks for the answer.
My board seems to have a different module structure and different attributes.
My Timer module is under pyb.Timer and it does not support a PERIODIC mode, therefore I use the UP mode. Also the tick_hz attribut is not supported.
I tried the following, but it did not accept my Values:
My board seems to have a different module structure and different attributes.
My Timer module is under pyb.Timer and it does not support a PERIODIC mode, therefore I use the UP mode. Also the tick_hz attribut is not supported.
Code: Select all
>>> dir(machine)
['__name__', 'info', 'unique_id', 'reset', 'soft_reset', 'bootloader', 'freq', 'rng', 'idle', 'sleep', 'deepsleep', 'reset_cause', 'disable_irq', 'enable_irq', 'time_pulse_us', 'mem8', 'mem16', 'mem32', 'Pin', 'Signal', 'I2C', 'SPI', 'UART', 'WDT', 'PWRON_RESET', 'HARD_RESET', 'WDT_RESET', 'DEEPSLEEP_RESET', 'SOFT_RESET']
>>> dir(pyb.Timer)
['init', 'deinit', 'channel', 'counter', 'source_freq', 'freq', 'prescaler', 'period', 'callback', 'UP', 'DOWN', 'CENTER', 'PWM', 'PWM_INVERTED', 'OC_TIMING', 'OC_ACTIVE', 'OC_INACTIVE', 'OC_TOGGLE', 'OC_FORCED_ACTIVE', 'OC_FORCED_INACTIVE', 'IC', 'ENC_A', 'ENC_B', 'ENC_AB', 'HIGH', 'LOW', 'RISING', 'FALLING', 'BOTH']
>>> timer=pyb.Timer(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Timer(-1) doesn't exist
Code: Select all
>>> timer=pyb.Timer(1)
>>> timer.init( prescaler=168000000, period=6*3600,callback=my_callback)
>>> timer
Timer(1, freq=0, prescaler=31232, period=21600, mode=UP, div=1, deadtime=0)
>>> timer.init(freq=1/(6*3600), callback=my_callback)
>>> timer
Timer(1, freq=0, prescaler=65535, period=29530, mode=UP, div=1, deadtime=0)
>>>
Re: STM32F405RG Hardware timer period to 6h
Which version of the firmware are you using? Type Ctrl-B to get it. It looks a little bit outdated.
Also, looking at http://docs.micropython.org/en/latest/l ... ight=timer, you might better use timer 2 or 5, since these are not limited to 16 bit.
Also, looking at http://docs.micropython.org/en/latest/l ... ight=timer, you might better use timer 2 or 5, since these are not limited to 16 bit.
Re: STM32F405RG Hardware timer period to 6h
Thanks, this solved my problem.
Altough using freq to initialise the timer is not accurrate.
I used prescaler and period instead.
My version
Should I concern a firmwareupdate?
As it is a clone, I did not find a firmware from the manufacturer. Is the original firmware for the pyboard compatible, as they both use the STM32?
Altough using freq to initialise the timer is not accurrate.
I used prescaler and period instead.
Code: Select all
>>>timer2=pyb.Timer(2)
>>> timer2.source_freq()
84000000
>>> timer2.init(freq=1/(6*60*60),callback=my_callback)
>>> timer2
Timer(2, freq=0, prescaler=9999, period=181439983, mode=UP, div=1)
>>> timer2.init(prescaler=8400, period=10000*6*60*60, callback=my_callback)
>>> timer2
Timer(2, freq=0, prescaler=8400, period=216000000, mode=UP, div=1)
>>>
Code: Select all
MicroPython v1.9.3 on 2018-03-05; SM1432F405 with STM32F405RG
Type "help()" for more information.
>>>
As it is a clone, I did not find a firmware from the manufacturer. Is the original firmware for the pyboard compatible, as they both use the STM32?
Re: STM32F405RG Hardware timer period to 6h
You may update. But the prebuilt images may not work for your board, unless it is a direct pyboard clone. Some members of the have prepared board definition files for other STM32F405RG boards. They may assist you finding the right one.
Re: STM32F405RG Hardware timer period to 6h
Thanks again for solving my problem.
I did not know the notation for the definition range.
[0-0xffff] for 0-65535
and
[0-0x3fffffff] for 0-1073741823
Having a second look at the documentation, I see what you are referring to.Also, looking at http://docs.micropython.org/en/latest/l ... ight=timer, you might better use timer 2 or 5, since these are not limited to 16 bit.
I did not know the notation for the definition range.
[0-0xffff] for 0-65535
and
[0-0x3fffffff] for 0-1073741823
Re: STM32F405RG Hardware timer period to 6h
Reading the docs, the prescaler should be 8399 for s division by 8400.
Re: STM32F405RG Hardware timer period to 6h
You are right.
I thought it is only a small inaccuracy, but multiplying it with the period the mistake grows.
I thought it is only a small inaccuracy, but multiplying it with the period the mistake grows.
Re: STM32F405RG Hardware timer period to 6h
You should definitely update the firmware -- 1.9.x is quite old (November 2017).
Do you know where the firmware came from?
Pre-built images for some boards are at http://micropython.org/download#other and all the others are built by Andrew at https://gitlab.com/alelec/micropython_ci/-/tags
But I don't see a board named SM1432F405 defined anywhere -- you might need to build your own board config. (look at ports/stm32/boards/ (there are some existing f405 boards, althoguh they're f405rg).
Do you know where the firmware came from?
Pre-built images for some boards are at http://micropython.org/download#other and all the others are built by Andrew at https://gitlab.com/alelec/micropython_ci/-/tags
But I don't see a board named SM1432F405 defined anywhere -- you might need to build your own board config. (look at ports/stm32/boards/ (there are some existing f405 boards, althoguh they're f405rg).