Shop OBEX P1 Docs P2 Docs Learn Events
What is the highest frequency square wave I can generate? — Parallax Forums

What is the highest frequency square wave I can generate?

HughHugh Posts: 362
edited 2014-12-13 01:47 in Propeller 1
Hi,

I need to generate a square wave and the Props I have lying around seemed a good thing to try. What is the highest frequency square wave that I can generate with the Prop? I'm not competent with ASM and on/off/on/off in Spin might not be very effecient.

There isn't a target value as such, I'd just like to know where the limit is likely to be - or NE555 here we come..!

Many thanks

Hugh

Comments

  • AribaAriba Posts: 2,690
    edited 2014-12-12 05:42
    Hugh wrote: »
    ....or NE555 here we come..!

    it's more like: Bye bye NE555 !

    The highest frequency you can generate with the PLL of a counter is about 160..200 MHz. Every cog of the Propeller has two such counters.

    But if you want to do it just by software with a PASM loop, you need 2 instructions, one for pin-toggle one for jump back in the loop, so you get a square wave frequency of 5 MHz (@80 MHz system clock). With an unrolled loop you can get 10 MHz for a short time.

    Hope this helps
    Andy
  • kuronekokuroneko Posts: 3,623
    edited 2014-12-12 06:02
    Ariba wrote: »
    With an unrolled loop you can get 10 MHz for a short time.
    You can get 10MHz (clkfreq/8) in a loop (dira setup not shown):
    mov     outa, mask
    
            add     outa, #1
            djnz    outa, #$-1
    
    mask    long    !(|< pin)
    
    @Hugh: This thread may be of interest as well.
  • ErNaErNa Posts: 1,752
    edited 2014-12-12 06:56
    nice to see. And PASM is even better: "'" allows to comment ;-) I actually can not follow
  • AribaAriba Posts: 2,690
    edited 2014-12-12 07:09
    kuroneko wrote: »
    You can get 10MHz (clkfreq/8) in a loop (dira setup not shown):
    mov     outa, mask
    
            add     outa, #1
            djnz    outa, #$-1
    
    mask    long    !(|< pin)
    

    Neat, A typical Kuroneko trick ;-)
  • HughHugh Posts: 362
    edited 2014-12-12 09:09
    A fantastic and comprehensive set of answers - thank you!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-12-12 10:29
    Edit: I checked my notes and the max frequency was 38.7KHz. I doubt the PWM is a good way to approach this. Counters may be a good Spin solution. I don't know enough to know what to suggest.

    Check out the counter section of the PEK (available from "help" menu). You can set these counters from Spin.

    I'm no expert on counters but I followed the tutorial to make the PWM section of my motor control demo code. The code will let you adjust the frequency of the PWM on the fly. I don't recall what the max frequency was. I think it was pretty high if you just needed two bits of resolution (square wave).

    I'd be surprised if there aren't better ways to do this in Spin.

    Edit: As I think about this a bit, I realize the PWM example probably isn't a good one. IIRC there was some setup code for easy PWM cycle. I think this would interfere with a nice square wave. Hopefully someone more knowledgeable about counters will chime in on how to do this in Spin.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2014-12-12 12:51
    The real question is how clean do you want the square wave? I used the Counter Modules code from Chip Gracey to produce a 60MHz square wave. It had a little ring to the low-to-high transition, but worked great for me.

    http://obex.parallax.com/object/187

    edit: after looking at my scope pictures again, the ringing was on both transitions, see attached and notes below from my PropBSC module testing http://forums.parallax.com/showthread.php/143318

    "10MHZ propeller generated signal. Ch2 is on the Propeller* Pin (P5). CH1 is on the Translator 5V Logic IO pin (PB5) This is showing the performance of the translator at 10MHZ. Signal loaded through a 4.7k resistor to ground."
    281 x 209 - 50K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-12-12 13:54
    The ringing is probably a measurement artifact rather than something endemic to the Propeller.

    -Phil
  • pjvpjv Posts: 1,903
    edited 2014-12-12 15:54
    I'm with Phil on this one.

    My experience indicates that ringing will almost entirely disappear if you arrange the circuit so you can connect to it without the use of a longish scope ground lead. For high speed circuitry scope measurements I use a home-built ground connection spring that is only 0.1 inches long. That makes all kinds of noise go away.

    Cheers,

    Peter
  • Cluso99Cluso99 Posts: 18,069
    edited 2014-12-12 16:16
    And you can overclock the prop. I typically run them at 104MHz but have done higher.

    Sapieha has run a DIP prop at 115MHz but I have only achieved ~113MHz on a QFP. But I would not take these frequencies as reliable.
  • Cluso99Cluso99 Posts: 18,069
    edited 2014-12-12 16:40
    kuroneko wrote: »
    You can get 10MHz (clkfreq/8) in a loop (dira setup not shown):
    mov     outa, mask
    
            add     outa, #1
            djnz    outa, #$-1
    
    mask    long    !(|< pin)
    
    @Hugh: This thread may be of interest as well.

    Am I missing something ???

    Presume P4 for the example....
            mov     dira, maskd   ' $0000_0010    (1<<4)
            mov     outa, mask    ' $FFFF_FFEF    !(1<<4)
    
            add     outa, #1      ' $FFFF_FFEF + 1 = $FFFF_FFFF (first time, then) $FFFF_FFFE + 1 = $FFFF_FFFF
            djnz    outa, #$-1    ' $FFFF_FFFF - 1 = $FFFF_FFFE 
    
    mask    long    !(1<<4)    ' !(|< pin)
    maskd   long    (1<<4)     ' (|< pin)
    

    BTW the original example should work for P0.
  • SapphireSapphire Posts: 496
    edited 2014-12-12 16:53
    No,

    $FFFF_FFEF + 1 = $FFFF_FFF0
    $FFFF_FFF0 - 1 = $FFFF_FFEF
  • Cluso99Cluso99 Posts: 18,069
    edited 2014-12-12 21:48
    Thanks Sapphire,
    How silly of me. I just couldn't see the forest for the trees :(
  • ErNaErNa Posts: 1,752
    edited 2014-12-13 01:21
    Always wait for others ask your "stupid" questions and you are a genius ;-) Now I got it. Thanks, ErNa
  • kuronekokuroneko Posts: 3,623
    edited 2014-12-13 01:47
    ErNa wrote: »
    Always wait for others ask your "stupid" questions and you are a genius ;-) Now I got it. Thanks, ErNa
    You could simply have run an example. I wasn't quite sure yesterday what you were after but I'm glad it's sorted now.
Sign In or Register to comment.