When the revision of ARDUINO UNO R4 was advertised all the distributers did not hesitate to mention the built-in OPAMP though no further information about it was available, no schematics, no tutorial, nothing. Only some month later, a few lines of code were published (see credits), and the only application given was a voltage follower which is completely useless.
The Hardware PartWhat can be done with some additional passive components is a filter that amplifies or rejects certain frequencies of an analog signal. Of course, this can be done by code but this may use a lot of processing time. Analog filters operate with the speed of light (nearly). This schematics shows how to create an analog band pass:
Instructions on how to implement filters can be found online easily (see credits). But you have to consider that operational amplifiers often need a positive and a negative supply voltage which we do not have. So we have to feed half of +Vcc to the non-inverting input (+), connected to A1, That is why you find two resistors (same values) between +Vcc and GND. We choose 10 kOhms for R1 and 22 kOhms for R2. The values of C1 and C2 depend on which frequencies you are interested in. We choose 100 nF. To find the exact values, just use this formula:
The output of the operational amplifier (A3) is connected to pin A4 where the filtered signal can be sent to the internal ADC.
The Software PartTo implement this project you need to download and install the <OPAMP.h> library which can be found at github.com. I used the "start_opamp.ino" example given there and added some lines in order to test my hardware.
#include <OPAMP.h>
void setup () {
long t1 = millis() + 2000;
Serial.begin(230400);
while (!Serial & millis() < t1)
;
Serial.println(__FILE__);
// activate OPAMP, default channel 0
// Plus: Analog A1
// Minus: Analog A2
// Output: Analog A3
if (!OPAMP.begin(OPAMP_SPEED_HIGHSPEED)) {
Serial.println("Failed to start OPAMP!");
}
bool const isRunning = OPAMP.isRunning(0);
if (isRunning) {
Serial.println("OPAMP running on channel 0!");
} else {
Serial.println("OPAMP channel 0 is not running!");
}
}
void loop() {
const int N = 500;
const int m = 1023;
int a[N], b[N];
long t1 = millis();
for (int i = 0; i < N; i++) {
a[i] = analogRead(A0);
b[i] = analogRead(A4);
}
long t2 = millis();
Serial.print("Zeit =");
Serial.print(t2 - t1);
Serial.println("ms");
for (int i = 0; i < N; i++) {
Serial.print(a[i]);
Serial.print(" ");
Serial.print(m - b[i]);
Serial.println();
}
delay(2000);
}
After successfully performings tests on a breadboard I moved all the parts to a "Treedix Solderable Mini Breadboard" (www.treedix.com) and it looks like this:
To test the filter I used a guitar pitch pipe:
and got these results on the Serial Plotter (using the "old" IDE):
The time for reading the 500 samples was 25 milliseconds, so you can easily calculate the frequencies.
Comments
Please log in or sign up to comment.