Shop OBEX P1 Docs P2 Docs Learn Events
New to Prop programing. Need a pointer. Jitter in square wave siren tones — Parallax Forums

New to Prop programing. Need a pointer. Jitter in square wave siren tones

turbosoundturbosound Posts: 7
edited 2011-01-30 08:06 in Propeller 1
The dual tone output is a 5/6 ratio "Minor Third" ramps up quickly from (pin 0 300hz - 850Hz)
(pin 1 360hz - 1020hz)

stays steady for a few seconds then coasts back down slowly. Im new to all this timing/frequency programming. Both Outputs are divided by 2 with an 74ACT74 Flip-flop before heading out to pre-amps to hard square the wave with a +5V supply on the flip-flop. Any suggestions why I here crystal jitter in the coast down? Or tell me where I'm wrong with programming? I'd really appreciate it. Thanks!

CON

_clkmode = xtal1 + pll16x
_xinfreq = 4_915_200


PUB TestDuty | pin, duty, mode



ctra[30..26] := %00110
ctrb[30..26] := %00110
ctra[5..0] := 0
ctrb[5..0] := 1
frqa := duty
frqb := duty

dira[0]~~
dira[1]~~

repeat duty from 70 to 213
frqa := duty * 425
frqb := duty * 510
waitcnt(clkfreq/62 + cnt)

repeat duty
frqa := duty * 425
frqb := duty * 510
waitcnt(clkfreq/30 + cnt)

repeat duty from 213 to 70
frqa := duty * 425
frqb := duty * 510
waitcnt(clkfreq/11 + cnt)

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-01-27 14:51
    Just bumping this thread in case some of the sound guru's missed this post and can help you.
  • kuronekokuroneko Posts: 3,623
    edited 2011-01-27 21:55
    turbosound wrote: »
    Any suggestions why I here crystal jitter in the coast down? Or tell me where I'm wrong with programming?
    CON
      _clkmode = xtal1 + pll16x                  
      _xinfreq = 4_915_200
      
    PUB TestDuty | pin, duty, mode
    
      ctra[30..26] := %001[COLOR="red"]0[/COLOR]0
      ctrb[30..26] := %001[COLOR="red"]0[/COLOR]0                     
    
      ...
    
      repeat duty from 213 to 70
        frqa := duty * 425[COLOR="red"]/2[/COLOR]
        frqb := duty * 510[COLOR="red"]/2[/COLOR]
        waitcnt(clkfreq/11 + cnt)
    
    I'm not an audio expert (whatever that means). Anyway, as I don't have external dividers I changed the counter mode to NCO (to get a square wave) and used half the frequency (careful, this is noisy). What I do notice during coast down is some odd modulation. I'm not entirely sure that's what you refer to as crystal jitter. While there is inherent jitter due to the way the wave form is generated I also replaced the generator with the one introduced in the [post=947033]Propeller Counter question[/post] thread. Same modulation effect, NG. Then I changed the resolution of the last loop, i.e. higher loop cycle count, less change in frequency per cycle.
    repeat duty from 213[COLOR="blue"]*scale[/COLOR] to 70[COLOR="blue"]*scale[/COLOR]
        frqa := duty * 425/(2[COLOR="blue"]*scale[/COLOR])
        frqb := duty * 510/(2[COLOR="blue"]*scale[/COLOR])
        waitcnt(clkfreq/(11[COLOR="blue"]*scale[/COLOR]) + cnt)
    
    CON
      scale = 4
    
    This definitely sounds better to me. Have a go on your setup and see if it resolves your issue. HTH
  • turbosoundturbosound Posts: 7
    edited 2011-01-28 04:03
    Well thank you much for replying with the suggestions. I really appreciate the help. I'll give it a shot. Thank You!
  • turbosoundturbosound Posts: 7
    edited 2011-01-28 04:31
    That certainly did the trick! I appreciate your time and patience with the newbie! Thank you!
  • siljamickesiljamicke Posts: 66
    edited 2011-01-28 04:38
    I haven't yet started to learn counters, so I don't know what mode the counter is configured in. Anyway, could it somehow be Nyquist frequencies? Just a thought...
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-01-28 13:05
    I think it might have to do with the way the steps are computed. It sounds pretty good to me as you have it, even before Kuroneko's suggestion, but I can hear the jumps in frequency on the way down. Is that what you mean by jitter?

    A constant frequency step is more easily perceived as jumps at low frequencies, where the step is a larger proportion of an octave. Increasing the number of steps as Kuroneko suggested is one way to improve the perception of smoothness. Another is to make the steps equally tempered. That is, each step is a constant proportion of the current frequency, no matter which octave. For example, your start and stop frequencies are in a ratio of 2.833333 = 850Hz / 300Hz. To divide that into 143 equally tempered steps, compute the 143rd root of 2.833333, which turns out to be 1.007309. So then, multiplying 300Hz * 1.007309 * 1.007309 * 1.007309 * ... 143 times ends up at 850 Hz in equally tempered steps. On the Prop, you can do that using the ** operator. A repeat loop starts with the duty value for 300Hz, and then 143 reps of (duty := duty + duty ** 31393973) brings it up to 850 Hz.

    The factor 31393973 comes from the fact that 31393973 / 2^32 = 0.007309, and division by 2^32 is implicit in the ** operator.

    The attached program illustrates this. I had to change a few of the constants to make it work on my hardware.
  • turbosoundturbosound Posts: 7
    edited 2011-01-29 07:44
    Tracy: This works great, however on the coast down it drop the second tone and outputs the one frequency coast down on both pins. Both apin and bpin coast down from 850hz to 300.
    Both tones ramp up fine apin = 300hz to 850 hz
    bpin = 360hz to 1020hz but bpin drops to 850hz to 300hz for some reason coasting down. I'm trying to learn the math and programing but is there a correction I can make to have the bpin to stay at 1020hz and coast down to 360hz? I appreciate the help. Thanks.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-01-29 10:37
    Good ear. In the wind-down I wrote,
    ....dutya := dutya ** 2131900566 * 2
    ....dutyb := dutya ** 2131900566 * 2
    You see the bug? The second line should be,
    ....dutyb := dutyb ** 2131900566 * 2
  • turbosoundturbosound Posts: 7
    edited 2011-01-30 08:06
    I see it! Thank you very much for the time and help!
Sign In or Register to comment.