Shop OBEX P1 Docs P2 Docs Learn Events
Frequency Synthesizer-Synth — Parallax Forums

Frequency Synthesizer-Synth

steprogsteprog Posts: 227
edited 2010-04-18 15:53 in Propeller 1
Hello
I was hoping to use the freq synth object to help me create 8 different frequencies coming out of 8 different cogs, but I found out that this object doesn't play nice being called again.· I tried calling it twice in cog 0 using different pins frequencies and different counters, but for some reason it wouldn't let me do it.· I also tried loading it into cognew with plenty of stack and it wouldn't do that either.· Is there some reason why freq synth object can only be used once?
Sorry for the newby question.
Thanks,
Greg

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-18 14:25
    The frequency synthesis object isn't written to be run the way you think. It's designed to be called as a subroutine. What you can do is to start up a cog in your main program and have that call Synth. What's happening to you is that Synth sets things up, then exits. When it exits, that causes the newly started cog to stop. COGNEW always starts up your code with a return to a COGSTOP as the initial stack contents.

    The easiest thing to do is to put a REPEAT at the end of Synth so that it never exits, then use COGNEW to call Synth (with an appropriate stack). Save the cog number returned from COGNEW so you can stop that cog later if you want to restart it with new parameters or just to stop it.
  • steprogsteprog Posts: 227
    edited 2010-04-18 14:48
    So when the cog stops all the timer variables are reset. I should have thought of that.
    Thanks Mike
  • steprogsteprog Posts: 227
    edited 2010-04-18 15:12
    Mike Green said...
    The frequency synthesis object isn't written to be run the way you think. It's designed to be called as a subroutine. What you can do is to start up a cog in your main program and have that call Synth. What's happening to you is that Synth sets things up, then exits. When it exits, that causes the newly started cog to stop. COGNEW always starts up your code with a return to a COGSTOP as the initial stack contents.

    The easiest thing to do is to put a REPEAT at the end of Synth so that it never exits, then use COGNEW to call Synth (with an appropriate stack). Save the cog number returned from COGNEW so you can stop that cog later if you want to restart it with new parameters or just to stop it.
    · Mike,
    · I just realized that one condition doesn't quite jive with your explanation.· I ran a test to turn on Freq.synth for the A counter and a second instance for the B counter.· Different freqs and pin numbers.· For some reason, the first instance would start then turn off once the second instance started up.· I've been up all night, but I can't see why I can't turn on to instances in cog 0 like that.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-04-18 15:49
    steprog,

    In order to create 8 different frequencies, you only need 4 cogs (you could have 16 different frequencies)
    The 'Synth' object is capable of generating 2 independent frequencies from Counter A and Counter B. Each instance of the 'Synth' object needs to be called as a separate COG. The Stack requirement of each 'Synth' object is about 25 longs, so 4 instances or 4 COGS would require a stack space of 100 longs.

    Hope this helps.

    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
      Frequency1 = 1_000                                    'DC to 128MHz
      Frequency2 = 1_500                                    'DC to 128MHz
      Frequency3 = 2_200                                    'DC to 128MHz
      Frequency4 = 1_600                                    'DC to 128MHz
      Frequency5 = 3_300                                    'DC to 128MHz
      Frequency6 = 1_700                                    'DC to 128MHz
      Frequency7 = 4_400                                    'DC to 128MHz
      Frequency8 = 1_800                                    'DC to 128MHz
    
    VAR
    long    STACK[noparse][[/noparse]100]
    
    OBJ
      Freq : "Synth"
    
    PUB DEMO
        COGNEW(FreqDemo(0,1,Frequency1,Frequency2),@Stack[noparse][[/noparse]00])
        COGNEW(FreqDemo(2,3,Frequency3,Frequency4),@Stack[noparse][[/noparse]25])
        COGNEW(FreqDemo(4,5,Frequency5,Frequency6),@Stack[noparse][[/noparse]50])
        COGNEW(FreqDemo(6,7,Frequency7,Frequency8),@Stack[noparse][[/noparse]75])            
    
    PUB FreqDemo(P1,P2,F1,F2)
        Freq.Synth("A",P1, F1)                              'Synth({Counter"A" or Counter"B"},Pin, Freq)
        Freq.Synth("B",P2, F2)                              'Synth({Counter"A" or Counter"B"},Pin, Freq)
        repeat                                              'loop forever to keep cog alive
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • steprogsteprog Posts: 227
    edited 2010-04-18 15:53
    Thanks Bean,
    I will give it a shot.
    Greg
Sign In or Register to comment.