Luckily, there are 3 more pins you can use, located in that block of pins on the end that nobody talks much about: 44, 45, and 46 can be used for PWM too, in place of the ones that the library makes non-usable with PWM. And of course, that's controlled by, if I'm not mistaken, the pot you have connected to A6, consistent with your observation.ĭon't use those pins for analogWrite(). Of course, the fact that it is calling analogWrite on the speaker pin (analogWrite will be doing a surprisingly slow lookup of which timer is on that pin, then calling pinMode() which does another series of slowass lookups even though the pin was just set output 100 microseconds ago), when they could be doing a single write to the output compare register, since they only support pins on timer0 anyway for that, implies that they haven't given much attention to performance now does it?Īnyway, so analogWrite(11,duty) will write a number between 1 and 254 to OCR1A, instead of 799, making it this interrupt fire more frequently, with the observed effect of the sketch getting slowed down something horrible, because it's spending all it 's time in that ISR. Gee, I hope the author wrote it with careful attention to performance. That means EVERY 800 CLOCK CYCLES IT FIRES THE INTERRUPT. if that doesn 't ring alarm bells in your head right off the bat, it should. Because see, it needs this to fire 20k times a second. In vol.begin, it is set to F_CPU/20000 -1, that is, at 16 MHz it's set to 799 and the prescaler is dropped back to 1. It's not in a PWM mode at all, it's in CTC mode (Clear Timer on Compare match). The problem is that you are using PWM on pins 11 and 12 in combination with the Volume.h library, on a mega2560 that should take out pwm on pins 11, 12, and 13, and trying to use it anyway will break stuff.ĪnalogWrite has no idea that the timer it would use to generate PWM on pins 11 and 12 has been completely reconfigured, and is now in an entirely different mode than it is expecting, and would set OCR1A or OCR1B to the duty cycle - if it were still in 8-bit pwm mode, like it was expecting, that would give you PWM of that duty cycle. Don't go sending people on fools errands when it's bloody obviously not going to provide any enlightenment. And Volume.h sounds like the sort of library that would be great at causing whacko problems like this. He reports that it works without using Volume.h library. ![]() Include links to technical information on all hardware items. Show all interconnections and power supplies. Start by posting a schematic, not a frizzy drawing. I'll be researching the issue and hoping someone will help me figure it out. Serial.println() // carriage return after potVals written serially. Vol.setMasterVolume(1.00) // Self-explanatory enough, right? Try lowering this value if the speaker is too loud! (0.00 - 1.00) correctly! Instead, use vol.delay() and vol.delayMicroseconds() for Vol.begin() // After calling this, vol.delay() and vol.delayMicroseconds will no longer work Volume vol // Plug your speaker into the default pin for your board type: //Note to self: this declares an instance of "Volume", is necessary. And I obviously don't wholly grasp the idea of timers and interrupts. An answer for me could be as simple as "such and such pins shouldn't be used because they correspond to some interrupt or timer, but that answer doesn't seem available anywhere I've looked). The obvious answer is "don't use the volume library, but it's pretty integral to the intended function of the project, and also, I need to know what this timer problem is". This is really frustrating me beyond my ability to produce words to convey that emotion. has something to do with timer0 (I'm assuming), which is utilized by the volume library NO MATTER WHERE I PLUG IT (amongst the available analog pins, which are A8-A12, or A6). ![]() When I use the code absent the volume library, it works perfectly, but when I incorporate the volume library, the results just become unpredictable and effed-up.įor example, Potentiometer 2 (potPins), aka pin A6, corresponding to the Bval variable seems to slow down the execution of the code, i.e. This code is for an LED/Sound layout using common-cathode RGB LEDs on a MEGA 2560 and 6 10k Potentiometers for adjustment.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |