Skip to content

Commit d0f1e7d

Browse files
SPRESENSEtakayoshi-k
authored andcommitted
Decrease calculation error of tone frequency (#7)
Change the cycle calculation of tone from round down to the nearest decimal to round off.
1 parent 2316099 commit d0f1e7d

File tree

1 file changed

+1
-1
lines changed
  • Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/cores/spresense

1 file changed

+1
-1
lines changed

Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/cores/spresense/wiring_tone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static int tone_begin(uint8_t pin, unsigned int frequency, unsigned long duratio
123123
s_ctx.pin = pin;
124124
s_ctx.infinite = (duration == 0);
125125
s_ctx.duration = duration * 1000; // convert to us
126-
s_ctx.interval = 1000000L / frequency / 2;
126+
s_ctx.interval = (unsigned long)(1000000.0 / 2 / frequency + 0.5);
127127
s_ctx.pin_addr = get_gpio_regaddr((uint32_t)pin_convert(pin));
128128

129129
if (!s_ctx.infinite && s_ctx.duration < s_ctx.interval) {

0 commit comments

Comments
 (0)