Function and frequency generator with SX chip
I would like to know if the SX chip can put out an accurate Frequency. I need to be able to build a frequency generator from about 500hz to 20khz. I am using the BS2 but man I can't get an accurate frequency out of it. The scope is all over the place. If I switch to a crystal would it help or should I try to use the SX chip for my project. I will use a LCD display and want to use a keypad for programing the frequenies or even a pot to adjut it. I also have to run a programed set of frequencies. ican do it with the BS2 but it's not accurate . I need precise control. I am new and the SX looks harder to write code the STamp.. Thanks
![freaked.gif](http://forums.parallax.com/images/smilies/freaked.gif)
Comments
20MHz will give you 40Hz resolution at 20KHz.
50MHz will give you 16Hz resolution at 20KHz.
(Assuming you want square waves)
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
Post Edited (Bean (Hitt Consulting)) : 6/6/2007 12:34:34 AM GMT
One alternative is a DDS chip like the AD9834. The resolution is fractional Hertz over a large range, e.g. 0.004 hertz resolution from 0 hz to 500khz. There is some code and info in threads here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
http://www.myplace.nu/avr/minidds/index.htm
http://www.rhoent.com/examples.htm
Rick
http://forums.parallax.com/showthread.php?p=549275
Here is a completed project using a DDS chip, with a link to an economical PCB and PBASIC code:
www.parallax.com/html_pages/resources/custapps/app_digsyndevcon.asp
Note that when you use a lower master clock frequency, you get a lower maximum frequency but better resolution in the range covered.
There is a whole family of chips, AD98xx.. Also google search for DDS or AD98 at search.parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 6/6/2007 4:07:18 PM GMT
This program will get you less than 1 hz resolution at 20Khz with a 50MHz clock.
[noparse][[/noparse]edit] Note a newer version of this program is posted further down...
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
Post Edited (Bean (Hitt Consulting)) : 6/7/2007 2:38:49 PM GMT
It should be noted that the Propeller can generate a 500 hz to 20 khz square wave from a counter module in NCO mode, with very little jitter, and with 99.999% of the processor power available for other functions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
If you need it I can probably come up with some code that will just let you specify the frequency you want and it will compute the values. So you could do something like "SetFreq 20001".
Let me know if you need it.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
The propeller works in much the same way as the DDS60/AD9851 DDS. There is a 32 bit phase accumulator that is updated on every clock cycle by adding the phase advance "tuning word", which is a value loaded into a register and possibly modulated. The AD9851 has a single phase accumulator, while the propeller has 16 of them in the dedicated counter modules. The control word for a DDS or for the Prop NCO are calculated in essentially same way. If you get into it, there are application notes and help in the Propeller forum.
The AD9851 has a built-in lookup from phase to SIN(phase), and it outputs the sinus as an analog value. It is capable of attaining RF frequency SIN output at a programmable level. The Propeller requires extra resources (hardware or software) to make an analog waveform, but for output of a square wave they are almost the same, the most significant bit of the phase accumulator. The clock cycle on the AD9851/DDS60 is pumped up to 180mhz in a phase lock loop, 6 times the 30mhz reference, while the propeller PLL pumps up its clock frequency to typically 80 megahertz. The higher the clock frequency, the less the jitter. The NCO achieves most frequencies by jittering back and forth between two frequencies that are close on either side of the target frequency, and you can anticipate the level of jitter by looking at the graphs on the data sheets. Again, a higher clock frequency in relation to the target output frequency, or the longer the phase accumulator in relation to the output period, the less the jitter.
P.S. Also check out SX 2007 contest winner,
www.parallax.com/sx/sxcontest06/freqsweep.asp
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 6/7/2007 5:14:51 AM GMT
But I got it working. Problem is there is a division of 800,000,000 by the frequency, so that took awhile to code.
There is a subroutine called SetFreq, you just pass it the frequency you want (382 to 65535) and it does the rest.
Frequencies up to 24414·should be within 1 Hz.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
looks like a great job on the programming. My SX is coming in the mail here in a few days. I'm just learning this stuff myself.
It looks like you just wrote half of what I'm trying to do. I'm trying to build a frequency to frequency converter that listens to an input freq and either slows it down or speeds it up.·The amount of offset would need to be adjustable by a pot or another form of input device.
Any advice or ideas on this?
Thanks,
Alex
I too am looking for a solution to drive my stepper motor at a LFO. Without Microstepping I need a Frequency of 0.1 Hz to 5KHz with 0.1 Hz resolution.· But I need less than 1% error.
I only have experience with the BS2.
I thought of inputing a 16bit value as a time delay and have something like:
'Input Delay
Top:
High 1
Pause Delay
Low 1
Pause Delay
'check for new delay value
Goto Top
I dont know assembly and hate to buy the propeller just to generate squarewave pulse alone. A $2 pic sounds like the way to go but where can I learn to program them? Do I need an expensive programmer to upload the code to the chip? Would I need an external crystal?
I do need LCD output and Keypad input so maybe the propeller is the way to go.
Thanks in advance
Steve
That kind of precision is relatively difficult.