arduino / ArduinoCore-sam

81 stars 108 forks source link

Tone implementation #108

Open RedRussianBear opened 4 years ago

RedRussianBear commented 4 years ago

Implemented Tone functionality for SAM3X/Due using TC5.

DesperateProgrammer commented 4 years ago

Looks solid.

Only one thing to consider: There might be a little issue with EMV. Usually the rectangular signal will be filtered to reduce the high frequency parts of the steep rise/false edges. If Cutoff however is odd, the algorithm is introducing another frequency: Example: MCK = 84MHz, Frequency = 440Hz (Musical Note A) -> Cutoff = 1491 -> Cuttoff/2 = 745 This creates two different widths for low and high phase. This actually generates the mixed frequency of MCK/128/(745*2) and MCK/128/1491 you will see a radiation of the frequency difference (MCK/128/1) in EMV measurements.

Surely the jitter due to the interrupt is flattening the EMV peek. But it will be measureable and might also interfere with some switching regulators operating in the same range.

This could be avoided with same or better frequency accuracy, If you decrease the prescaler to /32 and mask out the LSB in cutoff, so that cutoff value is never odd and the low and high times are equal.

RedRussianBear commented 3 years ago

Thanks for pointing that out, I would have never realized! I just got around to fixing that issue, hopefully all's good now.

CLAassistant commented 3 years ago

CLA assistant check
All committers have signed the CLA.

RedRussianBear commented 3 years ago

Hi, is there anything else I need to do to get this PR accepted?

jgromes commented 3 years ago

@RedRussianBear pray to some elder deity, possibly - this PR has been blocking one issue in my project for half a year now, which is very frustrating.

@cmaglie (or anyone else with the permissions) can this merged, or does it require some changes? Thanks.