Hi, I am trying to understand what this piece of code does.
I am having trouble understanding the functions of
ICR1=160
TCNT=OCR1A-1
also, where can I learn what do values like 0x10 | 0x01 mean for TCCR1B
Thanks in advance!
TCCR1B = 0x00;
TCCR1A = 0x80 | 0x00;
TCCR1A |= 0x30;
ICR1 = 160;
OCR1A = 1;
OCR1B = ICR1 - OCR1A;
TCNT1 = OCR1A -1;
//int myPrescaler = 1; // this could be a number in [1 , 6]. In this case, 3 corresponds in binary to 011.
//TCCR2B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR2B with our new value 011
TCCR1B = 0x10 | 0x01;
Did you consult the processor data sheet?
The description of each of the registers is in the datasheet. For an Arduino UNO or Nano you want the ATmega328p datasheet. TCNT1, ICR1,... refer to Timer/Counter 1.
ICR1 is the Input Compare Register but I suspect that in this case it is used to store "TOP", the maximum counter value for one of the Fast PWM Waveform Generation Modes.
TCNT1 is the current timer count.
OCR1A if one of two Output Compare Registers used to set the count at which the corresponding output pin is set HIGH or LOW or toggled.
There are a bunch of settings in the Timer/Counter Control Registers: TCCR1A and TCCR1B.
For some processors, the manufacturer issues a different document (like a user manual) to add more detail about all the internal registers and other circuits. But Atmel has it all together in one datasheet. Sometimes there are app notes that add yet more to those. All that stuff is expected to be clear and complete - it has to be, for software designers to have any success with the IC. That is why we always send people there.