GlobLib
HAL and API libraries for MCUs and hardware.
|
This module contains low level functions for timer interaction. More...
Files | |
file | stm32f103cb_timer.h |
Header file for stm32f103cb timers. | |
Enumerations |
Functions | |
mcu_error | TIMER_setupCount (timer_main timerNumber, uint32_t frequency, void(*handler)(void)) |
Initialize given timer for standard count with interrupt on timeout. More... | |
mcu_error | TIMER_setupIC (timer_main timerNumber, timer_channel timerChannel) |
Initialize given timer for input capture. More... | |
mcu_error | TIMER_setupPWM (timer_main timerNumber, timer_channel timerChannel, uint32_t frequency, uint8_t duty) |
Initialize given timer for PWM mode. More... | |
mcu_error | TIMER_setupPulse (timer_main timerNumber, timer_channel timerChannel, uint32_t frequency, uint32_t pulse) |
Initialize given timer for Pulse mode. More... | |
mcu_error | TIMER_setPeriod (timer_main timerNumber, uint32_t period) |
Set the period for the timer. (in microseconds) More... | |
mcu_error | TIMER_setFrequency (timer_main timerNumber, uint32_t frequency) |
Set the frequency for the timer. (in hertz) More... | |
mcu_error | TIMER_setDuty (timer_main timerNumber, timer_channel channel, uint8_t duty) |
Set the duty cycle for the waveform (PWM only, 0 - 100%). More... | |
mcu_error | TIMER_setPulse (timer_main timerNumber, timer_channel channel, uint32_t pulse) |
Set the pulse width for the output. (in microseconds) More... | |
uint16_t | TIMER_getCount (timer_main timerNumber) |
Get the current value of a running timer. More... | |
mcu_error | TIMER_setCount (timer_main timerNumber, uint16_t count) |
Set the current value of a running timer. More... | |
uint16_t | TIMER_getIC (timer_main timerNumber, timer_channel channel) |
Get the last input capture time from a channel of a timer. More... | |
mcu_error | TIMER_enableISR (timer_main timerNumber, void(*handler)(void)) |
Set the ISR target for timeout. More... | |
mcu_error | TIMER_disableISR (timer_main timerNumber) |
Disable the timeout IRQ. More... | |
mcu_error | TIMER_pause (timer_main timerNumber) |
Pause an already running timer. More... | |
mcu_error | TIMER_resume (timer_main timerNumber) |
Resume a paused timer. More... | |
This module contains low level functions for timer interaction.
The STM32F1x3 has four timers, each with four compare/capture channels.
Each timer can be configured to a different function, however each channel of that timer should have the same function. Exceptions are:
A timer can have PWM and pulse outputs on different channels as long as the frequency is the same. The ISR of the output timers, (PWM, pulse) can be targeted to function calls. The ISR will trigger at the same frequency as the timer.
The resolution of the base timer is set as:
The period is modified with TIMER_setPeriod()
Timer output/input channels are mapped to:
enum timer_channel |
Timers channels available for each timer.
Enumerator | |
---|---|
CHANNEL_1 |
Channel 1. |
CHANNEL_2 |
Channel 2. |
CHANNEL_3 |
Channel 3. |
CHANNEL_4 |
Channel 4. |
Definition at line 99 of file stm32f103cb_timer.h.
enum timer_main |
Main timers available on the MCU.
Enumerator | |
---|---|
TIMER_1 |
Timer 1. |
TIMER_2 |
Timer 2. |
TIMER_3 |
Timer 3. |
TIMER_4 |
Timer 4. |
Definition at line 88 of file stm32f103cb_timer.h.
mcu_error TIMER_disableISR | ( | timer_main | timerNumber | ) |
Disable the timeout IRQ.
This disables any previous use of timeout interrupts.
timerNumber | The timer number to modify |
Definition at line 751 of file stm32f103cb_timer.c.
mcu_error TIMER_enableISR | ( | timer_main | timerNumber, |
void(*)(void) | handler | ||
) |
Set the ISR target for timeout.
This feature can be used for Count, Pulse and PWM modes. Function is called on timeout event recursivly until TIMER_disableISR() is used.
timerNumber | The timer number to modify |
handler | The function to call on timeout |
Definition at line 696 of file stm32f103cb_timer.c.
uint16_t TIMER_getCount | ( | timer_main | timerNumber | ) |
Get the current value of a running timer.
This function returns the current value of the timer. The resolution of this value is detailed in module outline.
timerNumber | The timer number to modify |
Definition at line 2119 of file stm32f103cb_timer.c.
uint16_t TIMER_getIC | ( | timer_main | timerNumber, |
timer_channel | channel | ||
) |
Get the last input capture time from a channel of a timer.
The timer must be setup with TIMER_setupIC() for this function to work.
This function returns zero if no capture has occured within the last period. (Around 63ms). This value could be increased by setting a larger period with TIMER_setPeriod(). This however would scale up the value retuned by 10 or 100, as outlined in the module description.
timerNumber | The timer number to modify |
channel | The timer chanel to modify |
Definition at line 1442 of file stm32f103cb_timer.c.
mcu_error TIMER_pause | ( | timer_main | timerNumber | ) |
Pause an already running timer.
The timer must have been already setup to use this.
timerNumber | The timer number to modify |
Definition at line 825 of file stm32f103cb_timer.c.
mcu_error TIMER_resume | ( | timer_main | timerNumber | ) |
Resume a paused timer.
The timer must have been already setup and paused.
timerNumber | The timer number to modify |
Definition at line 859 of file stm32f103cb_timer.c.
mcu_error TIMER_setCount | ( | timer_main | timerNumber, |
uint16_t | count | ||
) |
Set the current value of a running timer.
The resolution of this value is detailed in module outline.
timerNumber | The timer number to modify |
count | The timer value |
Definition at line 2154 of file stm32f103cb_timer.c.
mcu_error TIMER_setDuty | ( | timer_main | timerNumber, |
timer_channel | channel, | ||
uint8_t | duty | ||
) |
Set the duty cycle for the waveform (PWM only, 0 - 100%).
timerNumber | The timer number to modify |
channel | The timer chanel to modify |
duty | The desired duty cycle. |
Definition at line 2382 of file stm32f103cb_timer.c.
mcu_error TIMER_setFrequency | ( | timer_main | timerNumber, |
uint32_t | frequency | ||
) |
Set the frequency for the timer. (in hertz)
timerNumber | The timer number to modify |
frequency | The desired timeout frequency. |
Definition at line 2344 of file stm32f103cb_timer.c.
mcu_error TIMER_setPeriod | ( | timer_main | timerNumber, |
uint32_t | period | ||
) |
Set the period for the timer. (in microseconds)
timerNumber | The timer number to modify |
period | The desired timeout period. |
Definition at line 2193 of file stm32f103cb_timer.c.
mcu_error TIMER_setPulse | ( | timer_main | timerNumber, |
timer_channel | channel, | ||
uint32_t | pulse | ||
) |
Set the pulse width for the output. (in microseconds)
timerNumber | The timer number to modify |
channel | The timer chanel to modify |
pulse | The desired pulse width. |
Definition at line 2653 of file stm32f103cb_timer.c.
mcu_error TIMER_setupCount | ( | timer_main | timerNumber, |
uint32_t | frequency, | ||
void(*)(void) | handler | ||
) |
Initialize given timer for standard count with interrupt on timeout.
This mode triggers an ISR on timeout. This function can be impemented for any timer by using TIMER_setISR(), however the frequency will be set to the frequency of the already used timer.
timerNumber | The timer number to setup |
handler | The function to call on timeout event. |
frequency | The frequency of the timer count expiration. |
Definition at line 1001 of file stm32f103cb_timer.c.
mcu_error TIMER_setupIC | ( | timer_main | timerNumber, |
timer_channel | timerChannel | ||
) |
Initialize given timer for input capture.
This supports input capture up for pulses up to 50ms long.
This function utalizes the ISR for the timer, this means that the ISR cannnot be target to an external function using TIMER_enableISR();
timerNumber | The timer number to setup |
timerChannel | The channel of that timer to use. |
Definition at line 897 of file stm32f103cb_timer.c.
mcu_error TIMER_setupPulse | ( | timer_main | timerNumber, |
timer_channel | timerChannel, | ||
uint32_t | frequency, | ||
uint32_t | pulse | ||
) |
Initialize given timer for Pulse mode.
The given timer number timer_main is now locked to this pulse or PWM modes.
All channels of this timer can only be used for pulse of PWM. Each channel must also share the same frequency. However each channel can be turned on and off
timerNumber | The timer number to setup |
timerChannel | The channel of that timer to use. |
frequency | The frequency of the total signal. |
pulse | The initial pulse width of the signal. |
Definition at line 967 of file stm32f103cb_timer.c.
mcu_error TIMER_setupPWM | ( | timer_main | timerNumber, |
timer_channel | timerChannel, | ||
uint32_t | frequency, | ||
uint8_t | duty | ||
) |
Initialize given timer for PWM mode.
The given timer number timer_main is now locked to this or pulse mode.
All channels of this timer can only be used for PWM of Pulse width output. Each channel must also share the same frequency. However each channel can be turned on and off
timerNumber | The timer number to setup |
timerChannel | The channel of that timer to use. |
frequency | The frequncy of the signal. |
duty | The initial duty cycle. |
Definition at line 934 of file stm32f103cb_timer.c.