source: orbit/arduino/libraries/PWM/PWM.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: 4.8 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/*
22This library is built to support two of the AVR Architecture 'groups' that Arduino uses
23a) ATmega48/88/168/328,
24b) ATmega640/1280/1281/2560/2561
25*/
26
27#ifndef PWM_H_
28#define PWM_H_
29
30#include "avr/pgmspace.h"
31#include "math.h"
32
33#if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
34        #include "utility/ATimerDefs.h"
35#elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
36        #include "utility/BTimerDefs.h"
37#endif
38
39
40
41#if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
42// 16 bit timers
43extern uint32_t GetFrequency_16(const int16_t timerOffset);
44extern bool             SetFrequency_16(const int16_t timerOffset, uint32_t f);
45extern uint16_t GetPrescaler_16(const int16_t timerOffset);
46extern void             SetPrescaler_16(const int16_t timerOffset, prescaler psc);
47extern void             SetTop_16(const int16_t timerOffset, uint16_t top);
48extern uint16_t GetTop_16(const int16_t timerOffset);
49extern void             Initialize_16(const int16_t timerOffset);
50extern float    GetResolution_16(const int16_t timerOffset);
51
52// 8 bit timers
53extern uint32_t GetFrequency_8(const int16_t timerOffset);
54extern bool             SetFrequency_8(const int16_t timerOffset, uint32_t f);
55extern uint16_t GetPrescaler_8(const int16_t timerOffset);
56extern void             SetPrescaler_8(const int16_t timerOffset, prescaler psc);
57extern void             SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
58extern void             SetTop_8(const int16_t timerOffset, uint8_t top);
59extern uint8_t  GetTop_8(const int16_t timerOffset);
60extern void             Initialize_8(const int16_t timerOffset);
61extern float    GetResolution_8(const int16_t timerOffset);
62
63#endif
64
65
66#if defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
67
68// 16 bit timers
69extern uint32_t GetFrequency_16();
70extern bool             SetFrequency_16(uint32_t f);
71extern uint16_t GetPrescaler_16();
72extern void             SetPrescaler_16(prescaler psc);
73extern void             SetTop_16(uint16_t top);
74extern uint16_t GetTop_16();
75extern void             Initialize_16();
76extern float    GetResolution_16();
77
78// 8 bit timers
79extern uint32_t GetFrequency_8(const int16_t timerOffset);
80extern bool             SetFrequency_8(const int16_t timerOffset, uint32_t f);
81extern uint16_t GetPrescaler_8(const int16_t timerOffset);
82extern void             SetPrescaler_8(const int16_t timerOffset, prescaler psc);
83extern void             SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
84extern void             SetTop_8(const int16_t timerOffset, uint8_t top);
85extern uint8_t  GetTop_8(const int16_t timerOffset);
86extern void             Initialize_8(const int16_t timerOffset);
87extern float    GetResolution_8(const int16_t timerOffset);
88
89#endif
90
91
92//common functions
93
94extern void             InitTimers();
95extern void             InitTimersSafe();                                                                               //doesn't init timers responsible for time keeping functions
96extern void             pwmWrite(uint8_t pin, uint8_t val);
97extern void             pwmWriteHR(uint8_t pin, uint16_t val);                                  //accepts a 16 bit value and maps it down to the timer for maximum resolution
98extern bool             SetPinFrequency(int8_t pin, uint32_t frequency);
99extern bool             SetPinFrequencySafe(int8_t pin, uint32_t frequency);    //does not set timers responsible for time keeping functions
100extern float    GetPinResolution(uint8_t pin);                                                  //gets the PWM resolution of a pin in base 2, 0 is returned if the pin is not connected to a timer
101
102#endif /* PWM_H_ */
Note: See TracBrowser for help on using the repository browser.