# Low Pass Filter for 20 kHz PWM signal

I want sense a $20\mathrm{kHz}$ PWM signal from an electronic board. I want read this signal with "analogRead(A0)" function on my Arduino board. Therefore, I made a 1st order low pass filter that consists a resistor, capacitor and opamp buffer.

Firstly I produced a $20\mathrm{kHz}$ PWM signal from D9 pin of my Arduino. The duty cycle of PWM signal is fading with $0\mathrm{\%}$ and $100\mathrm{\%}$ continuously. The PWM generation code:

pwmWrite(led, brightness);
if (brightness == 0 || brightness == 255) {
}


According to my calculations, for $20\mathrm{kHz}$ low pass filter, resistor should be $82\mathrm{k\Omega}$ and capacitor is $100\mathrm{pF}$.

But I used $68\mathrm{k\Omega}$ resistor because don't have $82\mathrm{k\Omega}$. In this case cut off frequency of low pass filter is being $23\mathrm{kHz}$. I read this signal from A0 pin with analogRead and ADC sampling. The reading code is:

int c;
long a;
for(c=0;c <32;c++) {
a += pwm_deger;
}

int f = a / 32;
Serial.println("pwm_deger:");
Serial.println(f);
delay(200);


I've added the results below. The figures are scaled in 0-1023 (Arduino's ADC value)

• Figure 1 shows $20\mathrm{kHz}$ PWM signal that I want to test signal with fading from $0\mathrm{\%}$ to $100\mathrm{\%}$ duty cycle with $200\mathrm{ms}$.

• Figure 2 shows LPF signal without buffer.

• Figure 3 shows LPF signal from output of opamp buffer.

Is there any problem in figures? Why figure 2 shows 0.7 of 1023 and cutting after ADC value of 700. Is it because of the opamp?

### Figure 3:

• You need to post a schematic of the filter and the buffer and how you've connected it all to the Arduino. Label the parts correctly (including the op-amp part number.) – JRE Feb 23 '16 at 11:28
• You are stating there are 3 figures but only 2 are shown AND the actual RAW post shows 4 img links (1,2,4,5). Assuming the freq is 20kHz, the 3dB point will be at 20kHz and thus the amplitude will be reduced by 0.707 – JonRB Feb 23 '16 at 11:30
• Hi, I cant add anymore figure or schematic because of I dont have enough reputation. It allows me max. 2 link. – Adem Gül Feb 23 '16 at 13:14
• By the way, descriptions are already written on figures. If I tell you about schematic, there is a basic RC filter (with a resistor and capacitor) at the D9 pin of Arduino. And output of this filter goes to non-inverting input of LMV324 opamp. There is a simple buffer circuit here and output of LM324 goes to A0 analog pin of Arduino. Opamp VCC is 5V from Arduino. – Adem Gül Feb 23 '16 at 13:19