/      日本語

Timer Library

Timer library
Introducing the Timer library.

Timer Library

tsTimerContext

A structure for configuration used by the Timer library.

  • Clear it to 0.
  • Ensure it is statically allocated.
TypeNameExplanation
uint8u8DeviceSpecifies the timer device (E_AHI_DEVICE_TIMER0..4).
uint16u16HzSpecifies the timer frequency in Hz.
uint8u8PreScaleSets the prescaler for the 16MHz clock.
bool_tbPWMOutIf TRUE, performs PWM output.
bool_tbDisableIntIf TRUE, disables interrupts.

vTimerConfig()

Explanation

Initializes the Timer.

Arguments

TypeNameDescription
tsTimerContextpsTCThe timer configuration structure.

Return Value

None.

Sample

tsTimerContext sTimerApp; // global or static allocation

// set 64ticks/sec
memset(&sTimerApp, 0, sizeof(tsTimerContext));
sTimerApp.u8Device = E_AHI_DEVICE_TIMER0;
sTimerApp.u16Hz = 64;
sTimerApp.u8PreScale = 4; // 15625ct@2^4

vTimerStart()

Explanation

Starts the Timer.

This function can also be called for a Timer that has already been started. It is used when changing the duty cycle, etc.

Arguments

TypeNameDescription
tsTimerContextpsTCThe timer configuration structure.

Return Value

None.

Sample

// initialize and start
vTimerConfig(&sTimerApp); // initialize
vTimerStart(&sTimerApp); // start

// change duty
sTimerPWM.u16Duty = 256; // set new duty ratio
vTimerStart(&sTimerPWM); // just start again to change duty

vTimerStop()

Explanation

Stops the operation of the Timer.

Arguments

TypeNameDescription
tsTimerContextpsTCThe timer configuration structure.
Return Value

None.

Sample

// just stop the timer
vTimerStop(&sTimerApp);
...
// restart
vTimerStart(&sTimerApp);
...
// now, disable timer completely
vTimerStop(&sTimerApp);
vTimerDisable(&sTimerApp);

vTimerDisable()

This function destroys the Timer.

Arguments

TypeNameDescription
tsTimerContextpsTCThe timer configuration structure.

Return Value

None.

Sample

// just stop the timer
vTimerStop(&sTimerApp);
...
// restart
vTimerStart(&sTimerApp);
...
// now, disable timer completely
vTimerStop(&sTimerApp);
vTimerDisable(&sTimerApp);