Author Topic: Tone() works on some pins but not others  (Read 3635 times)

bratoff

  • Newbie
  • *
  • Posts: 6
Tone() works on some pins but not others
« on: April 26, 2015, 08:06:53 pm »
Has anyone else noticed that the Tone() function doesn't work properly on pins 2, 3 and 4?  If you code Tone(4, 800) you'll get an 800Hz tone, but on pin D1!  Calling Tone() for pins 2 and 3 causes the tone to be generated on D0.

Looking at the core source, D0 thru D4 are all coded as being capable of hardware tone generation on Timer 1, so I thought it would just be a matter of setting the correct bits in TCCR1D based on the port #.  However, I tried that and it does not work as expected - I think something else is messing with TCCR1D.

Changing entries 2, 3 and 4 of digital_pin_to_timer_PGM[] to NOT_ON_TIMER makes Tone() work properly (those pins then get "software" tone generation), but looks like it will break the PWM stuff.

Does anyone have a "clean" fix for this issue?

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Tone() works on some pins but not others
« Reply #1 on: June 23, 2015, 01:53:26 pm »
this is a conflict between pwm and tone - the pwm routines have special features to handle the Pro's multi-channel PWM capabilities, the tone library is not updated with these yet. Using pwmConnect and pwmDisconnect after calling tone might allow you to move which pin the tone is on, but it sounds like the one library is due a better port to the Pro