Calculating value of TCNT register or Delay
Timer as counter
- When we use timer mechanism, whole process runs on clock of crystal oscillator
- But when we use timer as counter it get pulse from T0 (PORTB.0) or T1 (PORTB.1) pin.
- In counter all the register of timer like TCNTx, TCCRx, TIFR, etc are used as same.
- Just different is of clock select bit CS02, CS01 and CS00 of TCCR register.
REGISTERS ARE USED TO PROGRAM TIMER AND COUNTER ARE AS FOLLOWS:
- We load the value to this register and timer run up to this value and after this value timer rolls over and over flow flag is raised
- FOC = force output compare (for wave form generation)
- COM1 & COM0 = compare output mode (waveform generation)
- TOV = Timer over flow bit is 1 mean overflow occur, 0 mean not overflow
- OCF = output compare flag, 1 mean occur, 0 mean compare match not occur
- ICF = input capture flag (wave form generation)
- OCF1A = output compare flag, 1 mean occur, 0 mean compare match not occur for timer 1 (16 bit)
- OCF1B = output compare flag, 1 mean occur, 0 mean compare match not occur for timer 1 (16 bit)