-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastPWMdac.cpp
More file actions
28 lines (21 loc) · 836 Bytes
/
FastPWMdac.cpp
File metadata and controls
28 lines (21 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
FastPWMdac
For the output pins that can be used see: http://www.pjrc.com/teensy/td_libs_TimerOne.html
The library <TimerOne.h> has to be installed too
https://github.com/PaulStoffregen/TimerOne
Version 19-12-2015
*/
#include <TimerOne.h> // this library has to be installed
#include "FastPWMdac.h"
void FastPWMdac::init(byte _timer1PWMpin, byte resolution)
{ timer1PWMpin = _timer1PWMpin;
if(resolution == 8) Timer1.initialize(32);
if(resolution == 10) Timer1.initialize(128);
Timer1.pwm(timer1PWMpin, 0); // dummy, required before setPwmDuty()
}
void FastPWMdac::analogWrite8bit(byte value8bit)
{ Timer1.setPwmDuty(timer1PWMpin, value8bit*4); // faster than pwm()
}
void FastPWMdac::analogWrite10bit(int value10bit)
{ Timer1.setPwmDuty(timer1PWMpin, value10bit); // faster than pwm()
}