Closed Papamaker closed 5 years ago
A0 is an analogue pin ... This will never work, you need a digital pin with PWM and a timer on it, to get this trickery out of an ATMEGA. And timer 0 is used for delay, so only timer 1 and 2 are left for other stuff. Check the datasheet if you're unsure about the pins. google ATMEGA328p pinout timers
Papamaker: Thanks :)
Sadly, what JO3RI said. This code (as is the case with most audio code beyond simple beeps) relies on PWM to output audio, which is only available on a select few pins and further limited by timer usage. There are other options such as using a built-in DAC output (not available on ATMEGA328) or using an external SPI/shift-register DAC on 13, 11 and a CS pin of choice. You could also use A0 through A5 and a resistor ladder to produce a 6-bit output signal. That covers your options, but not all of them are implemented in Squawk.
Wow, thank you JO3RI and stg for those fast answers! I was wishing it could be possible because I'm currently using the Arduino's Tone() function on the A0 pin... (I still don't understand how it could work or maybe the Tone() function has a special software bypassing). Anyway thanks again for your project, I will find a way to hack my hardware to use it anyway (www.kitco.fr) Then I will let you know :-) A+ François
Tone works because it's very limited - it only outputs a square wave, the simplest of all waveforms to produce in a digital system. It hooks onto an interrupt and simply toggles the pin "manually"="by software" (as opposed to PWM that is handled by a hardware counter and compare circuit called a Timer) producing a square wave at the selected frequency. While it does not exactly apply, one could say that this is 1-bit sound. Squawk is an 8-bit synthesizer and as such this model does not work. One could in theory do software PWM, but the interrupt would have to be called 256(2^8bits) times for each sample which puts a much, much higher strain on the available processing power. It may be technically feasible - but would require quite a bit of trickery and time and would undoubtedly leave very little, if any, time over to do anything beyond playing music.
Hello Thank you for this amazing library, it is really great. I was wondering if the A0 PC0 output could be added for this library on a ATMEGA328. If you give me a few clues about it I would be glad to contribute about it :-). Thanks François