GTimerClass Class
GTimerClass Class
Description
A class to operate Gtimer. GTimer is a hardware timer and occupy same resource as PWM. Please make sure the timer is not conflict with you PWM index.
Syntax
class GTimerClass
Members
Public Constructors | |
GTimerClass::GTimerClass | Constructs a GTimerClass object. |
Public Methods | |
TimerClass::begin | Initialize a timer and start it immediately. |
GTimerClass::stop | Stop a specific timer. |
GTimerClass::reload | Reload a specific timer. |
GTimerClass::read_us | Read current countdown value. |
GTimerClass::begin
Description
Initialize a timer and start it immediately.
Syntax
void begin(uint32_t timerid, uint32_t duration_us, void (*handler)(uint32_t), bool periodical = true, uint32_t userdata = 0);
Parameters
timerid: There are 5 valid GTimer with timer id 0~4.
duration_us: The duration of the timer. The time unit is microsecond, and the precision is 32768Hz.
periodical: By default, the timer would keep periodically countdown and reload which means the handler would periodically be invoked.
userdate: The user data brings to the handler.
Returns
NA
Example Code
Example: TimerOneshot
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GTimer/examples/timer_oneshot/timer_oneshot.ino)
Notes and Warnings
“GTimer.h” must be included to use the class function.
GTimerClass::stop
Description
Stop a specific timer.
Syntax
void stop(uint32_t timerid);
Parameters
timerid: Stop the timer with the selected timer id. timerid range: 0~4.
Returns
NA
Example Code
Example: TimerPeriodical
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/GTimer/examples/timer_periodical/timer_periodical.ino)
Notes and Warnings
“GTimer.h” must be included to use the class function.
GTimerClass::reload
Description
Reload a specific timer. The GTimer is a countdown timer. Reload it would make it discard the current countdown value and restart countdown based on the duration.
Syntax
reload(uint32_t timerid, uint32_t duration_us);
Parameters
timerid: The timer to be modified, timerid range: 0~4
duration_us: The updated duration in unit of microseconds
Returns
NA
Example Code
NA
Notes and Warnings
“GTimer.h” must be included to use the class function.
GTimerClass::read_us
Description
Read the current countdown value.
Syntax
uint64_t read_us(uint32_t timerid);
Parameters
timerid: The timer to be read, timerid range: 0~4.
Returns
This function returns 0 if the timerid is more than GTIMER_MAX=5. Else, returns the current countdown value.
Example Code
NA
Notes and Warnings
“GTimer.h” must be included to use the class function.