Skip to content

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

@paulvha

Description

@paulvha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions