Hi everyone, first time i post here. I've built a small circuit to see how different capacitors would filter a pulsating signal at different frequencies. To do that i used analogRead pins to read the voltage. The readings are fine without the capacitors (it reads 5v when OUTPUT pin is high and 0 v when is low) and with the 100uf electrolytic capacitor (with a frequency of 1hz and 20k ohm resistance the results match with an LTSpice simulation of the circuit), but with the 100nf ceramic capacitor, instead of getting results similar to those with no capacitor, analogRead reads basically a constant voltage, while it obviously isn't (i've put an LED in series with the resistors and it turns on and off like it should).
Any idea why this happens?
Isn't it basically the same thing? I've put the Load resistors after the capacitor and a diode before it because i wanted to replicate the filtering that happens in power supplies... anyway it doesn't explain why analogRead doesn't read the voltage correctly with the 100nf ceramic capacitor
Yes, i am feeding an 1hz signal right now , but the weird reading also happens with all the frequency i tested: 0.5hz (the one in the graph above), 10hz and 50hz
That's exactly what happens on the circuit, but when using the small 100nf capacitor analogRead reads basically a perfect DC voltage even at very low frequency, when it should read, as you said, almost a square wave.
If i put an LED in series with the load resistors with low frequency when using the small 100nf capacitor, it obviously turns on and off like it should, but AnalogRead instead of reading 4.38V and then almost 0V reads 4.38v and then 4.28v, which is obviously incorrect
to prevent floats from being converted to ints, I learned to make sure all the ints in a float calculation are cast as floats.
Such as float Volt1 = (float)Lettura1 * (5.0 / 1023.0); is more likely to result in a float.
I'll try putting a 10ms delay between the analogReads and when i change B to either true or false, although the weird thing is that with the bigger capacitor everything works fine.
Edit: tried it, nothing changes.... regardless of the frequency it keeps reading 4.37 to 4.27 with that small capacitor
On the serial monitor i should see the highest voltage and then the lowest voltage, because when the output pin is high the voltage is just constant, while when the output pin is low i am measuring the voltage immediately before the voltage is again set to high... this is working fine with the large capacitor, while with the smaller one the reading is weird:
e.g this is the 100uf electrolytic capacitor at 0.5 hz and the high and lows match the graph in the first post
When you call Serial.print you are printing the value that was captured at the time analogRead was called - just after the digitalWrite. Of course this does not explain behavior of the 100nF cap. I suspect some wiring mistake (e.g. no connection to the pull-down resistor).
This also explans the observed behavior. Note the "tooths" has an opposite polarity when some cap is present vs no capacitor. When no cap is present the minimum is when D13 pin is LOW and maximum when the pin is HIGH - simple. But with a capacitor it is reversed:
At the moment you turn D13 LOW the capacitor is charged and the pull-down starts slooowly discharging it. At the moment you sample it and measure nearly supply voltage.
After this the capacitor discharges during the looong delay. When you turn the pin HIGH it starts charging quickly - but not instantly. The small 100nf cap charges nearly to Vcc before the sampling but the large 100uF cap is only about halfway charged before it is smapled.