PWM voltage decay

Hello,

I am using an arduino uno r3, and I am having some issues with the digital write function. More specifically, the voltage outputted decays over time (it seems fine in the microsecond range, but I need to output in the millisecond range). The following test code and photos illustrate my issue.

int pin = 3;
 
 
void setup()
{
  pinMode(pin, OUTPUT);
}
 
 
void loop()
{
  digitalWrite(pin,HIGH);
  delay(1000);
  digitalWrite(pin,LOW);
  delay(1000);
}

(I used a different delay at the time of taking the pictures).
Imgur: The magic of the Internet (The problem I am experiencing)
http://imgur.com/afe3C9C (does not seem to occur at high frequency)
I do not have much ardunio experience, although i have tried using several different pins, and i have tried measuring the voltage across a resistor connected from the pin to ground. The strange thing is that on a previous arduino board i was using the pulses did not decay as depicted, and this problem has existed on two seperate baords. The board is connected via usb to my computer, there are no other accessories attached, and the measurement is taken via oscilloscope. Does anyone have any idea why this is happening?
Thank you for your time.

Which oscilloscope? Does the oscilloscope pull more than 5v at any certain point? That would give out false PWM I believe. Otherwise I don't think I've ever come across a decaying or changing PWM...

It is a tektronix tds 2002. The oscilloscope does not seem to be giving a reading past 5v. Maybe decaying isnt the best way of describing it. But as shown in the image, the voltage does not remain constant over a square wave, and produces a downward spike at the point where digitalWrite(pin,LOW) is called.

Where are your resistors in the circuit? How do you have it connected? At lower freq pulse I believe unless you have a small resistor in line there can be 'static'. Sorry man I'm just a noob trying to learn more too, but that sounds along the right line of reasoning. Hope I'm at least being helpful. :slight_smile:

You have your oscilloscope set for AC coupling (see the first image). This is expected behavior.

Next time, set the oscilloscope for DC coupling!

Thanks for the help! The square waves work perfectly now. Vaj was right, I'll pay more attention to what im doing with the oscilloscope next time :). (my resistor was connected from a digital output pin, I think it was 3, to the ground pin).