2 * Copyright Droids Corporation, Microb Technology, Eirbot (2006)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: timers.h,v 1.1.2.4 2009-01-23 23:54:16 zer0 Exp $
23 * This file contains definitions used for timer use
25 * In the future, most of definitions will be added in autogenerated
26 * files from atmel's documentation (aversive/parts.h and
27 * aversive/parts/ATxxxx.h) which are not timer specific.
30 /* XXX won't be needed : use parts.h */
32 #ifndef _AVERSIVE_TIMERS_H_
33 #define _AVERSIVE_TIMERS_H_
36 #define TIMER_8_MODE_NORMAL 0
37 #define TIMER_8_MODE_PWM_PC 1 // phase correct PWM
38 #define TIMER_8_MODE_CTC 2
39 #define TIMER_8_MODE_PWM 3 // fast PWM
41 #define TIMER_16_MODE_NORMAL 0
42 #define TIMER_16_MODE_PWM_PC_8 1 // phase correct PWM 8 bits
43 #define TIMER_16_MODE_PWM_PC_9 2 // phase correct PWM 9 bits
44 #define TIMER_16_MODE_PWM_PC_10 3 // phase correct PWM 10 bits
45 #define TIMER_16_MODE_CTC1 4 // clear on compare, TOP = OCRA
46 #define TIMER_16_MODE_PWM_8 5 // fast PWM 8 bits
47 #define TIMER_16_MODE_PWM_9 6 // fast PWM 9 bits
48 #define TIMER_16_MODE_PWM_10 7 // fast PWM 10 bits
49 #define TIMER_16_MODE_PWM_PFC1 8 // PWM, Phase & Freq Correct
50 #define TIMER_16_MODE_PWM_PFC2 9 // PWM, Phase & Freq Correct
51 #define TIMER_16_MODE_PWM_PC1 10 // PWM, Phase Correct
52 #define TIMER_16_MODE_PWM_PC2 11 // PWM, Phase Correct
53 #define TIMER_16_MODE_CTC2 12 // clear on compare, TOP = ICR
54 #define TIMER_16_MODE_PWM_F1 14 // fast PWM
55 #define TIMER_16_MODE_PWM_F2 15 // fast PWM
58 // ATMEGA128 ////////////////////////////////////////
59 #if defined (__AVR_ATmega128__)
64 #define OCR1A_DDR DDRB
66 #define OCR1B_DDR DDRB
68 #define OCR1C_DDR DDRB
72 #define OCR3A_DDR DDRE
74 #define OCR3B_DDR DDRE
76 #define OCR3C_DDR DDRE
82 // ATMEGA1281 ////////////////////////////////////////
83 #elif defined (__AVR_ATmega1281__)
86 #define OCR0A_DDR DDRB
88 #define OCR0B_DDR DDRG
90 #define OCR1A_DDR DDRB
92 #define OCR1B_DDR DDRB
94 #define OCR1C_DDR DDRB
96 #define OCR2A_DDR DDRB
98 #define OCR3A_DDR DDRE
100 #define OCR3B_DDR DDRE
102 #define OCR3C_DDR DDRE
107 // ATMEGA32 ////////////////////////////////////////
108 #elif defined (__AVR_ATmega32__) || defined (__AVR_ATmega323__)
110 #ifdef __AVR_ATmega323__
118 #define WGM12 3//CTC1
119 #define WGM13 4 // reserve bit
128 #define OCR0_DDR DDRB
130 #define OCR1A_DDR DDRD
132 #define OCR1B_DDR DDRD
134 #define OCR2_DDR DDRD
138 // ATMEGA8 ////////////////////////////////////////
139 #elif defined (__AVR_ATmega8__)
142 #define OCR1A_DDR DDRB
144 #define OCR1B_DDR DDRB
146 #define OCR2_DDR DDRB
151 // ATMEGA163 ////////////////////////////////////////
152 #elif defined (__AVR_ATmega163__)
161 #define WGM13 4 // reserve bit
164 #define OCR1A_DDR DDRD
166 #define OCR1B_DDR DDRD
168 #define OCR2_DDR DDRD
172 // ATMEGAx8 ////////////////////////////////////////
173 #elif defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__)
176 #define OCR0A_DDR DDRD
178 #define OCR0B_DDR DDRD
181 #define OCR1A_DDR DDRB
183 #define OCR1B_DDR DDRB
186 #define OCR2A_DDR DDRB
188 #define OCR2B_DDR DDRD
193 //#error No timer/prescaler definitions for your AVR type