GlobLib
HAL and API libraries for MCUs and hardware.
|
This module contains low level functions for timer interaction. More...
Files | |
file | attiny13a_timer.h |
Header file for attiny13a timers. | |
Macros | |
#define | IC_PIN PIN4 |
Pin used for input capture. | |
Enumerations |
Functions | |
mcu_error | TIMER_setupCount (timer_main timerNumber, uint16_t frequency, void(*handler)(void)) |
Initialize given timer for standard count with interrupt trigging the function handler 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, uint16_t frequency, uint8_t duty) |
Initialize given timer for PWM mode. More... | |
mcu_error | TIMER_setupPulse (timer_main timerNumber, timer_channel timerChannel, uint16_t frequency, uint16_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, uint16_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, uint16_t pulse) |
Set the pulse width for the output. (in milliseconds) More... | |
uint8_t | TIMER_getCount (timer_main timerNumber) |
Get the current value of a running timer. More... | |
mcu_error | TIMER_setCount (timer_main timerNumber, uint8_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 ATTINY13A has a single 8 bit timer with two output channels with output channels mapped to:
The low width of the timer means there are frequency and resolution restrictions. See the given function descriptions.
Many of the functions in the module have unused parameters. These parameters are kept in place for compatability with other MCUs.
enum timer_channel |
Timers channels available for each timer.
Enumerator | |
---|---|
CHANNEL_1 |
Channel 1. |
CHANNEL_2 |
Channel 2. |
Definition at line 76 of file attiny13a_timer.h.
enum timer_main |
Main timers available on the MCU.
Enumerator | |
---|---|
TIMER_0 |
Timer 0. |
Definition at line 68 of file attiny13a_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 (not used) |
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 recursively until TIMER_disableISR() is used.
timerNumber | The timer number to modify (not used) |
handler | The function to call on timeout |
uint8_t TIMER_getCount | ( | timer_main | timerNumber | ) |
Get the current value of a running timer.
The resolution of the value returned depends of the frequency of timer as setup.
timerNumber | The timer number to modify (not used) |
Definition at line 297 of file attiny13a_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.
timerNumber | The timer number to modify (not used) |
channel | The timer channel to modify |
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 (not used) |
Definition at line 113 of file attiny13a_timer.c.
mcu_error TIMER_resume | ( | timer_main | timerNumber | ) |
Resume a paused timer.
Due to the internal register configuration of the ATTINY13A the timer needs to be restarted with one of the setup functions. E.g TIMER_setupCount()
timerNumber | The timer number to modify (not used) |
Definition at line 122 of file attiny13a_timer.c.
mcu_error TIMER_setCount | ( | timer_main | timerNumber, |
uint8_t | count | ||
) |
Set the current value of a running timer.
timerNumber | The timer number to modify (not used) |
count | The timer value |
Definition at line 303 of file attiny13a_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 (not used) |
channel | The timer chanel to modify |
duty | The desired duty cycle. |
Definition at line 312 of file attiny13a_timer.c.
mcu_error TIMER_setFrequency | ( | timer_main | timerNumber, |
uint16_t | frequency | ||
) |
Set the frequency for the timer. (in hertz)
The minimum and maximum frequency value that can be represented are dependant on the frequency of the main clock as specified:
F_CPU | Minimum | Maximum |
---|---|---|
9.6MHz | 40Hz | 10kHz |
4.8MHz | 20Hz | 5kHz |
1.2MHz | 5Hz | 2.5kHz |
0.6MHz | 3Hz | 1.25kHz |
timerNumber | The timer number to modify (not used) |
frequency | The desired timeout frequency. |
mcu_error TIMER_setPeriod | ( | timer_main | timerNumber, |
uint32_t | period | ||
) |
Set the period for the timer. (in microseconds)
The minimum and maximum periods that can be represented are dependant on the frequency of the main clock as specified:
F_CPU | Minimum | Maximum |
---|---|---|
9.6MHz | 100us | 25ms |
4.8MHz | 200us | 50ms |
1.2MHz | 800us | 200ms |
0.6MHz | 1.6ms | 400ms |
timerNumber | The timer number to modify (not used) |
period | The desired timeout period. |
mcu_error TIMER_setPulse | ( | timer_main | timerNumber, |
timer_channel | channel, | ||
uint16_t | pulse | ||
) |
Set the pulse width for the output. (in milliseconds)
The resolution and period of the pulse widths are limited by the clock frequency as follows:
F_CPU | Period | Resolution |
---|---|---|
9.6MHz | 6.8ms | 26.6us |
4.8MHz | 13.6ms | 53.3us |
1.2MHz | 13.5ms | 53.3us |
0.6MHz | 27.9ms | 106us |
timerNumber | The timer number to modify (not used) |
channel | The timer channel to modify |
pulse | The desired pulse width. |
Definition at line 326 of file attiny13a_timer.c.
mcu_error TIMER_setupCount | ( | timer_main | timerNumber, |
uint16_t | frequency, | ||
void(*)(void) | handler | ||
) |
Initialize given timer for standard count with interrupt trigging the function handler on timeout.
The minimum and maximum frequency value that can be represented are dependant on the frequency of the main clock as specified:
F_CPU | Minimum | Maximum |
---|---|---|
9.6MHz | 40Hz | 10kHz |
4.8MHz | 20Hz | 5kHz |
1.2MHz | 5Hz | 2.5kHz |
0.6MHz | 3Hz | 1.25kHz |
timerNumber | The timer number to setup (not used) |
handler | The function to call on timeout event. |
frequency | The frequency of the timer count expiration. |
mcu_error TIMER_setupIC | ( | timer_main | timerNumber, |
timer_channel | timerChannel | ||
) |
Initialize given timer for input capture.
The input capture channel is fixed to PORTB, PIN4. This can be changed by adding the compiler flag -DIC_PIN=xxx, where xxx is the pin number defined by gpio_pin.
The signal period and pulse resolution is dependant on the clock frequency of the device, as set in the Makefile.
F_CPU | Period | Resolution |
---|---|---|
9.6MHz | 6.8ms | 26.6us |
4.8MHz | 13.6ms | 53.3us |
1.2MHz | 13.5ms | 53.3us |
0.6MHz | 27.9ms | 106us |
timerNumber | The timer number to setup (not used) |
timerChannel | The channel of that timer to use. (not used) |
mcu_error TIMER_setupPulse | ( | timer_main | timerNumber, |
timer_channel | timerChannel, | ||
uint16_t | frequency, | ||
uint16_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
The signal period and pulse resolution is dependant on the clock frequency of the device, as set in the Makefile.
F_CPU | Period | Resolution |
---|---|---|
9.6MHz | 6.8ms | 26.6us |
4.8MHz | 13.6ms | 53.3us |
1.2MHz | 13.5ms | 53.3us |
0.6MHz | 27.9ms | 106us |
timerNumber | The timer number to setup (not used) |
timerChannel | The channel of that timer to use. |
frequency | The frequency of the total signal. (not used) |
pulse | The initial pulse width of the signal. |
Definition at line 251 of file attiny13a_timer.c.
mcu_error TIMER_setupPWM | ( | timer_main | timerNumber, |
timer_channel | timerChannel, | ||
uint16_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
The frequency of the PWM waveform is determined by the clock frequency as follows:
F_CPU | Frequency |
---|---|
9.6MHz | 37.5kHz |
4.8MHz | 18.75kHz |
1.2MHz | 4.69kHz |
0.6MHz | 2.3kHz |
timerNumber | The timer number to setup (not used) |
timerChannel | The channel of that timer to use. |
frequency | The frequency of the signal. (not used) |
duty | The initial duty cycle. |
Definition at line 220 of file attiny13a_timer.c.