My hardware configuration:
My Arduino connection:
Obviously, you can see that these signals are not square waves and my PWM = 50% or 0.5.
How do I fix this?
You're not sampling fast enough, as per the Nyquist theorem, you need to sample at least twice faster as the maximum frequency of interest.
More over, you're sampling one sample for every duty-cycle which is not even a waveform.
So do you think maybe I should have two loops.
one loop that writes PWM at a slower rate (maybe 1000 ms) and another that reads PWM very fast (10 ms).
what do you think? Is that a good approach? What would be your suggestion?
These should give you better looking representation of the PWM Generated but not the realistic one as Arduino's are not DAQ devices to sample at a high rate and stream with reliable timing accuracy to the PC.