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::GTimerClassConstructs a GTimerClass object.
Public Methods 
TimerClass::beginInitialize a timer and start it immediately.
GTimerClass::stopStop a specific timer.
GTimerClass::reloadReload a specific timer.
GTimerClass::read_usRead 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.

Please confirm that QQ communication software is installed