Someone told me 16 PWM outputs per cycle could generate a decent filtered sine wave. If PBP can handle a much lower 20-KHz (50-usec) interrupt (with 20-MHz clock), maybe we could get Hank to check out the waveforms on his scope? For 16 outputs per cycle he could use an Fout frequency of 20000/16=1250-Hz. For 20 outputs per cycle he could use an Fout frequency of 20000/20=1000-Hz.
So how would you PBP gurus convert this DDS engine for Hank's 20-MHz 16F690 to PBP (Accum and Phase are 24-bit variables)?
We'd also need a 256 element sine table with PWM values of 0..250. Here's the output from my handy dandy Sine PWM Table Generator;Code:// // setup CCP in PWM mode for 20-KHz (50-usecs) with prescale 1, // postcale 1, and PR2=250-1 (20-MHz clock) // // Fdds = 1 / 0.00005 = 20000 Hz // Fres = 20000 / 2^24 = 0.0011920928955078125 // Phase (1250-Hz) = INT(1250 / 0.0011920928955078125 + 0.5) = 1048576 // Phase (1000-Hz) = INT(1000 / 0.0011920928955078125 + 0.5) = 838861 // void interrupt() // { pir1.TMR2IF = 0; // clear TMR2 interrupt flag Accum = Accum + Phase; // add phase offset to Accum ccpr1l = sine[Accum >> 16]; // setup next PWM duty cycle }
Code:Number of steps: 256 Output range: 250 Table or Array: a 125,128,131,134,137,140,143,146 149,152,155,158,161,164,167,169 172,175,178,181,183,186,189,191 194,196,199,201,204,206,208,211 213,215,217,219,221,223,225,227 228,230,232,233,235,236,237,239 240,241,242,243,244,245,246,246 247,248,248,249,249,249,249,249 250,249,249,249,249,249,248,248 247,246,246,245,244,243,242,241 240,239,237,236,235,233,232,230 228,227,225,223,221,219,217,215 213,211,208,206,204,201,199,196 194,191,189,186,183,181,178,175 172,169,167,164,161,158,155,152 149,146,143,140,137,134,131,128 124,121,118,115,112,109,106,103 100,097,094,091,088,085,082,080 077,074,071,068,066,063,060,058 055,053,050,048,045,043,041,038 036,034,032,030,028,026,024,022 021,019,017,016,014,013,012,010 009,008,007,006,005,004,003,003 002,001,001,000,000,000,000,000 000,000,000,000,000,000,001,001 002,003,003,004,005,006,007,008 009,010,012,013,014,016,017,019 021,022,024,026,028,030,032,034 036,038,041,043,045,048,050,053 055,058,060,063,066,068,071,074 077,080,082,085,088,091,094,097 100,103,106,109,112,115,118,121
Bookmarks