Files
42_EXT_03_42chips/module05/ex00/timer.c
2025-03-15 16:15:10 +01:00

12 lines
432 B
C

#include "header.h"
// Set up Timer1 in CTC mode to trigger every 20ms
// With 16MHz clock and prescaler of 8, and OCR1A = 39999:
// 16MHz/8/40000 = 50Hz = 20ms period
void timer_1B_init() {
TCCR1A = 0; // Normal operation, OC1A/OC1B disconnected
TCCR1B = (1 << WGM12) | (1 << CS11); // CTC mode, prescaler = 8
OCR1A = 39999; // Compare match value for 20ms
TIMSK1 = (1 << OCIE1B); // Enable Timer1 Compare B Match Interrupt
}