Shop OBEX P1 Docs P2 Docs Learn Events
Frequencies — Parallax Forums

Frequencies

Can the COGs in a propeller be used to generate frequencies such as 440 Hz, 623 Hz, 812 Hz, and 984 Hz?

Sincerely,

Discovery

Comments

  • Yes than can. But the best way to generate these frequencies is to use the hardware timers built into each cog.

    Check this link out Propeller Counters

    Mike
  • jmgjmg Posts: 15,173
    Discovery wrote: »
    Can the COGs in a propeller be used to generate frequencies such as 440 Hz, 623 Hz, 812 Hz, and 984 Hz?
    Sure.
    You might like to look at
    AN001-P8X32ACounters-v2.0_prop.pdf

    and that gives a NCO mode for the timers, which can output square waves with fine granularity, and there are 2 timers per COG.

    fHz = SysCLK * FRQA/2^32

    so for 440Hz you would derive FRQA = (440Hz*2^32)/80MHz = 0x5C46, and actual Hz is 439.994037

    If you want Sine waves, then more code is needed eg a Direct Digital Synthesis and lookup table loop
  • I was planning to run the frequencies through band-pass filters to get sine waves but I like the Direct Digital Synthesis approach.

    I use Propbasic for programming...will this present a problem?

    Sincerely,

    Discovery
  • jmgjmg Posts: 15,173
    Discovery wrote: »
    I was planning to run the frequencies through band-pass filters to get sine waves but I like the Direct Digital Synthesis approach.

    I use Propbasic for programming...will this present a problem?
    No, it should be fine, just port code as needed.

    For ideas you could search these forums
    One example thread is
    https://forums.parallax.com/discussion/140784/sine-wave-generator

    and in that thread is some working code
    https://forums.parallax.com/discussion/comment/1112113/#Comment_1112113
  • GenetixGenetix Posts: 1,754
    edited 2019-03-23 23:40
    Discovery,

    You should really give Spin a try.
    When I first saw Spin I found it intimidating compared to PBASIC but I also found that about 75-80% was the same.
    Spin is a lot more powerful though than PBASIC ever was and all the different Objects make up for the fact that it doesn't have commands like FREQOUT.

    There is a BS2 Object in OBEX that you start with but it doesn't use any PAsm (Propeller Assembly Language) so it's slow, especially serial.
    http://obex.parallax.com/object/164

    The Propeller Education Kit (PEK) Text is how I started learning Spin though it doesn't teach the uses of CONstants other than to set the Propeller clock frequency.

    As the others have said, the Counters in each Cog have an NCO mode that will generate a Square Wave based on a 32-bit number or Long variable.
    https://www.parallax.com/downloads/propeller-education-kit-labs-fundamentals-text
    Chapter 7 teaches the different Counter modes and Page 143 uses the NCO mode to generate tones on a Piezospeaker.

    This is the code that goes with the PEK text and it uses Propeller Tool.
    https://www.parallax.com/downloads/propeller-education-kit-labs-fundamentals-example-code
    https://www.parallax.com/downloads/propeller-tool-software-windows-spin-assembly

    You should also have a copy of the Propeller Manual available for reference on commands and the Propeller chip hardware registers.
    https://www.parallax.com/downloads/propeller-manual
  • Thank you for the information.

    This project is designed to produce a simulated diesel locomotive horn of four chimes. Four sine waves will be sent to a summing amplifier then sent to a power amplifier and speaker. Several years ago, I recorded the sound of a locomotive blowing for a crossing and the sound was washed through my spectrum analyzer to acquire the frequencies. That data was lost but I think that the four frequencies stated earlier are close enough that I can adjust them in the propeller program.

    Sincerely,

    Discovery
  • Cluso99Cluso99 Posts: 18,069
    You should have no problems doing this with a prop. Take a look at SIDCOG to see what can be done.
  • Cluso99,

    Page not found for Prop Tools (Index), Emulators (Index), and ZiCog.

    What is SIDCOG?

    Discovery
  • JonnyMacJonnyMac Posts: 9,102
    edited 2019-03-24 13:37
    What is SIDCOG?
    SIDCOG is a Spin/PASM object that simulates the SID chip (https://en.wikipedia.org/wiki/MOS_Technology_6581) that was made famous in Commodore computers in the 80s.

    You might want to try Spin for a while; it was designed for the Propeller and will help you get close to the hardware. Once you have a really good understanding of the hardware, you'll be more effective with PropeBASIC. And if it's speed of the final code that concerns you, there is FastSpin that will compile to LMM code. FTR, I haven't used FastSpin, but many have.
  • jmgjmg Posts: 15,173
    Discovery wrote: »
    This project is designed to produce a simulated diesel locomotive horn of four chimes. Four sine waves will be sent to a summing amplifier then sent to a power amplifier and speaker. Several years ago, I recorded the sound of a locomotive blowing for a crossing and the sound was washed through my spectrum analyzer to acquire the frequencies. That data was lost but I think that the four frequencies stated earlier are close enough that I can adjust them in the propeller program.

    There are also examples aplenty here, of WAV file playback, for another way to solve this.

  • Well...I'll be darned.

    I did not know the SIDCog chip was used in the Commodore computers. I had two 64s and one 128. When I sold an earlier house the buyer said that they wanted to keep the Commodore 64 that ran the heating and cooling systems in the house.

    Sincerely,

    Discovery
  • I modified my DTMF object to handle four tones. It's written in PASM, I've never used PropBasic.
    4-tone%20generator.jpg
    That's using a simple low-pass RC filter.
  • That looks really nice. I wonder if someone knows how to convert the code to Propbasic?

    Sincerely,
    Discovery
Sign In or Register to comment.