From b9ede455b3dc93a0de8aab81a685d12aeab5807e Mon Sep 17 00:00:00 2001 From: Ivan Stefanov Date: Tue, 3 Nov 2020 17:37:57 +0200 Subject: [PATCH] Create Timer_1_200ms_ISR.ino --- Timer_1_200ms_ISR/Timer_1_200ms_ISR.ino | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Timer_1_200ms_ISR/Timer_1_200ms_ISR.ino diff --git a/Timer_1_200ms_ISR/Timer_1_200ms_ISR.ino b/Timer_1_200ms_ISR/Timer_1_200ms_ISR.ino new file mode 100644 index 0000000..b1ae812 --- /dev/null +++ b/Timer_1_200ms_ISR/Timer_1_200ms_ISR.ino @@ -0,0 +1,43 @@ +void setup() { + pinMode(13, OUTPUT); + noInterrupts(); //cli(); // Stop reception of interrupts + + // Set PB1 to be an output (Pin9 Arduino UNO) + DDRB |= (1 << PB1); + // Clear Timer/Counter Control Registers + TCCR1A = 0; + TCCR1B = 0; + TIMSK1 = 0; + // Set non-inverting mode - Table 15-3 (page 108) + TCCR1A |= (1 << COM1A1); + // Set Fast-PWM Mode (Mode 14) - Table 15-5 (page 109) + TCCR1A |= (1 << WGM11); + TCCR1B |= (1 << WGM12); + TCCR1B |= (1 << WGM13); + // Clear Timer 1 Counter + TCNT1 = 0; + // Set PWM frequency/top value - Output PWM 10kHz + ICR1 = 199; + OCR1A = 180; + // Enable compare match interrupt + TIMSK1 |= (1 << OCIE1A); + TIMSK1 |= (1 << TOIE1); + // Set prescaler to 8 and starts PWM + TCCR1B |= (1 << CS11); + + interrupts(); //sei(); +} + +void loop() { + // Empty +} + +//Timer1 Compare Match Interrupt turns OFF pin 13 (LED) +ISR(TIMER1_COMPA_vect) { + digitalWrite(13, LOW); +} + +//Timer1 Overflow Interrupt turns ON pin 13 (LED) +ISR(TIMER1_OVF_vect) { + digitalWrite(13, HIGH); +} -- 2.39.5