GTimerClass Class

GTimerClass Class

Description
A class used for managing GTimer settings. 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, uint32_t userdata);

Parameters
timerid: GTimer ID. (There are 5 valid GTimer with timer id 0~4).
duration_us: The duration of the timer (in us) with precision in 32,768Hz.
periodical: By default, the timer would keep periodically countdown and reloaded, which means the handler would periodically be invoked. (Default value: True).
userdate: The user data brings to the handler. (Default value: 0).

Returns
NA

Example Code
Example: TimerOneshot
(https://github.com/ambiot/ambd_arduino/tree/dev/Arduino_package/hardware/libraries/GTimer/examples/TimerOneshot/TimerOneshot.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. (There are 5 valid GTimer with timer id 0~4)

Returns
NA

Example Code
Example: TimerPeriodical
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/GTimer/examples/TimerPeriodical/TimerPeriodical.ino)

Notes and Warnings
“GTimer.h” must be included to use the class function.

GTimerClass::reload

Description
Reload a specific timer by changing the duration_us. The GTimer is a countdown timer. Reload it would make it discard the current countdown value and restart countdown based on the duration (in us).

Syntax
reload(uint32_t timerid, uint32_t duration_us);

Parameters
timerid: The timer to be modified. (There are 5 valid GTimer with timer id 0~4)
duration_us: The updated duration to be set (in us).

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 time value (in us).

Syntax
uint64_t read_us(uint32_t timerid);

Parameters
timerid: The timer to be read. (There are 5 valid GTimer with timer id 0~4)

Returns
This function returns “0” if the timerid is invalid, otherwise, returns the current countdown time value (in us).

Example Code
NA

Notes and Warnings
“GTimer.h” must be included to use the class function.

请先确认已安装QQ通讯软体