so i want to generate a PWM signal using the arduino interrupts on the the specific pins , a mate told me that with a capacitor you can actually turn the frequency(0v-5v) into a veritable voltage , before i thought that systems actually round the signal to a voltage ,
what i did learn about capacitors is the discharge and charge processes i have some differential equations on that but none allows you to determine an accurate voltage value out of a specific frequency (or that's as far as i know)
so how does this work
+in lessons , they did mention that a perfect generator of current is needed for the correct speculation of the capacitors charge , the generator of current seems to be a generator that supplies a voltage that is independent from the charge (internal resistance = 0)
can an arduino pin work like that ?
There are 6 pins on an Uno that support PWM output, driven be specific timer/counter hardware in the 328P chip.
You can filter that thru a 4.7K resistor/10uF cap (RC lowpass filter) to create a DC level output.
For example, here is the filtered output of a PWM pin, with code
You actually need a resistor AND a capacitor to make a [u]low-pass RC filter[/u]. A low-pass filter has no effect on constant voltages or (relatively) slowly changing voltages (low frequencies) but it blocks (or reduces) fast changes or high frequencies. i.e. It can be used to "smooth out" or "average" PWM.
As a rough starting-point you can use the [u]RC time constant[/u] which is the resistance (in Ohms) multiplied by the capacitance (in Farads) and it's the time it takes for a capacitor to charge to about 63 percent of the applied DC voltage (or discharge by 63 percent. For example, a 1uF capacitor and a 1 meghom resistor have a time-constant of 1 second.
In any RC circuit, you also have to take into account the source impedance/resistance and the load impedance/resistance. With the Arduino, you can usually ignore the source impedance because it's usually low relative to the series resistor. But, if the load resistance (which is in parallel with the capacitor) is too low that can reduce your time constant or affect your RC filter.
Always use a resistor before the capacitor - ie don't connect a capacitor to a pin and ground if its
an output pin.
An RC low pass filter has a simple first-order exponential decay behaviour with a time constant
of RC seconds (where R measured in ohms and C in farads).
For Arduino PWM I'd suggest a roll-off frequency of 20 Hz or less, ie a time constant of 8ms or more,
then you'll get reasonably low ripple on the output. For instance 10k x 1uF = 10ms
time constant t = 1 /(2 pi f)
Roll off frequency is where the filtering starts to take effect.
In this case the frequency will stay the same (Arduino Playground - PwmFrequency) but the time on @ 5V and off @ 0V will change. By exemple a 25% On time and a 75% Off time should stabilize the voltage value at around 1.25V, with a 50%/50% on time/off time it should give you around 2.5V, etc. Take note that the voltage may change according to the charge used out of the capacitor. Personnaly I would like to make sure that the capacitor is large enough to smooth the voltage ripple but not too large to get a voltage stability quickly (depending of my application) and use a resistor large enough to do not damage my Arduino with current greater than 40 mA. By exemple : 5V/0.02A = 250 Ohms I would use a 270 Ohms resistor (Unless I control and use an external transistor...).
For the current regulator part I would use an analog pin to sense the voltage through a resistor and then adjust the pmw signal accordingly. By exemple if I need to control a 10mA current, I would measure it through a 25 Ohms resistor. As V=RI, V=25Ohms0.01A=0.25V. My analog input should read around 0.25V/5V1023=51 and control it using the digital pmw pin. I hope it'll answer some of your questions.
amine2:
+in lessons , they did mention that a perfect generator of current is needed for the correct speculation of the capacitors charge , the generator of current seems to be a generator that supplies a voltage that is independent from the charge (internal resistance = 0)
can an arduino pin work like that ?
No. A perfect current generator is one where the current, not the voltage, is independent of the voltage.
No. An Arduino pin cannot act like that although, with some external circuitry, you could approximate to it.
Wow! Those lessons really confused you, didn't they?
amine2:
so i want to generate a PWM signal using the Arduino interrupts on the the specific pins
This has nothing whatsoever to do with interrupts.
amine2:
a mate told me that with a capacitor you can actually turn the frequency(0v-5v) into a veritable voltage , before i thought that systems actually round the signal to a voltage
And in the case of a low-pass filter, "rounding" the signal to a voltage is a pretty good way to put it. The voltage is not constant due to the presence of residual ripple, and not accurate.
amine2:
what i did learn about capacitors is the discharge and charge processes I have some differential equations on that but none allows you to determine an accurate voltage value out of a specific frequency (or that's as far as i know)
The equations work just fine, but you have to know what you are doing with them.
amine2:
in lessons , they did mention that a perfect generator of current is needed for the correct speculation of the capacitors charge
No, the equations perfectly predict the behaviour of a resistor feeding a capacitor. A constant current is only needed if you want the capacitor to charge at a constant rate. With a resistor it is exponential.
amine2:
the generator of current seems to be a generator that supplies a voltage that is independent from the charge (internal resistance = 0)
A constant current generator emulates an infinite internal resistance.