Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tone() does not work correctly on V2.x.x #471

Open
paulvha opened this issue Oct 30, 2022 · 0 comments
Open

tone() does not work correctly on V2.x.x #471

paulvha opened this issue Oct 30, 2022 · 0 comments

Comments

@paulvha
Copy link
Contributor

paulvha commented Oct 30, 2022

Error description
The command tone() is not generating a PWM signal on the pins.

Reproduce
try tone(A16,200) in a sketch and it will fail (as with any other pin)

Root cause error in the library
file : SparkFun/hardware/apollo3/2.1.1/cores/arduino/sdk/core-implement/CommonAnalog.cpp,
function : void indexTone(pin_size_t index, unsigned int frequency, unsigned long duration)
at the end of the function (line 184) the duration handling check is incorrect. If duration = 0 (which means NO duration check needed) the tone should continue until the user stops with notone(). Now it will stop tone immediately.

if(duration){
        uint32_t stop_time = millis() + duration;
        while(millis() < stop_time){};
    }

   ap3_pwm_output(pad, 0, 0, clk);

Change this to :

    if(duration){
        uint32_t stop_time = millis() + duration;
        while(millis() < stop_time){};
        ap3_pwm_output(pad, 0, 0, clk);
    }

It will then work as it should. The error is on all the V2 library versions. V1x library has 2 different tone() calls one with and one without duration and thus is works correctly there.

regards,
Paulvha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant