Code is randomly not working
qsuscs
Posts: 12
Hello,
this afternoon, I wanted to check which frequencies I can hear, but I wanted to do this by myself. So I wrote a bit of spin which should give me the tones from 10Hz to 20kHz in different intervals.
It works, sometimes, but not every time. There are two problems:
BTW, I use a 5MHz crystal (two legs), but I also have a 4.9152MHz oscillator and some other microcontrollers that I could use as a clock.
qsuscs
EDIT: I also tried different frequencies (i.e. pll1x instead of pll16x), it stopped later, but it stopped nevertheless, and the tone frequencies were still off.
this afternoon, I wanted to check which frequencies I can hear, but I wanted to do this by myself. So I wrote a bit of spin which should give me the tones from 10Hz to 20kHz in different intervals.
It works, sometimes, but not every time. There are two problems:
- It stops at a random point, there is no sound anymore but the frequencies are printed all at once
- The frequencies are off too much
BTW, I use a 5MHz crystal (two legs), but I also have a 4.9152MHz oscillator and some other microcontrollers that I could use as a clock.
qsuscs
EDIT: I also tried different frequencies (i.e. pll1x instead of pll16x), it stopped later, but it stopped nevertheless, and the tone frequencies were still off.
Comments
That's because cnt doesn't keep going up forever; it overflows from $7FFF_FFFF (biggest positive number) to $8000_0000 (smallest negative number). Do this instead:
Your frequencies are off (too low) becasue of this statement:
It doesn't account for interpreter overhead. Also, you need parens in the denominator. Better would be this:
where k is initialized to cnt at the beginning of the loop.
I'm not certain, but Spin may be too slow to reach 20 kHz this way. But you can use one of the counters to generate your output without having to resort to PASM.
-Phil
But the counters sound interesting, how do I use them? AFAIK the Propeller doesn't have interrupts, this is how the counters are used in the world of AVR.
Just found that: http://www.parallax.com/tabid/780/Default.aspx. I think it’ll be a strange feeling when I do something with AVR again, one core, interrupts, …
for example the object http://obex.parallax.com/objects/422/ creates frequencies.
So take a look into the OBEX which frequency-object suits best to your needs
best regards
Stefan
Also, are you adding very high frequencies? I have always imagined I can "hear" frequencies that are supposed to be near ultra sonic, from working with CRTs, marginal TVs, etc. If convenient, please include a couple brands above what were are supposed to be able to detect.
I planned to prompt a frequency (PS/2+TV or serial) after all the frequencies were played. There is a sticker on my CRT that says fH: 27-68kHz, I don't think you are able to hear that, but, I don't know, maybe you are, or the CRT emmits other frequencies.