Added a define to use pin 3 for PWM, instead of the new default pin 11.

This commit is contained in:
Stephen Olesen 2015-07-01 15:01:55 -06:00
parent 8f2115adbc
commit 016ad2398a
2 changed files with 11 additions and 0 deletions

View File

@ -10,8 +10,14 @@ void DDS::start() {
// First, the timer for the PWM output // First, the timer for the PWM output
// Setup the timer to use OC2B (pin 3) in fast PWM mode with a configurable top // Setup the timer to use OC2B (pin 3) in fast PWM mode with a configurable top
// Run it without the prescaler // Run it without the prescaler
#ifdef DDS_PWM_PIN_3
TCCR2A = (TCCR2A | _BV(COM2B1)) & ~(_BV(COM2B0) | _BV(COM2A1) | _BV(COM2A0)) | TCCR2A = (TCCR2A | _BV(COM2B1)) & ~(_BV(COM2B0) | _BV(COM2A1) | _BV(COM2A0)) |
_BV(WGM21) | _BV(WGM20); _BV(WGM21) | _BV(WGM20);
#else
// Alternatively, use pin 11
TCCR2A = (TCCR2A | _BV(COM2A1)) & ~(_BV(COM2A0) | _BV(COM2B1) | _BV(COM2B0)) |
_BV(WGM21) | _BV(WGM20);
#endif
TCCR2B = (TCCR2B & ~(_BV(CS22) | _BV(CS21))) | _BV(CS20) | _BV(WGM22); TCCR2B = (TCCR2B & ~(_BV(CS22) | _BV(CS21))) | _BV(CS20) | _BV(WGM22);
// Set the top limit, which will be our duty cycle accuracy. // Set the top limit, which will be our duty cycle accuracy.

5
DDS.h
View File

@ -3,6 +3,11 @@
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
// Use pin 3 for PWM? If not defined, use pin 11
// #define DDS_PWM_PIN_3
// Use a short (16 bit) accumulator. Phase accuracy is reduced, but speed
// is increased, along with a reduction in memory use.
#define SHORT_ACCUMULATOR #define SHORT_ACCUMULATOR
#ifdef SHORT_ACCUMULATOR #ifdef SHORT_ACCUMULATOR