← index #8586PR #9726
Off-topic · high · value 0.920
QUERY · ISSUE

Long Timer Never Gets Called

openby patrick-collinsopened 2022-04-25updated 2022-04-26
port-rp2

On a Raspberry Pico a timer with a period of 300000 (5 minutes) gets called reliably while another timer with a period of 900000 (15 minutes) never gets called. Changing the period of task3 to 300000 gets it working again.

task1 = Timer()
task2 = Timer()
task3 = Timer()
task1.init(period=60000, mode=Timer.PERIODIC, callback=get_gnss)
task2.init(period=300000, mode=Timer.PERIODIC, callback=get_temperature)
task3.init(period=900000, mode=Timer.PERIODIC, callback=put_data)

CANDIDATE · PULL REQUEST

docs/library/machine.Timer: Add freq arguement in machine.Timer.

closedby LiaoJingyiopened 2022-10-23updated 2022-10-24

Timer has a freq arguement which is not methoned in the document.

  • The timer class method timer_settime(tid, hz) has a frequency arguments. And the period is in nano second accuracy.
  • Timer is triggered by Crystal Oscillator (XOSC). The STARTUP_DELAY register specifies how many clock cycles must be seen from the crystal before it can be used. This is specified in multiples of 256. That means in theory the max frequency is 12 MHz (crystal frequency) divided by 256, which is 46.875 MHz.

The following code is tested on Respberry Pi pico, using RP2040 microcontrollers.

from machine import  Timer
speed = 2000 
tim = Timer()
tim.init(freq=speed, mode=Timer.PERIODIC, callback=testSeqCallback)

Result supports arguement freq, and outputs correct signal.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied