1284P and pin 20

Hi All,

I'm using the 1284P in my Nixie clock projects, with no issues except for this one - pin 20 is connected to the gate of a 2N7000 through a 4k resistor, driving some LEDs. A piezo buzzer is connected to another pin and when tone() is executed, PWM on pin 20 is affected. There also appears to be some conflict between PWM on pin 20 and commands issued to the MCP23017 on the I2C bus, but I haven't investigated that further. The sketch is about 2500 lines, and I haven't spent much time trying to narrow the possibilities.

I'm using the Bobuino/Skinny Bob configuration, and all boards that I've built have the same issue. I can avoid pin 20, but if anyone has clues as to what is happening, I'd like to know.

Thanks in advance.

..pin 20 is connected to...

Is that physical pin 20 or logical pin 20? (A schematic would be helpful.)

Sorry, physical pin 20, D9. I'm out of town at the moment, I'll include a schematic next week when I return home.

Here's an example - with this test, when a button on D15 is pressed, PWM on D9 will stop

void setup() {
  
pinMode(15, INPUT_PULLUP); // button
pinMode(29, OUTPUT); // buzzer
pinMode(9, OUTPUT); // PWM

analogWrite(9, 200);
}

void loop() {

byte x = digitalRead(15);

if (!x) tone(29,100);

}

Using Tone() requires one of the timers. That means it takes out PWM on two pins.

Thank you. Is there a way around this such as a substitute for tone(). I'm not sure but I think Timer3 is not used. I just need a short beep to confirm key presses, nothing more.

Can you use different pins for the PWM?

If you're using the separate core (the one that works with all the 40-pin ones and includes it's own copy of the core) you could also modify the core to use a different timer for tone...

One more pwm pin is available. I'll try it, but I have to cut a trace and run a wire. Now that I know what's happening, I'll try a timer free tone library first. Thanks for the help!

You lose both timer2 pins to tone()

I've searched and I can't find documentation on which pins the three timers are related to. Please post a link or that information. Thanks again.

MitchSF:
I've searched and I can't find documentation on which pins the three timers are related to. Please post a link or that information. Thanks again.

It's in the datasheet, pin configurations page, the pins for each timer are marked OC (for output compare) then the number of the timer and a letter indicating the channel, ex OC2A. Then cross reference with Arduino pin mapping.

MitchSF:
Is there a way around this such as a substitute for tone(). I'm not sure but I think Timer3 is not used. I just need a short beep to confirm key presses, nothing more.

If you use an active piezo buzzer then you don't need to use tone().

pert:
If you use an active piezo buzzer then you don't need to use tone().

Now that is funny. I've been using active piezo buzzers and tone() all along, and I never realized that there was such a thing. Thank you both.