Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Calling tone in loop freezes the Arduino #368

Open
@jgromes

Description

@jgromes

Hi,

I have ran into a bit of an issue that calling tone in a loop will crash/hang/freeze Arduino Nano 33 BLE. Here's a simple sketch to replicate:

voidsetup() {  Serial.begin(9600);while(!Serial);pinMode(6, OUTPUT);  Serial.println("beep :)");int start =millis();while(millis() - start <30000) {tone(6,2200);delayMicroseconds(833);tone(6,1200);delayMicroseconds(833);  }// after a couple of seconds, pin 6 stops outputting anything (checked with a scope)noTone(6);  Serial.println("no beep :(");// never gets printed}voidloop() {}

My initial theory was that this is caused by a failed dynamic allocation here:

voidtone(uint8_t pin,unsignedint frequency,unsignedlong duration) {
if (active_tone) {
delete active_tone;
}
Tone* t =newTone(digitalPinToPinName(pin), frequency, duration);
t->start();
active_tone = t;
};

However, adding a check to make suret != NULL didn't fix this, so now I'm no longer so sure. I don't know the platform well enough to attempt to fix this.

Background: this popped up in one of my projects (jgromes/RadioLib#407), when generating 1200/2200 Hz tones for AX.25 transmission. I was able to work around the issue by usingPwmOut and switching the frequency of that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp