NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Basic Electronics » Shuttering with the Nerdkit & piezo buzzer (Can't post in Support, gives error)
January 28, 2014 by lailai |
Hi all, I'm attempting to play sound (with the piezo buzzer) using the nerdkit. I wanted to play more than one tone at a time, so I used two timers set to interrupt. Each timer manages one pin, both pins are then hooked to a resistor and finally the piezo buzzer. It works quite well, however there are shuttering present. It always shutters at the same time. The shuttering still happens without LCD updates, but at different times. If I change a little bit, the times when shuttering happens changes again. Here is my code (with some parts like defining notes to frequencies stripped out):
Can I fix the shuttering? (maybe 0.1 to 0.15 seconds) Or is it interrupt clashes like I suspect? NOTE: It happens without any LCD updates. Thanks! |
---|---|
January 29, 2014 by BobaMosfet |
lailai- Don't use delay_ms(). BM |
January 30, 2014 by Ralphxyz |
BobaMosfet, where did you see that delay_ms() was used? I assume "Stuttering" is meant instead of "shuttering". Ralph |
January 30, 2014 by Noter |
Find it in the play_tone( ) function. I don't think it is related to the problem. Likely the timer is overrunning the OCRxA value when OCRxA is updated to a value smaller then the current TCNTx. I put that suggestion in one of the other threads (3 of them) lailai started on this topic. |
January 30, 2014 by BobaMosfet |
Ralph, Line 38. I mention it because it could be part of the problem-- anything that affects interrupts can be. Noter's point is also correct. Furthermore, he's enabling and disabling clock which can also cause problems because (per the Datasheet), this can cause a random number of cycles for the chip to sort out and change state. I would do this differently, with a single interrupt. BM |
Please log in to post a reply.
Did you know that a flyback diode is important when driving a motor or any inductive load? Learn more...
|