Project

General

Profile

Timers

Timer hardware

The ATmega128 has 4 timers/counters:

TC name Bits # Output compare registers # Output compare pins
TC0 8 1 1
TC1 16 3 3 (one shared with TC2)
TC2 8 1 1 (shared with TC1)
TC3 16 3 3
All timers support:
  • Overflow and compare match interrupts
  • Clear timer on compare match (Auto reload, CTC)
  • Phase correct PWM
  • Fast PWM

Dragonfly timer pin connections

Pin function Pin name Alternate functions Net name Function Comments
OC0 PB4 -- !IR_EN Rangefinders power switch
OC1A PB5 -- PWM_HB1 Motor
OC1B PB6 -- PWM_HB1 Motor
OC1C/OC2 PB7 -- PWM_BUZZ Da Beep
OC3A PE3 AIN1 DIO1 DIO pin 3 Analog comperator
OC3B PE4 INT4 DIO2/SCL_B DIO pin 5 External Interrupt
OC3C PE5 INT5 DIO3/SDA_B DIO pin 7 External Interrupt

Timer to function allocation

Functions:
  • The motors have to use TC1, because they are connected to OC1A/OC1B (and hardware PWM should be used).
  • The Buzzer has to use TC2 because it is connected to OC2 (and hardware frequency generation should be used).
  • The orbs cannot be shared with the motors because the motors (hardware PWM) require a PWM mode of the time, while the orbs (software PWM) require a non-PWM mode to allow for immediate OCR update (this is due to the implementation of the AVR timer modes)
Current plan:
Function Timer
Motors TC1
Buzzer TC2
Time base
Orbs TC0

Timer Uses (Old)

Timer 1 motor.c
Timer 2 buzzer.c (odometry also seems to use this)
Timer 3 time.c, orb.c