File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ FastPWMdac
3
+ For the output pins that can be used see: http://www.pjrc.com/teensy/td_libs_TimerOne.html
4
+ The library <TimerOne.h> has to be installed too
5
+ https://github.com/PaulStoffregen/TimerOne
6
+
7
+ Version 19-12-2015
8
+ */
9
+
10
+ #include < TimerOne.h> // this library has to be installed
11
+ #include " FastPWMdac.h"
12
+
13
+ void FastPWMdac::init (byte _timer1PWMpin, byte resolution)
14
+ { timer1PWMpin = _timer1PWMpin;
15
+ if (resolution == 8 ) Timer1.initialize (32 );
16
+ if (resolution == 10 ) Timer1.initialize (128 );
17
+ Timer1.pwm (timer1PWMpin, 0 ); // dummy, required before setPwmDuty()
18
+ }
19
+
20
+ void FastPWMdac::analogWrite8bit (byte value8bit)
21
+ { Timer1.setPwmDuty (timer1PWMpin, value8bit*4 ); // faster than pwm()
22
+ }
23
+
24
+ void FastPWMdac::analogWrite10bit (int value10bit)
25
+ { Timer1.setPwmDuty (timer1PWMpin, value10bit); // faster than pwm()
26
+ }
27
+
28
+
Original file line number Diff line number Diff line change
1
+ #ifndef FastPWMdac_H
2
+ #define FastPWMdac_H
3
+
4
+ class FastPWMdac
5
+ {
6
+ public:
7
+ void init (byte _timer1PWMpin, byte resolution);
8
+ void analogWrite8bit (byte value8bit);
9
+ void analogWrite10bit (int value10bit);
10
+
11
+ private:
12
+ byte timer1PWMpin;
13
+ };
14
+
15
+ #endif
You can’t perform that action at this time.
0 commit comments