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.
Type | Name | Explanation |
---|---|---|
uint8 | u8Device | Specifies the timer device (E_AHI_DEVICE_TIMER0 ..4). |
uint16 | u16Hz | Specifies the timer frequency in Hz. |
uint8 | u8PreScale | Sets the prescaler for the 16MHz clock. |
bool_t | bPWMOut | If TRUE , performs PWM output. |
bool_t | bDisableInt | If TRUE , disables interrupts. |
vTimerConfig()
Explanation
Initializes the Timer
.
Arguments
Type | Name | Description |
---|---|---|
tsTimerContext | psTC | The 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
Type | Name | Description |
---|---|---|
tsTimerContext | psTC | The 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
Type | Name | Description |
---|---|---|
tsTimerContext | psTC | The 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
Type | Name | Description |
---|---|---|
tsTimerContext | psTC | The timer configuration structure. |
Return Value
None.
Sample
// just stop the timer
vTimerStop(&sTimerApp);
...
// restart
vTimerStart(&sTimerApp);
...
// now, disable timer completely
vTimerStop(&sTimerApp);
vTimerDisable(&sTimerApp);