Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Error in tone duration calculation

$
0
0

The Energia Reference says:

duration: the duration of the tone in milliseconds (optional) - unsigned long

 

In Energia, however, the tone() function does not plays the tone for the specified duration due to a miscalculation in Tone.cpp. This causes incompatibility compared to the behavior of the tone() function in Arduino.

 

The problem is here:

  if ( duration > 0 )

    tone_periods[n] = (duration * (F_TIMER/2)) / (1000L * tone_interval[n]);
  else

We must not divide F_TIMER by 2, so I modified the code to the following:

  if ( duration > 0 )

    tone_periods[n] = (duration * F_TIMER) / (1000L * tone_interval[n]);

  else

Now it play tunes as expected.


Viewing all articles
Browse latest Browse all 2077

Trending Articles