Shop OBEX P1 Docs P2 Docs Learn Events
Square Signal generation — Parallax Forums

Square Signal generation

octaloctal Posts: 67
edited 2011-01-04 02:39 in Propeller 1
Hello,
I try to generate square wave signal (about 25MHz) with Propeller and I have some questions:

1- If I use asembly (or maybe spin only cause 25Mhz is not too much) can I have good square waves (I dont have a fast oscillo to check)

2- Are generated square waves using code as good as those generated using COG counters modules?

3- using COG counters, is there any solution (an example code) to make the signal generator generate only a certain number of waves? (I mean for example to generate only 1000 Pulses and stop) ?

Regards

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-12-30 05:17
    The propeller usually runs with 80MHz clock frequency. Each instruction needs 4 clock cycles. Fastest squarewave-generator needs 2 instructions, one for toggeling the pin and one for the loop. So, with code the max frequency is 80MHz / 4 cycles / 2 instructions = 10MHz.
    This code itself of course can not count and stop after 1000 pulses. But as the propeller is fully deterministic you could have one COG which outputs the wave in a loop and another that waits long enough and then stops the squarewave-COG.

    Counters can only divide the clock by power of 2 values. So, if you need 25MHz the only way is to use a 6.25MHz chrystal (=100MHz clock) and use the counters (divide by 4). As the counter runs allone after it's setup, the COG can do a waitcnt to wait for 1000 pulses and then stop the counter. As the propeller is deterministic there will be a formula that can be used to exactly calculate the waittime needed for any amount of pulses.
  • octaloctal Posts: 67
    edited 2010-12-30 22:56
    Thank you MaglO2.
    Finally I need only about 20 Mhz, so the 80MHz (5MHzxPLL) is enought. The main pb now for me is to find a way to stop perfectly the wave form gen after a certain num of pulses. not that easy, I'll check.

    Regards
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-30 23:20
    octal wrote: »
    Finally I need only about 20 Mhz, so the 80MHz (5MHzxPLL) is enought.
    That will do. Just use an NCO and set frqx to $40000000 (clkfreq * 2-2).
    octal wrote: »
    The main pb now for me is to find a way to stop perfectly the wave form gen after a certain num of pulses. not that easy, I'll check.
    One way is to simply sit there in a waitcnt and then switch off the counter. You could also count the pulses (edge counter mode) your NCO emits and periodically check how far it got and do something else while you're waiting. When you get closer to your intended target you simply pay more attention so you don't miss the cut off point. There are other ways to achieve this, this should get you started.

    Is this SPIN or PASM?
  • octaloctal Posts: 67
    edited 2011-01-03 08:46
    Thx kuroneko
    I'm effectively trying to do it using counters in a second COG.
    As for the implementation, everything I'm writing is done using PASM (in the COG monitoring the count of pulses) because of the need for precision.

    Regards
  • kuronekokuroneko Posts: 3,623
    edited 2011-01-03 15:53
    octal wrote: »
    I'm effectively trying to do it using counters in a second COG.

    Is there a particular reason that you have to use a second cog? Are the two counters in the monitor cog not enough?
  • octaloctal Posts: 67
    edited 2011-01-04 02:39
    I juste used another COG in order to got more speed and easier timing management. As my propeller chip will be used mostly as a signal generator, consuming a second cog is not a pb for me.
Sign In or Register to comment.