Timer - Using the periodic GTimer


  • Ameba x 1


Ameba provides 5 hardware GTimer for users to use. The timers’ resolution are at microseconds scale.
Note that the timers may have overlapped pin with other peripherals. For example, the timer with ID 0 overlaps with PWM_3. Therefore, when we use Time 0, we can not use the PWM_3 on D12.
Time IDNote
0Share with PWM_3
1Share with PWM_0
2Share with PWM_1
3Share with PWM_2
4Share with software RTC

The timer can be set to be periodic or for single use. The periodic timers reset periodically, and the single-use timers don’t.
Open the example, “File” -> “Examples” -> “AmebaGTimer” -> “timer_periodical”. Compile and upload to Ameba, and press reset.
In the Serial Monitor, you can see the counter value is increased periodically.

Code Reference

The first argument of begin() is the timer id (0~5).
The second argument is the value of the timer (in microseconds). In the example, we fill in 1000000us = 1s.
The third argument specifies the funcion to call when the time is up. In the example, we call the “myhandler” function to increase the counter value by 1 and print the counter value to serial monitor.
GTimer.begin(0, 1 * 1000 * 1000, myhandler);
The GTimer is periodic by default, therefore “myhandler” function is called every second.

When we want to stop the GTimer, use “stop()”:

Please confirm that QQ communication software is installed