New to Prop programing. Need a pointer. Jitter in square wave siren tones
turbosound
Posts: 7
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)
(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
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.
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.
....dutya := dutya ** 2131900566 * 2
....dutyb := dutya ** 2131900566 * 2
You see the bug? The second line should be,
....dutyb := dutyb ** 2131900566 * 2