Skip to content

Commit

Permalink
Decrease calculation error of tone frequency (#7)
Browse files Browse the repository at this point in the history
Change the cycle calculation of tone from round down to the nearest
decimal to round off.
  • Loading branch information
SPRESENSE authored and takayoshi-k committed Aug 30, 2018
1 parent 2316099 commit d0f1e7d
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int tone_begin(uint8_t pin, unsigned int frequency, unsigned long duratio
s_ctx.pin = pin;
s_ctx.infinite = (duration == 0);
s_ctx.duration = duration * 1000; // convert to us
s_ctx.interval = 1000000L / frequency / 2;
s_ctx.interval = (unsigned long)(1000000.0 / 2 / frequency + 0.5);
s_ctx.pin_addr = get_gpio_regaddr((uint32_t)pin_convert(pin));

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

0 comments on commit d0f1e7d

Please sign in to comment.