Correct Pin 3 output to scale to the reduced comparator size.

This commit is contained in:
Stephen Olesen 2015-07-02 19:57:32 -06:00
parent 6ff2791963
commit 77a8c62b78
1 changed files with 3 additions and 3 deletions

View File

@ -140,13 +140,13 @@ uint8_t DDS::getDutyCycle() {
uint8_t phAng; uint8_t phAng;
#endif #endif
phAng = (accumulator >> ACCUMULATOR_BIT_SHIFT); phAng = (accumulator >> ACCUMULATOR_BIT_SHIFT);
int8_t position = pgm_read_byte_near(ddsSineTable + phAng)>>(8-COMPARATOR_BITS); int8_t position = pgm_read_byte_near(ddsSineTable + phAng); //>>(8-COMPARATOR_BITS);
// Apply scaling and return // Apply scaling and return
int16_t scaled = position; int16_t scaled = position;
// output = ((duty * amplitude) / 256) + 128 // output = ((duty * amplitude) / 256) + 128
// This keeps amplitudes centered around 50% duty // This keeps amplitudes centered around 50% duty
scaled *= amplitude; scaled *= amplitude;
scaled >>= 8; scaled >>= 8+(8-COMPARATOR_BITS);
scaled += 128; scaled += 128>>(8-COMPARATOR_BITS);
return scaled; return scaled;
} }