source: orbit/arduino/libraries/PWM/utility/BTimerDefs.h @ 1f70352

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since 1f70352 was 1f70352, checked in by AzureViolin <zhanghaotz@…>, 9 years ago

arduino fly Orbit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2Copyright (c) 2012 Sam Knight
3Permission is hereby granted, free of charge, to any person obtaining a copy
4of this software and associated documentation files (the "Software"), to deal
5in the Software without restriction, including without limitation the rights to
6use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7of the Software, and to permit persons to whom the Software is furnished to do
8so, subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in all
11copies or substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19*/
20
21
22#ifndef BTIMERDEFS_H_
23#define BTIMERDEFS_H_
24
25#if defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
26
27//physical memory locations used in pwmWrite()
28#define OCR1A_MEM       0x88
29#define OCR1B_MEM       0x8A
30#define OCR1C_MEM       0x8C
31
32#define OCR0A_MEM       0x47
33#define OCR0B_MEM       0x48
34#define OCR2A_MEM       0xB3
35#define OCR2B_MEM       0xB4
36
37#define TCCR1A_MEM      0x80
38#define TCCR1B_MEM      0x81
39#define TCCR1C_MEM      0x82
40
41#define TCCR0A_MEM      0x44
42#define TCCR0B_MEM      0x45
43#define TCCR2A_MEM      0xB0
44#define TCCR2B_MEM      0xB1
45
46#define ICR1_MEM        0x86
47
48//8 bit timers
49#define TIMER0_OFFSET   0x00
50#define TIMER2_OFFSET   0x6C
51
52#define TCCRA_8(tmr_offset)             _SFR_MEM8(0x44 + tmr_offset)
53#define TCCRB_8(tmr_offset)             _SFR_MEM8(0x45 + tmr_offset)
54#define OCRA_8(tmr_offset)              _SFR_MEM8(0x47 + tmr_offset)
55
56static const uint16_t pscLst[] = { 0, 1, 8, 64, 256, 1024};
57static const uint16_t pscLst_alt[] = {0, 1, 8, 32, 64, 128, 256, 1024};
58
59enum prescaler
60{
61        ps_1    =       1,
62        ps_8    =       2,
63        ps_64   =       3,
64        ps_256  =       4,
65        ps_1024 =       5
66};
67
68//certain 8 bit timers read the CSn register differently
69enum prescaler_alt
70{
71        psalt_1         =       1,
72        psalt_8         =       2,
73        psalt_32        =       3,
74        psalt_64        =       4,
75        psalt_128       =       5,
76        psalt_256       =       6,
77        psalt_1024      =       7
78};
79
80//macros for each timer 'object'
81#define Timer0_GetFrequency()   GetFrequency_8(TIMER0_OFFSET)
82#define Timer0_SetFrequency(x)  SetFrequency_8(TIMER0_OFFSET, x)
83#define Timer0_GetPrescaler()   GetPrescaler_8(TIMER0_OFFSET)
84#define Timer0_SetPrescaler(x)  SetPrescaler_8(TIMER0_OFFSET, x)
85#define Timer0_GetTop()                 GetTop_8(TIMER0_OFFSET)
86#define Timer0_SetTop(x)                SetTop_8(TIMER0_OFFSET, x)
87#define Timer0_Initialize()             Initialize_8(TIMER0_OFFSET)
88#define Timer0_GetResolution()  GetResolution_8(TIMER0_OFFSET)
89
90#define Timer1_GetFrequency()   GetFrequency_16()
91#define Timer1_SetFrequency(x)  SetFrequency_16(x)
92#define Timer1_GetPrescaler()   GetPrescaler_16()
93#define Timer1_SetPrescaler(x)  SetPrescaler_16(x)
94#define Timer1_GetTop()                 GetTop_16()
95#define Timer1_SetTop(x)                SetTop_16(x)
96#define Timer1_Initialize()             Initialize_16()
97#define Timer1_GetResolution()  GetResolution_16()
98
99#define Timer2_GetFrequency()   GetFrequency_8(TIMER2_OFFSET)
100#define Timer2_SetFrequency(x)  SetFrequency_8(TIMER2_OFFSET, x)
101#define Timer2_GetPrescaler()   GetPrescaler_8(TIMER2_OFFSET)
102#define Timer2_SetPrescaler(x)  SetPrescalerAlt_8(TIMER2_OFFSET, x)
103#define Timer2_GetTop()                 GetTop_8(TIMER2_OFFSET)
104#define Timer2_SetTop(x)                SetTop_8(TIMER2_OFFSET, x)
105#define Timer2_Initialize()             Initialize_8(TIMER2_OFFSET)
106#define Timer2_GetResolution()  GetResolution_8(TIMER2_OFFSET)
107
108#else
109
110        #error "BTimerDefs.h only supports ATMega48, ATMega88, ATMega168, ATMega328"
111#endif
112
113#endif /* BTIMERDEFS_H_ */
Note: See TracBrowser for help on using the repository browser.