Shop OBEX P1 Docs P2 Docs Learn Events
Not understanding pssing a global variable — Parallax Forums

Not understanding pssing a global variable

WolfbrotherWolfbrother Posts: 129
edited 2011-01-28 13:53 in Propeller 1
I am hoping to pass a global variable to a running cog, while updating it my main cog running. To test this I have modified an example from Harprits book, called Harpritstones2. This seems to work like a champ, I increment the tones in the first cog and the second cog seems to play them just fine. I wanted to add a 1/2 second pause between each note played, so I thought I could just play a zero frequency tone for 1/2 second, I would do this by storing the passed tonenumber into a temp variable, changing tonenumber to a zero frequency in the DAT lookup, waiting 1/2 second and then returning the tonenumber back to where it was by making it equal to stored temp value. That program is called Harpritstones21

Doesn't seem to work, I can play the first tone, it then goes to the second tone, without a pause ( which does make sense to me, based on how I wrote it) Once the ToneNumber changes to 9 ( the zero frequency in the DAT table) the tones never come back. I have run serial terminal to make sure the values are changing correctly, but no tones follow.

I have attached all the programs and a notepad copy of my serial terminal output, what am I missing here?

Thanks,

Dave

Comments

  • WolfbrotherWolfbrother Posts: 129
    edited 2011-01-28 13:30
    I found one mistake, putting a zero for the repeat frequency, made it so I heard nothing, but causes other issues... oops. So I put in a frequency of one and that works, but it produces a little (audible) click noise. Does anyone have a better idea for me to insert a pause in the notes?

    Thanks,

    Dave
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-28 13:40
    If your Note value is zero you have a division by zero, which is not a good idea.

    You should change the loop to
      repeat                           'outer loop
        repeat RepFactor               'inner loop and repeat #
          GetTone                      'gets value for NoteFreq
          if NoteFreq  
            !OUTA[output]                'toggle output line
            NoteDelay:=10_000_000/(NoteFreq*2)   'calculate the delay
          waitcnt(NoteDelay +cnt)       'wait for delay to synthesize freq 
    

    I don't see a reason for having the inner loop as it's immediately repeated by the outer loop. So, it can be removed.
  • WolfbrotherWolfbrother Posts: 129
    edited 2011-01-28 13:53
    Hi MagIO2,

    That seems to work just fine. I wasn't convinced I needed the nested repeats either. Thank you. Based on your idea, I modified the program to use a flag to either output a tone or not. I think this is much cleaner. If you have any suggestions about this idea I would welcome it.

    Thanks,

    Dave

    Harpritstones24.spin
Sign In or Register to comment.