4

I used my Arduino Uno's pin 3 to generate a PWM output. The code is:

void setup() {
  // Put your setup code here, to run once:
}

void loop() {
  analogWrite(3, 180);
}

I connected the output directly with a oscilloscope. And the output waveform is shown below:

PWM waveform

I found it's weird that the minimum voltage is negative! And with the duty cycle increasing, both the maximum voltage and minimum voltage decrease. Why does it behave in such a way?

  • 2
    Oh my god! It's due to the setting of the oscilloscope. I reset it and now it's works normally. – Legend Lee Jul 12 '16 at 2:20
  • But I still don't know which setting is not right...Can you guys help me? – Legend Lee Jul 12 '16 at 2:21
  • There is no need to have the analogWrite call in loop() - it only needs to be called once (the hardware automatically generates the PWM signal - no software is involved). It can and should be moved to setup(). – Peter Mortensen Jul 12 '16 at 13:05
13

At first you had the scope AC (Alternating Current) coupled. Then you switched it to DC (Direct Current) coupled.

AC coupling is used to remove the DC component of a signal. It places a large capacitor between the probe and the internal amplifier. This is used, for instance, if you want to see a small signal with a large DC offset. But it can also attenuate and / or alter signals that are low in frequency.

When a PWM signal is AC coupled to an oscilloscope, an interesting phenomenon occurs. As the duty cycle goes from a minimum (almost always off) to a maximum (almost always on) the DC component of the PWM signal changes. Since the DC component is blocked by the AC coupling, the PWM signal appears to move lower on the screen as the duty cycle increases.

DC coupling is where there is no coupling capacitor between the probe and the internal amplifier. Everything comes through. For digital electronics where the signal travels a small distance from 0 to 5 volts or from 0 to 3.3 volts, this is the best way to use the scope.

  • Incidentally - you see how the top and bottom of the waveform are sloping down and up slightly? This is indicative of the charging and discharging of the AC coupling capacitor by the low frequency component of the waveform. – Majenko Jul 12 '16 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.