The analogWrite() function's waveform has a weird behaviour on my Arduino Uno. I checked it with an oscilloscope. (The pulses were checked between the respective pin and Arduino's GND)
At close to zero duty cycle input to the function (the second parameter of the function, range: 0-255), it would be between 0 and 5V (as expected), however, the higher that the duty cycle value went, the pulses started going into negatives, till at close to 255 (almost 100% duty cycle), the pulses would be between -5V and 0V.
Furthermore using an RFduino (I know it is completely different hardware), the analogWrite() function generates pulses between -1.7V and 1.7V, rather than 0V and 3V.
The attached code is the one I used on Uno. It is supposed to be control of motor speeds by varying duty cycles (using a MOSFET for switching). But for now, I am just interested in the waveform of the analogWrite() function.
So, does anyone know what the problem is? How the analogWrite() function of Arduino really works?
Thanks in advance.
Project_Echo.ino (1.21 KB)