What if I messed up the Timer 0 and set it faster?
Basically the only thing right about that code was the setting of the PWM frequency.You were using the wrong pin, I have changed it to pin 9.You had the wrong delay value - I changed that.You had the for loop wrong like AWOL tried to tell you.But most of all you were reading the program memory incorrectly.
I think he is saying "my life for iera" although not ever watching films it means nothing to me.
So, isn't necessary at all to have a very fast PWM?
The actual delayMicroseconds should be of 62, not 50
Exactly why? Because the variable i hasn't initialized from the beginning
It appears in a "old-school" PC game called "StarCraft".
However such a strong out of band signal could screw up the electronics in the audio amplifier so it is best to leave it in. For the tests I just used a high impedance "ear bud" touched onto the pin directly.
Only 62 if the for loop overhead, writing to the A/D, and fetching the sample byte from program memory takes zero time. I was trying it slightly shorter to compensate for these.
Basically yes, also the short variable type, while part of C is not used much in this world.
Never had a PC so I wouldn't know.
(and that's how I deducted how long takes that functions to execute, is that right or I'm wrong?
So, for a "good programming practice", should I keep using int type variables for looping statements?
So my earbuds have lower impedance? Because I could barely hear my sound without using .....
For that you need to set another timer going (not timer 0 ) so that it generates an interrupt at exactly the sample frequency. Then the interrupt service routine does the fetches and loading of the PWM register. This means that you can do other stuff while the sample is playing, like LED animation or looking for a button press to set the sample going again. Like n.n.n.nineteen, that song from Paul Hardcastle.
Yes if an int is big enough, you could use a byte, or a long, but always initialise the loop variable. It could start off with junk in it.
Looks like it. These were the cheapest in a cheap shop I visited when I went to New York for the 2011 Maker fair, I don't have to put them in my ear to here the sound.
Is that like simulating a multi-threaded (aka multi-task) process from a single-core CPU?
like sensing the push of a button while playing an animation for a RGB LED strip
I guess they can pick up the weak signal of a dynamic microphone without any sort of amplification.
Yes that is called a state machine.
No I just tried it. I could barely see the signal when I whistle as loud as I can into the ear bud. It gives about 20mV. It says Panasonic on them but given the price and where I got it from it is almost certainly fake.
Do you mean that many mandatory functions inevitably consume a significant amount of time and it's impossible to achieve a 100% perfect timing?
at least is comprehensible that even delayMicroseconds is accurate enough
And that is with a task that contains only the one instruction, you will have to insure that all your tasks complete in significantly shorter time than the sample rate. Even then there will be a jitter of a time period equal to the length of your longest task.
A jitter of 4uS might not be noticeable at the low quality you have at the moment but it will soon show up as noise on your output.