issues on PWM sine wave generator

gcjr:
each iteration of your code takes ~200+ usec and 90 samples per cycle. only 16 usec when using a table of pre-calculated values.

You can change my code to use a table if you want the speed, the point is that's
phase is a linear function of time, so just have to multiply time by a suitable factor.

have you ever written DSP code? voice communication sampled at 8 kHz or 125 usec.

Oh yes, usually 24 bit / 192kHz in fact.

This thread is about synthesizing a 50Hz sine wave in PWM, not audio sampling.

gia
what are the values of your R and C? i think you're filtering too much

MarkT:
All this complicated code when you can just do:

Your code produces 10 + 10 mS waves, but they are a mess because I think the hardware pwm on the Arduino is not suitable to generate square waves above a certain frequency.
I'll try an array as soon as I have time.

Dear gcjr, I tried your 8th July 2020 code with the shortest array, the 28-element one, but the result is the same: a faster pulse but no pause between the semi-waves.
I made a video and uploaded it to youtube in case you want to see it:

Note: it's 5 ms/div. You can slow down the video with the appropriate youtube command

I apologize for my long silence, but for the moment I have abandoned the use of Arduino and therefore I have not solved my problem.
I will keep you informed if I'll solve my problem.
Thank you.