Sinewaves using interrupts.
I'm looking at scalerobotics (thanks Walter!) funky article wrt generating sine waves using DT's interrupts (in my nerdy-esque secret world - this has popped into "No1 slot" in my interest table!)
I (think) I've grasped the concept - we're using timer1 to generate a precise interrupt ...at each interrupt, read a preset value from an array & this value is used to control a PWM stream, which if put through the correct filter, will produce a sine wave (have I got that bit right?)
How granular do you think it's possible to go with the frequency - let's say if generating frequencies between 80Hz & 5Khz? (eg one decimal point, two decimal points ....no decimal points!)
Also, I'm no filter expert...but what bandwidth can you get away with when using just the one simple RC filter? (ie max range of frequencies, again say starting at 80Hz)
Also, if wantng to phase shift (vs an incoming signal) how granular could the phase shift 'steps' be?
What I'm possibly thinking of doing, is to extract the frequency from an incoming guitar signal, then 'PIC generate' other sine wave frequencies from it (eg double the incoming guitar frequency) - but for maximum sonic flexibility, I have an intended use that rather than change the incoming frequency, (ie generate the same PIC generated sine frequency as the incoming guitar note), only shift the phase vs the original incoming signal.......do-able, or is this getting too taxing for a PIC?
thanks!
Re: Sinewaves using interrupts.
Ok, old thread of mine & hands up...short of dabbling with scalerobotics cool sinewave generation program I never actually progressed much further - but I keep coming back to this DDS issue....I reckon I can do so much cool stuff once I've mastered the art of generating sine waves under my control
Now I'm never the brightest button in the sewing box, but I do have dogged determination (rough translation "a pest")...I'll often kludge my way through without necessary understanding every part of the process - So with this in mind, I hope to start soon again on this pesky DDS melarky.
So some questions.....
all this talk of a 24 bit accumulator - how do I achieve that on a 12LF1822 with PICbasic?!!!
Would up to 4.8Khz be do-able in HPWM for the DAC aspect?
Can I really expect to get granular with setting the frequency without recourse to floating point? (I want to be able to set the frequency via another PIC by fiielding an Eusart interrupt to the DDS PIC)
There are those on the net, that have done this with other processors. The Atmel AT90S2313 seems to figure large due to the lower number of clock cycles it takes per instruction. This chap has posted a great webpage...
http://www.myplace.nu/avr/minidds/index.htm
Including code....
http://www.myplace.nu/avr/minidds/minidds.asm
for those that have a clue (rules me out), how much of an ordeal would it be to move that over to a PIC?
Is this a project where I really ought to start learning assembly?
Re: Sinewaves using interrupts.
Hi Hank,
Note that the avr project needs at least 8 I/O pins to drive the resistor ladder(DAC). So with a PIC12f series you are stuck using PWM, serial DAC or a dedicated DDS chip.
I tried a spi DAC, too slow. Couldn't get over 600hz. It wouldn't be too hard to do the avr dds with a pic. Use a look up table and a loop and write each value to an 8bit port. Not sure how the speed would compare with an AVR?
This is the best, but it is expensive
http://www.sparkfun.com/products/9169
I wrote some code for this in PBP if you are interested.
cheers
Re: Sinewaves using interrupts.
Hi Mark,
Agreed about the 12lf1822's 6 Inputs & 5 outputs being insufficient for a resistor ladder ...I therefore have three options...
1. Use HPWM
2. Use the 12lf1822's internal 5 bit DAC (which while woeful, is handy from a low parts count & convenience/learning perspective)
3. Go with a larger 14 pin sibling (eg 16lf1824) & use a reistor ladder.
As much as I'd really like to just use the dedicated DDS chips, but they're way overkill for my modest needs, too expensive & also I'd like to lean how to roll my own so to speak.
Just sounding the ground again here.