Safe to connect analogOutput(PWM) to analogInput?

Would it be safe to generate a square wave with the arduino microcontroller and then connect it to an analog input pin (also on the board) to measure the signal? This is all done on the board itself. Would doing this fry my board?

Thanks.

I think that you would want to put a resistor in between the output and input to limit the current. The input pins can't take more than 40ma. That's a resistance of at least 125 ohms (at the 5V that the output pins output).

The PWM output is not literally an analog output. It's used in an analog way, but it's really a digital output that switches between high and low at about 500 Hz. The ratio of how long it stays high to how long it stays low is how it gives you the signal (called the duty cycle).

You can connect that to either the digital or analog input pins. But you should put a 1K-10K resistor in between to avoid weirdness.

Now how you would read that signal may be a bit of a chore, I think. It's a 500 Hz signal and you would need to be careful with your coding to get the read cycles to stay in sync.

... and you may have just given me an idea on how to handle a PWM problem I've had! LOL

Yes, as already stated, there will be NO damage wiring a PWM output pin to a analog input pin, however there will also be no useful information available when the analog value is read.

What you need is a simple low pass filter comprised of a single capacitor (10mfd, 6vdc or higher) and a single resistor (4.7K ohm). Wire one end of the resistor to the PWM output pin and the other end to the analog input pin. Wire the + lead of the cap to the analog input pin and the - lead of the cap to ground.

Now as you vary the duty variable for the PWM output command the 0-255 value will be read as 0-1023 value on a analog read. Works great I've used it several times on my breadboard.

Lefty

The input pins can't take more than 40ma

AdderD, that statement doesn't make sense. Input pins will accept logic levels of 0 or (up to) 5V. At a 5V input the current taken by the pin is less than 10uA. You can't make it take more without exceeding the input voltage. The 40mA figure you have in mind is the maximum output current you can source or sink with an output pin.

Ooops... Yes, I was being dumb. You're right, that's output pins.