-
-
Notifications
You must be signed in to change notification settings - Fork 24
timer
This class includes support for using K210 hardware timer peripheral
K210 system has three TIMER modules, each with 4 channels, with the following characteristics:
- 32-bit counter width
- Configurable as up or down counter
- Independent clocks
- Configurable polarity for each interrupt
- Configurable individual or combined interrupt output flags
- Each timer has a read/write consistent register
- Timer reload output, switches whenever the timer counter is reloaded
- Output PWM mode , 0 % -100% duty cycle
Several timer operational modes are available:
Mode | Description |
---|---|
ONE_SHOT | When timer is started, it runs for defined time and stops. If given, the callback function is executed when the defined time elapses. |
PERIODIC | Timer runs repeatedly until explicitly stopped. When defined time elapses the callback function is executed, if given |
CHRONO | Used for measuring the elapsed time with µs precision. Can be started, paused, resumed and stopped |
- Up to 12 hardware timers can be used.
- In CHRONO mode timers uses 1 MHz clock as timer base frequency to achieve 1 µs resolution.
- In other modes timers uses hw timer clock as timer base frequency, resulution of 1 µs is available.
- Each timer keeps track of number of timer events and number of executed callbacks
PWM and Timer clases uses the same K210 timers.
If some channel is used for Timer it cannot be used for PWM and vice versa.
Warning:
Due to MicroPython callback latency, some callbacks may not be executed if the timer period is very short.
The number of events and executed callbacks can be checked usingtm.events()
method.
timer_no
argument is the timer number to be used for the timer.
Range: 0 ~ 11
Argument | Description |
---|---|
period |
Timer period in µs, only used for PERIODIC and ONE_SHOT timers Default: 1000000 µs |
mode |
Timer mode of operation. Use constants: machine.Timer.ONE_SHOT machine.Timer.PERIODIC machine.Timer.CHRONO Default: PERIODIC |
callback |
The Python callback function to be executed on timer event Default: None
|
pin |
GPIO pin to be used as debug output. If used, the gpio level will toggle on each timer event. Default: -1 (not used) |
All arguments must be given as kw arguments (arg=value
)
The timer of the type
CHRONO
is not started aftertimer.init()
.
Stop and deinitialize the timer, free all used resources.
Returns the current timer counter value in µs
Most useful for CHRONO mode timers, as it returns the actual elapsed time.
Pause the timer.
Stop the timer. Alias for tm.pause()
Only use for timer in CHRONO mode.
Resume the previously paused timer.
Resume the previously paused/stopped timer.
Same function as tm.resume()
, but resets all timer counters.
Start the ONE_SHOT timer again.
Only use for timer in ONE_SHOT mode.
Returns the hw timer number this timer uses.
Returns the number of timer events and number of executed callbacks.
The tuple is returned: (num_events, num_cb).
If no callbacks were missed, num_events = num_cb
.
Returns True
if the timmer is currently running, False
if not.
Get or set the timer period.
Executed without argument, returns the current timer's period.
Executed with period
argument, changes the timer's period to the new value.
Disable or change the timer's callback function.
Executed without argument or with cb_func=None
, disables timer's callback.
Executed with cb_func
argument, changes the timer's calback function to the new one.
Only use for timers in ONE_SHOT or PERIODIC modes.
- Maix-M1 schematic
- Maix-Bit schematic
- Maix-Go schematic
- Kendryte K210 datasheet
- RISC-V ISA Design
- RISC-V ISA Manual
- Forum
- MicroPython documentation
If you find this project useful, you can contribute by making a donation