Shop OBEX P1 Docs P2 Docs Learn Events
Function and frequency generator with SX chip — Parallax Forums

Function and frequency generator with SX chip

datacpsdatacps Posts: 139
edited 2007-07-12 18:48 in General Discussion
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.. Thanksfreaked.gif

Comments

  • JonnyMacJonnyMac Posts: 8,940
    edited 2007-06-05 22:57
    If you run the SX at 50 MHz the instruction cycle is 20 nanoseconds -- if you're just generating square waves you could get very accurate output using simple ISR code.
  • BeanBean Posts: 8,129
    edited 2007-06-06 00:29
    If you use the SX48 protoboard with a·high speed·resonator, you can very easily use the built-in timer to generate the required frequencies.

    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
  • datacpsdatacps Posts: 139
    edited 2007-06-06 03:37
    Thanks Guys, Bean I need increments of 1 hz . A resolution of 1 hz,,,, do you mean I can only do 16 0r 40hz increments. If that is the case I can't use any of them or I need a bigger chip. I hope I mis-understood you. Yes I want to generate a square wave but in increments of 1 hz at a time. Is it possible with the SX.. Thanks again
  • datacpsdatacps Posts: 139
    edited 2007-06-06 03:51
    Also Bean I can get away with generating only 10khz.. If I have to .. Let me know ? I also thought the SX can clock at 74MHZ.? SHould I use another chip with the SX to get what I need??? if so what do you think?
  • datacpsdatacps Posts: 139
    edited 2007-06-06 04:24
    I found the PWMPAL what about that one. ? hop.gifyeah.gif
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2007-06-06 07:16
    The PWMPAL works at a time resolution of 25 microseconds, so unfortunately the steps would be courser than you could get with the ~25 nanosecond time resolution of the raw SX chip clocked at 40mhz. Note that the resolution at low frequencies is better, easily 1 hz resolution at 500hz and pretty close to 1 hz at 4000 hz, but it drops off to 20 hz resolution at 20khz.

    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
  • datacpsdatacps Posts: 139
    edited 2007-06-06 13:09
    Thanks! Tracy where could I find some code or more info on putting it together.. You have a great site too. !!!!
  • RickBRickB Posts: 395
    edited 2007-06-06 14:52
    Here are some examples of dds/nco function generators with the AVR and SX using a dac on a port. Up to several hundred KHz in fractional Hz increments.

    http://www.myplace.nu/avr/minidds/index.htm

    http://www.rhoent.com/examples.htm

    Rick
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2007-06-06 16:01
    This thread has some info on the interface to the Analog Devices DDS.

    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
  • BeanBean Posts: 8,129
    edited 2007-06-06 17:02
    Here is the code I was looking for...

    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
  • JonnyMacJonnyMac Posts: 8,940
    edited 2007-06-06 17:34
    That's a cool program, Terry, and a really cleaver solution.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2007-06-06 21:50
    Yes, neat program Terry. Without having to use any double precision, too!

    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
  • datacpsdatacps Posts: 139
    edited 2007-06-06 23:52
    Thanks again guys. I just order the DDS60 and a few SX chips. I am going to look at that Propeller chip too. Tracy you have any code for it to test with...Thanks again..
  • BeanBean Posts: 8,129
    edited 2007-06-07 00:10
    datacps,
    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
    ·
  • datacpsdatacps Posts: 139
    edited 2007-06-07 00:59
    Yes Bean that would be great. I am getting the proboard so I can test different chips. But I would like to use the SX chip first ..Thank you very much. I have to wait for the chips they won't ship out until the 16 of June.. Just my luck....
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2007-06-07 04:57
    datacps,

    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
  • datacpsdatacps Posts: 139
    edited 2007-06-07 10:36
    Thanks again for the infor.. right now I have the BS2 counting the rctime then sending that out as the output so i can use the pot as my tuner control. At the moment I don't want to use a key pad because I need to sweep through the frequencies by turning the pot.I only want to use square wave so I am not worried about sine waves. I am using two pots scaled to 500 to 5000 hz one for fine tuning. ... When I get the proboard I will test it too. I want to use the pbasic language because I am a newbie.· It sounds like Parallax has the solution and a chip capable of what ever I need and the support here is incredible. Thanks to everyone for your help. I am having so much fun with the stamps. I am looking forward to testing the other chips too. Thanks again. everybody..
  • BeanBean Posts: 8,129
    edited 2007-06-07 14:35
    That will teach me, this program turned out to be alot harder than I first thought.
    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
  • datacpsdatacps Posts: 139
    edited 2007-06-11 01:45
    Bean While I am waiting on my Proboard and SX chip. I need to drive an IRF720 mosfet Should I use an opto or a mosfet driver or will the SX chip drive it with no problem. I would like to isolate the chip because I will be drive a high voltage device like a coils. Also I want to use 2 pots one coarse and 1 for fine adjustment. I probably will have to add a selection switch to choose under 10khz and one for above 10Khz. Should I read a encoder instead and convert that into the Freqout output? the Freqout has to be continuously until I turn the dail . I guess you call it an interupt. I have a BS2 but that will not do the job and is why I am switching to the SX like you said I guess once I get the SX chip I can resolve my problems with freqout and scaling the pot or encoder. Thanks again
  • Alex41Alex41 Posts: 112
    edited 2007-06-17 20:13
    Bean,

    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
  • gtslabsgtslabs Posts: 40
    edited 2007-07-12 17:25
    Hi

    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
  • jb1311jb1311 Posts: 20
    edited 2007-07-12 18:48
    It looks like you want greater resolution than the % error. .1 hz / 5000 hz is .00002 or .002%

    That kind of precision is relatively difficult.
Sign In or Register to comment.