20 static uint8_t IC_time;
21 static uint8_t IC_highTime;
30 static void (*tim0_handler)(void);
43 tim0_handler = handler;
44 TIMSK0 |= (1<<OCIE0A);
53 TIMSK0 &= ~(1<<OCIE0A);
63 tim0_handler = handler;
64 TCCR0A |= (1 << WGM01);
65 TIMSK0 |= (1<<OCIE0A);
82 if(frequency > (F_CPU / 960)){
86 else if(frequency > 600){
92 else if(frequency > (F_CPU / 240000)){
146 #elif F_CPU == 4800000 148 #elif F_CPU == 1200000 150 #elif F_CPU == 600000 162 MCUCR &= ~(1<<ISC01);
179 IC_time = TCNT0 - IC_highTime;
193 uint8_t tempTime = IC_time;
202 return ((uint16_t)(tempTime-1) * 27);
203 #elif F_CPU == 4800000 204 return ((uint16_t)(tempTime-1) * 53);
205 #elif F_CPU == 1200000 206 return ((uint16_t)(tempTime-1) * 53);
207 #elif F_CPU == 600000 208 return ((uint16_t)(tempTime-1) * 106);
210 return ((uint16_t)(tempTime-1) * 27);
232 TCCR0A |= (1 << WGM01) | (1 << WGM00);
233 TCCR0A |= (1 << COM0A1);
240 TCCR0A |= (1 << WGM01) | (1 << WGM00);
241 TCCR0A |= (1 << COM0B1);
262 #elif F_CPU == 4800000 264 #elif F_CPU == 1200000 266 #elif F_CPU == 600000 273 TCCR0A |= (1 << WGM01) | (1 << WGM00);
274 TCCR0A |= (1 << COM0A1);
281 TCCR0A |= (1 << WGM01) | (1 << WGM00);
282 TCCR0A |= (1 << COM0B1);
306 return TCNT0 = count;
316 OCR0A = (duty * 0xFF)/100;
320 OCR0B = (duty * 0xFF)/100;
332 OCR0B = (pulse / 27);
333 #elif F_CPU == 4800000 334 OCR0B = (pulse / 53);
335 #elif F_CPU == 1200000 336 OCR0B = (pulse / 53);
337 #elif F_CPU == 600000 338 OCR0B = (pulse / 106);
uint8_t TIMER_getCount(timer_main timerNumber)
Get the current value of a running timer.
mcu_error TIMER_setCount(timer_main timerNumber, uint8_t count)
Set the current value of a running timer.
mcu_error TIMER_setupPWM(timer_main timerNumber, timer_channel timerChannel, uint16_t frequency, uint8_t duty)
Initialize given timer for PWM mode.
mcu_error TIMER_resume(timer_main timerNumber)
Resume a paused timer.
mcu_error TIMER_pause(timer_main timerNumber)
Pause an already running timer.
mcu_error TIMER_enableISR(timer_main timerNumber, void(*handler)(void))
Set the ISR target for timeout.
mcu_error TIMER_setPeriod(timer_main timerNumber, uint32_t period)
Set the period for the timer. (in microseconds)
Header file for attiny13a timers.
timer_main
Main timers available on the MCU.
mcu_error TIMER_disableISR(timer_main timerNumber)
Disable the timeout IRQ.
mcu_error TIMER_setFrequency(timer_main timerNumber, uint16_t frequency)
Set the frequency for the timer. (in hertz)
timer_channel
Timers channels available for each timer.
#define CLOCK_DIV_1024
Clock speed divided by 1024.
mcu_error TIMER_setDuty(timer_main timerNumber, timer_channel channel, uint8_t duty)
Set the duty cycle for the waveform (PWM only, 0 - 100%).
mcu_error TIMER_setupPulse(timer_main timerNumber, timer_channel timerChannel, uint16_t frequency, uint16_t pulse)
Initialize given timer for Pulse mode.
Error timer: Period too long / frequency too high.
mcu_error TIMER_setupIC(timer_main timerNumber, timer_channel timerChannel)
Initialize given timer for input capture.
uint8_t pinRead(gpio_port port, gpio_pin pin)
Read the current digital value of an input pin.
mcu_error TIMER_setPulse(timer_main timerNumber, timer_channel channel, uint16_t pulse)
Set the pulse width for the output. (in milliseconds)
#define CLOCK_DIV_64
Clock speed divided by 64.
#define IC_PIN
Pin used for input capture.
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...
mcu_error
Error enumerators for the Debug peripheral.
uint16_t TIMER_getIC(timer_main timerNumber, timer_channel channel)
Get the last input capture time from a channel of a timer.