3
\$\begingroup\$

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);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ; 
}   

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++) {
    pwm_deger=analogRead(A0);
    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 1

Figure 1 - Test Signal


Figure 2:

Figure 2 - Output signal from LPF without buffer opamp


Figure 3:

Figure 3 - LPF output with buffer opamp

\$\endgroup\$
  • 1
    \$\begingroup\$ 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.) \$\endgroup\$ – JRE Feb 23 '16 at 11:28
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – JonRB Feb 23 '16 at 11:30
  • \$\begingroup\$ Hi, I cant add anymore figure or schematic because of I dont have enough reputation. It allows me max. 2 link. \$\endgroup\$ – Adem Gül Feb 23 '16 at 13:14
  • \$\begingroup\$ 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. \$\endgroup\$ – Adem Gül Feb 23 '16 at 13:19
4
\$\begingroup\$

Why figure 2 shows 0.7 of 1023 and cutting after ADC value of 700. Is it for opamp?

You almost certainly need to use a rail to rail (R2R) op-amp that is capable of producing a decent output close to the top power rail. If you are using something like an LM324, the soft clamping you see at the top of the waveform is likely due to it not being R2R on the high parts of the input signal and also on the high parts of the output signal.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your reply. Yes, I used LMV324 in my project. Can you suggest me any R2R opamp with effective cost? \$\endgroup\$ – Adem Gül Feb 23 '16 at 13:12
  • \$\begingroup\$ @AdemGül not really. Try using someone like TI or ADI but TI are probably going to be cheapest. \$\endgroup\$ – Andy aka Feb 23 '16 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.