Actions

EmSys

Tm4clib-gptm-programming-examples

From EdWiki

GPTM Programming Example

The following example shows how to use the timer API to configure the timer as a half-width one shot timer and a half-width edge capture counter.

  1. #include "cortex.h"
  2. #include "gptm.h"
  3.  
  4. /* Configure TimerA as a half-width one-shot timer, and TimerB as a
  5.    half-width edge capture counter.
  6. */
  7. gptm_configure(TIMER0, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_ONE_SHOT | TIMER_CFG_B_CAP_COUNT));
  8.  
  9. /* Set the count time for the the one-shot timer (TimerA). */
  10. gptm_set_load(TIMER0, TIMER_A, 3000);
  11.  
  12. /* Configure the counter (TimerB) to count both edges. */
  13. gptm_control_event(TIMER0, TIMER_B, TIMER_EVENT_BOTH_EDGES);
  14.  
  15. /* Enable the timers. */
  16. gptm_enable(TIMER0, TIMER_BOTH);