On Tue, 25 May 2004, Jason Harper wrote: > No PIC (that I'm aware of) has real analog outputs - you'll need to produce > a PWM output (on/off at varying duty cycles) at a significantly higher > frequency than the highest you need to generate, and filter it externally. Jason, Your advice for Peter is very good. Specifically, I think your suggestion of synthesizing the total waveform from the three individual sine waves and then using the PWM peripheral as an analog output is the best way to approach this problem from a PIC perspective. I can add only a couple more suggestions. First, the three frequencies are best generated with a phase accumulator. In it's simplest form it would look something like this: f1 = f1 + delta_phase1; f2 = f2 + delta_phase2; f3 = f3 + delta_phase3; Where f_i are the frequencies and delta_phase_i the amount the frequencies are advanced at each accumultation interval. This snippet of code is called at a constant rate. Now, the trick here is that the delta_phase needs to be chosen such that the frequency variable will roll over at the rate desired. For example, if these variables are all 16-bits wide and this code is called every 33uS, then to generate a 100Hz frequency you want the delta_phase to be: delta_phase = 65536 counts/rollover * 100 rollovers/second * 33 uS/update = 216.27 counts/update You'd probably round this 216. To see that this works, you can try repeatedly adding 216 to f1 and you'll see that after 303 iterations that f1 will rollover. 303 iterations with 33uS/iteration means that f1 rolls over in about 10 mS, which is the period for a 100Hz rollover. BTW, if you examine the top bit of your frequency variable, it'll be a square wave with that frequency. The next bit will be the second harmonic, etc. Second, for the sine wave generator, Peter may wish to consider: http://www.dattalo.com/technical/software/pic/sine18.asm This routine has been designed to take as it's input a phase accumulator like the one described above. The output is of course the sine wave. To make this all work, I'd design the software such that the PWM interrupt routine (which occurs at a constant rate), accumulates the three frequencies, computes the three sine waves, and combines them into one ~10-bit number and finally uses that value for the *next* PWM interval. I'd estimate that around 200 instruction cycles are required to perform all of this arithmetic. An 18F running at 40MHz can do this in about 20 uS. So depending on other system requirements, a realistic PWM update rate would be 30uS (or 33uS like above :). Scott -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu