when timer 1 or 3 is in CTC mode, in the interrupt you have to load the comparison registerOCR1A (OCR3A), otherwise the desired time interval does not work.
//****
uint8_t timer3=0;
//**
//interrupt from timer 1 in coincidence with A
ISR(TIMER1_COMPA_vect)
{
OCR1A=12500;//does not want to work without this line (the interval does not match)
if(timer3==0){cbi(PORTB,5);timer3=1;}
else {sbi(PORTB,5);timer3=0;}
}
//
void setup()
{
//set port led
DDRB=0b01110111;
PORTB=0b01110111;
// set timer 1
cli();
OCR1A=12500;
TCCR1A =0;// 0b00000000;
//TCCR1B = 0b00001011;
TCCR1B |=(1<<WGM12);//ctc 0100
TCCR1B |=(1<<CS10);
TCCR1B |=(1<<CS11);
TCCR3C = 0;//0b00000000;
TIMSK |= (1<<OCIE1A);
sei();
}
void loop()
{
}
//*****
this happens both with timer 1 and with timer3 (with the corresponding register settings).
This code is checked in AVR STUDIO 7, without line OCR1A = 12500; in the interrupt ISR (TIMER1_COMPA_vect).
For many years I wrote programs for Atmega, both in assembler and in C, С++. Such a situation has never happened.
When working with Atmega 328, setting a timer and interruption does not cause problems
when timer 1 or 3 is in CTC mode, in the interrupt you have to load the comparison registerOCR1A (OCR3A), otherwise the desired time interval does not work. //****
include <avr/io.h>
include <avr/interrupt.h>
ifndef cbi
define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
endif
ifndef sbi
define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
endif
//LED control on standard contact
define LED_RED_ON cbi(PORTB,5)
define LED_RED_OFF sbi(PORTB,5)
uint8_t timer3=0; //** //interrupt from timer 1 in coincidence with A ISR(TIMER1_COMPA_vect) { OCR1A=12500;//does not want to work without this line (the interval does not match) if(timer3==0){cbi(PORTB,5);timer3=1;} else {sbi(PORTB,5);timer3=0;} } // void setup() { //set port led DDRB=0b01110111; PORTB=0b01110111; // set timer 1 cli(); OCR1A=12500; TCCR1A =0;// 0b00000000; //TCCR1B = 0b00001011; TCCR1B |=(1<<WGM12);//ctc 0100 TCCR1B |=(1<<CS10); TCCR1B |=(1<<CS11); TCCR3C = 0;//0b00000000; TIMSK |= (1<<OCIE1A); sei(); } void loop() { } //***** this happens both with timer 1 and with timer3 (with the corresponding register settings). This code is checked in AVR STUDIO 7, without line OCR1A = 12500; in the interrupt ISR (TIMER1_COMPA_vect). For many years I wrote programs for Atmega, both in assembler and in C, С++. Such a situation has never happened. When working with Atmega 328, setting a timer and interruption does not cause problems