PIC + DDS = Frequency Synthesizer?

I asked a friend to post to this forum about desinging a PIC-based PWM. Now that I have joined this forum, I'll get more specific about my requirements. Thanks by the way for all your interesting and informative responses.

What I am trying to do is make a frequency synthesizer that will output 1Hz to say 40kHz in 1Hz resolution. I need to input via a keypad, and have an LCD display show me the inputted frequency. I know virtually zero about assembly language! I am presently programming PICs with PicBasic Pro. That's the first hurdle - if I can either program this in BASIC or cut-n-paste assembly code in areas that need fast excecutuion then that's fine.

I have seen examples whereby one can make a PIC act like an Numerical Controlled Oscillator (NCO), and one gets a cheap DDS. Cost is an issue, so the cheaper and simpler the better. I do not mind using 2 x PICs for the interface and control. The output frequency need only be stable to +/-0.1 Hz.

I am totally new to DDS (Analog Device IC's, etc.) so that is hurdle #2.

I would appreciate any information you can offer. I apologize in advance if I ask some basic questions! Thanks kindly! Russ >:)

Reply to
RussT
Loading thread data ...

"RussT" schreef in bericht news: snipped-for-privacy@posting.google.com...

Take a look at this page:

formatting link

AVR's are faster than PIC, at a given clock frequency. Also, the AVR has some very convenient instructions for table lookup, making a software DDS more practical compared to PIC.

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)
Reply to
Frank Bemelman

Hi, you will never get that resolution by just using a pic. There are several synth chips around, use 1 of those.

Reply to
CBarn24050

You're welcome.

The post I saw, from Richard posting as "The Mind Factory INC", specified 0 - 20 kHz. If you do this with a PIC and no hardware DDS, you will probably need to run it at least 2 MIPS (8 MHz clock, I think), in order to get enough instructions per transition. This is not a concern if you use an external hardware DDS.

Two software only techniques were mentioned, constant clock and variable clock. I was recommending the variable clock, since it can produce lower jitter, but the other is simpler.

? I need to input via a

It should be a good learning exercise. ;-)

Stability is specified change in the output over changes in another variable. For frequency, this is usually vs. a temperature range, supply voltage, or deterioration over time. Stability without the variable being changed has no meaning.

If you mean accuracy, rather than stability, this will primarily depend on the accuracy of your reference frequency. If you are using a software-only implementation, it would be the processor oscillator accuracy. If you want 40 kHz to be accurate to 0.1 Hz, you are asking for for 2.5 ppm accuracy. A standard crystal isn't that accurate. You can buy TXCOs (temperature controlled oscillators) which can achieve this. They usually provide a means to fine tune the oscillator.

The DDS will typically provide a signal with less jitter because it will run at a higher clock frequency than you can achieve with a PIC. As far as how to interface or use a DDS, you can ask specific questions here.

In general, the external DDS solution will give less jitter (a more pure signal) and will be easier to program, but will cost more. In contrast, the processor only solution will give you a good programming exercise. ;-)

Here's a hint: the more specific question you ask, the better and more relevant the responses are likely to be.

Thad

Reply to
Thad Smith

snipped-for-privacy@sotainstruments.com (RussT) wrote in news: snipped-for-privacy@posting.google.com:

I wrote an article for Analog Devices that uses a low cost DSP. A DSP and a low cost 96k sigma delta DAC could give you a 1 Hz to 40k synthesizer with very low distortion. There is a link on our homepage:

formatting link

--
Al Clark
Danville Signal Processing, Inc.
--------------------------------------------------------------------
Purveyors of Fine DSP Hardware and other Cool Stuff
Available at http://www.danvillesignal.com
Reply to
Al Clark

In order to generate a sine signal at the maximum frequency f, you need to update the DAC at least twice during each cycle, however, in order to be able to filter out the aliases, the update frequency has to be at least 2.5f to 3f. Thus, in this case the update rate has to be at least 100 kHz, thus the software calculation loop cycle time must be _exactly_ 10 us, thus, if the processor runs at 2 MIPS, there are 20 instructions available to update the phase accumulator, do the sine(x), lookup and control the DAC.

However, if the frequency step needs to be exactly 1.0 Hz, then the phase accumulator has to have at least 17 bits and be clocked at

131.072 kHz and a new value must be outputed every 7.62939453125 us, thus with a 2 MIPS processor speed 15.258... instructions are available. In practice you would have to tune the CPU crystal frequency in order to have an integer number of instructions for each software loop cycle.

If no high frequency timer interrupts or a free running hardware counters are available, then the software calculation loop must contains exactly the same amount of CPU clock cycles during each iteration. This means no conditional branching (other than constant loop counting) or if a conditional loop is used, in cases the branch is _not_ taken, some dummy instructions must be included that consumes_exactly_ the same number of clock cycles as the other path when the conditional branch is taken.

How you are going to handle the keyboard and display during the available 15 instructions in addition to the DDS is a mystery. You can not simply handle these every 100th main loop iteration, since this would upset the timing.

Then I suggest that you should learn it before going any further with this project.

It might be doable if the phase accumulator increment is transferred through parallel ports from one controller to the other and the parallel ports can be read with a single instruction (to avoid race conditions, if the user interface is currently changing the value).

I would really suggest that you should look for a faster processor, preferably with a high frequency timer interrupt (in which case the DAC can be written during the interrupt service routine without too much jitter) or at least contain a free running high resolution counter (and use a busy wait to wait for a specific value to be reached). By using these kinds of tricks, the actual calculation time does not have to be _exactly_ the cycle time, but now it can (and must) be shorter than the DAC update interval. Paul

Reply to
Paul Keinanen

The specification of stabilitiy is ambiguous unless you give some averaging period over which the measurements of frequency are taken. It is easy to make a programmable signal generator, 1 Hz to 40 kHz in steps of 1 Hz with 0.1 Hz stability if the averaging periods are 10 seconds. There would just be a lot of short-term jitter. But if the averaging periods are 10 msec, then you would need a lot of extra hardware to help out the PIC to produce that kind of stability. Perhaps you could restate the requirements and explain your application more clearly. This would help to understand what sort of averaging period is appropriate in evaluating the performance of the signal generator.

By the way, the term "DDS" is not usually applied to the generation of a square wave signal, but rather to the generation of an analog waveform, like a sine wave, using table-drive DAC lookups.

-Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)

Reply to
Robert Scott

***Sorry for the misuse of wording! I was visualizing seeing the output squarewave on a frequency counter and I thought it would be good not to see the 1Hz digit jumping around. I saw this as "instability". But you are correct that 0.1Hz accuracy is a better definition of what I am looking for.

So, from all these threads I think that a DDS chip is what I need. Perhaps AD9833? It is the cheapest, and has a "simple" serial interface. I do not know much about interfacing so it might not be simple to me. :>)

***I have been monkeying around with MeLabs PIC Basic Pro (PBP). This allows me to get the PIC up and running and has served my needs extremely well. My issues are what I need to do to program the DDS. Specifically, how do I get the PIC to talk to the DDS using BASIC commands? PBP has commands like SERIN, SEROUT etc. that seems to me to be the command I need. Do I simply output SEROUT on say PORTA.1? How do I initialize the DDS? Let's say I use a 4MHz oscillator on the DDS, and want a maximum 50kHz output. AD's interactive tool tells me that the codewords will be 2100 7333 40CC 8000 9000 C000 E000 2000. What BASIC code gets this word to the DDS from the PIC, if this is the codeword that is used? Do I have to run other code first? I really don't have a clue.

I think I can work my way around the keypad and LCD interfacing. I was thinking of using 2 x PICs + DDS. The first PIC does the keypad and LCD, and sends a SEROUT command to the second PIC to pass on the desired frequency as inputted. The second PIC only interfaces with the DDS and nothing more. Would I use the SERIN command on the 2nd PIC and have it waiting and listening for the data from #1 PIC? OK, do I setup a loop to scan the port?

Also, can all PICs and the DDS run off the same 4MHz crystal? or does each chip need their own crystal?

BTW, why do posts to this forum take 3-9 hours to post? Seems very strange.

So, hope this provides more detailed info. I am learning as I go here, so I might not know what questions to ask next. Thanks again for your patience and help!! Much appreciated. Russ :>)

Reply to
RussT

***Yes, I did come across this! OK, can one program a PIC in a similar fasion? Even though the PIC is slower, could it yield acceptable results...perhaps 1Hz-20kHz in 1Hz steps? If not then I will bite the bullet and use a DDS. Thanks! Russ :>)
Reply to
RussT

snipped-for-privacy@sotainstruments.com (RussT) wrote in news: snipped-for-privacy@posting.google.com:

Russ:

If you are going to use a DDS chip, I would reconsider a DSP/DAC solution instead of a PIC/DDS solution. ADI assembly language is very easy to learn.

You have stated that you only want to go to 40kHz. What distortion performance are you looking for? A digital audio DAC with a DSP will give you very good distortion specs, much better than a DDS chip.

OTOH, a DDS chip can be used for much higher frequency range.

There is a DDS-DSP application note on the ADI web site.

Our DSP-8300 small module can do what you want to a 20kHz range. We have sample code. It would be easy to adapt the software to your requirements by substituting the AC'97 codecs with a 96k digital audio DAC.

--
Al Clark
Danville Signal Processing, Inc.
--------------------------------------------------------------------
Purveyors of Fine DSP Hardware and other Cool Stuff
Available at http://www.danvillesignal.com
Reply to
Al Clark

"RussT" schreef in bericht news: snipped-for-privacy@posting.google.com...

Do you want a square-wave or a sine-wave? If sine-wave, you need a lookup-table, and with 256 entries in your LUT, you will have to skip samples at 20KHz. An alias-filter will help to remove the steps. For audio purposes, an 8 bit LUT/DAC is not enough, you will hear all kinds of funny noises, even at 15KHz, where you expect to hear almost nothing but a very high tone. You also need an alias filter that changes it's cutoff frequency, or else you will hear funny noises at 20Hz etc. A 16 bit ADC is better ;) If you only want a square wave, things are a lot easier.

You can get 20KHz out of a PIC DDS, assuming a 20MHz PIC and a tight DDS accumulator loop. Don't attempt to program the loop as a timer interrupt, it will be too slow. But an AVR is highly recommended.

Been there, done that:

formatting link
where you can find more information on a DDS using an AVR.

For a better audio sinewave, you better use a AD9834 that uses an internal 12bit LUT and DAC.

OTH, the PIC or AVR route is a great learning experience.

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)
Reply to
Frank Bemelman

"RussT" schreef in bericht news: snipped-for-privacy@posting.google.com...

Put simply, it's like sending sort of a 'morse code' to the DDS chip. You have to convert the code words to bits, set an output low or high depending the bit you want to sent, and the generate a clock pulse using another output. This way you can load the entire code word, bit by bit, until all bits are transferred. This will not work in one go, and you will get surprising result. But after a couple of hours messing around, you will probably be able to put all those code words into the DDS.

With a DDS chip, the loading of the keywords isn't much extra work. It is probably more difficult to get two pics communicating properly, than to just load that DDS chip with the correct data.

I guess you can hookup the DDS to the output drive of the PIC's crystal, but I would use a seperate crystal for the DDS, as fast as possible. It will increase the quality of the signal produced.

? Ask your provider?

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)
Reply to
Frank Bemelman

Let's do a little math here:

First, let's assume first that you want to go for pure DDS (Digital in all sense), meaning you won't rely on an analog filter to remove aliasing effects.

For an 8-bit precision sine output (meaning the smallest step on the output is 1/256th of the full-scale) you would need ~0.22deg. of phase resolution, or in other words you would have to generate 1602 samples per cycle. This would give you 48dB of signal-to-noise ratio. For 12-bit resolution you would need 25736 samples per cycle and would achieve 72dB of SNR.

Now, for your 40kHz specification this would mean a 64MHz update rate for

8-bit and 1.029GHz for 12-bit resolution. I don't think either of this would be possible with a PIC. The first one is probably doable with an ADI fixed point DSP, but a small FPGA would surely do the trick. The second one would not be possible without special-purpose and expansive ICs.

If you don't mind having an analog filter, you can get much more reasonable specifications but you would rely on your analog circuitry to give you the precision and noise you need.

As others pointed out one easy path would be to use a sigma-delta converter with 96kHz sampling rate. That would have a high-precision converter and an integrated filter to provide a smooth output signal. However that would generate nothing but sine at 40kHz.

I think to decide what you need to do you should come up with numbers for the following:

- Required signal bandwidth (or maximum output slew-rate)

- Required signal to noise ratio

Regards, Andras Tantos

Reply to
Andras Tantos

Yes, having the units digit "jumping around" is an indication of short term instability, but probably a poor way to go about determining your requirements.

Accuracy is a more stringent requirement that stability. I honestly don't know what you are looking for. What determines you frequency range, accuracy, resolution, and signal purity requirements?

I haven't looked at the data sheet, but you should be able to connect the DDS control lines to I/O lines on the PIC. The easiest way to send data serially is probably to write a subroutine to set the data bit on the data line, pulse the clock line, then repeat until all bits have been sent, then pulse a strobe line. It might be possible to use some internal serial peripheral for that, I don't know.

Just set one output line at a time, looping through all the bits you want to send. In general, make sure that you program all the required registers.

That's the third number I have seen for the upper frequency limit. Sounds like a little stability in requirements is called for. ;-)

I think you should be able to handle everything with a single PIC, assuming that you have enough I/O lines, especially if you use an external DDS, which, once set, will continue to generate the requested frequency.

You should be able to use a single oscillator. To reiterate an earlier point, if you really need 0.1 Hz accuracy from 40 kHz, you need to go to a precision oscillator, not a simple crystal. If 50 ppm is sufficient, you can probably use a simple crystal, but your accuracy will be less. Thad

Reply to
Thad Smith

***Yes agreed. My application is to produce squarewaves, not sines. I forgot to clarify that. I just thought I would Schmidt Trigger the sines to get squares. Having said that, is there an easier way to generate 50% Duty Cycle squarewaves? Russ :)

address is fake.)

Reply to
RussT

***Actually this message came from Google! I quote: "Your message has been posted. Your message has been posted to Usenet. Please note that it may take anywhere from 3 to 9 hours for your message to appear on Google Groups. The text of your message is included below for your convenience. Return to Google Groups". That is why I asked. :>)
Reply to
RussT

***I am sorry I did not mention it but I am actually looking to generate 50% Duty Cycle Squarewaves, not sine waves. Having said that, is the DDS still the way to proceed? Thanks! Russ :>)
Reply to
RussT

Same principle, but you don't need a LUT, just use the MSB of the calculated index you would use to acces the LUT. That saves a lot of time, such a software DDS would result in a much shorter accumulator loop, and therefore reduce jitter.

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)
Reply to
Frank Bemelman

***Yes, 50% Duty Cycle Squarewaves.
***Hmmm, I would not know how to program the PIC...any sample code?

Don't attempt to program the loop

***What exactly is an AVR? Thanks, Russ :>)

Reply to
RussT

If you just need square waves, a smal CPLD does the job. Take one with 64 or 128 Flipflops and have it running with a few dozend MHz. Just make auto-reload counters counting down or up. Then have a few registers for the period. My website has a few examples :

formatting link

Rene

--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com
& commercial newsgroups - http://www.talkto.net
Reply to
Rene Tschaggelar

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.