0
\$\begingroup\$

I used this code to generate a 32kHz 50% duty cycle PWM output:

int pwmpin = 3;
void setup()
  TCCR2B = TCCR2B & B11111000 | B00000001;
  pinMode(pwmpin, OUTPUT);
}

void loop() {
  int pwmvalue = 511;
  pwmvalue = map(pwmvalue, 0, 1023, 0, 255);
  analogWrite(pwmpin, pwmvalue);
}

The output signal looks like this (shows 2 signals), why? the oscilloscope is properly calibrated.

enter image description here

\$\endgroup\$
11
  • \$\begingroup\$ Are you concerned that the signals overlap, or that they have spikes at the transitions? \$\endgroup\$
    – JRE
    Commented Dec 23, 2020 at 15:50
  • \$\begingroup\$ Both actually, but most importantly why do they overlap? \$\endgroup\$ Commented Dec 23, 2020 at 15:51
  • \$\begingroup\$ There's a { missing after void setup(). Is this the actual code you used? \$\endgroup\$
    – ocrdu
    Commented Dec 23, 2020 at 15:53
  • 2
    \$\begingroup\$ Your ground connection between MCU and scope is broken? \$\endgroup\$
    – Justme
    Commented Dec 23, 2020 at 15:57
  • 1
    \$\begingroup\$ Turn the timebase down so that you're seeing at least one full cycle of your local power line frequency (so, around 2ms per division). If you see a sine wave impressed on your signal, you've got a grounding problem. It'll be pretty obvious, and it's a dead easy test. Any time you see your scope trace looking weird you should zoom in and out and look at different time scales. \$\endgroup\$
    – TimWescott
    Commented Dec 23, 2020 at 16:40

1 Answer 1

0
\$\begingroup\$

To solve this problem you can connect the Arduino to power supply so the ground of the Arduino will not be broken with the scope

\$\endgroup\$
1
  • \$\begingroup\$ Not really. What is needed is to connect the scope's probe ground to the circuit being examined. Some types of power supplies may make that unsafe to even do, though hopefully the asker does not have one. Relying on the mains ground through both a power supply and the scope's mains supply is a poor choice of ground reference to take a high frequency measurement as that is a very long path; but the probe grounding does need to not be inconsistent with a mutual ground through the mains. \$\endgroup\$ Commented Dec 27, 2020 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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