Hey there,
high school junior here who was recently introduced to arduinos for a school science fair project. I apologize for my inexperience, but the point of my project is examine the comparative performance of various noise reduction techniques, the focus being on active and passive low-pass filters (if the project even makes sense? - i only chose it due to signal processing seeming interesting to me).
In any case, due to a limited time-frame, lack of resources, and an uncompetitive school, i'm planning on using an arduino with a DAC0808LCN as a substitute to a function generator (not sure if it even works), and can't seem to get a proper output from it? I'm using the 5v output of the arduino, connected to my laptop, but only seem read 0.2v on my oscope (albeit a low-end one). The wiring seems to match the datasheets, so I’m a bit lost.
Anyways, I'd like to know what the source of the problem is, whether it was on my part (in which i'd be open to sending photos of the breadboard or provide more information), or if its a matter of the feasibility of the project itself, meaning i'll have to scrap the project and think of another one.
We can't see your setup, so the best we can do is make educated guesses. Please post an annotated schematic that shows exactly how you plan to wire it. A photo may also be helpful. Make sure to check with your instructor to confirm you're reading the oscilloscope correctly. Below are two example schematics: one for a low-pass filter and one for a high-pass filter.
Hey, thanks for the responses.
To clarify, im doing this project on my own, and i know no one else in my country with expertise in these stuff.
Sadly, it seems that new users can't attach photos
Oh damn, thanks.
I can't seem to find any other DACs for sale in my country, nor am i in a position to order from abroad.
At this point - and i apologize for the possibly stupid question but, do you reckon i should just change the topic? I can't seem to find any alternatives for generating a signal that's affordable.
That DAC is a very old dual supply design and a poor choice for this application. With an Arduino you would have trouble driving it at a high enough rate to make a function generator.
I would suggest looking at a module using the AD9833 DDS chip which is designed for this sort of application. They run $9-$20 depending on the features on the board. There are several articles on the web about interfacing them to an Arduino. Sine wave output is realistically limited to 2-3Mhz where distortion becomes a problem due to the limited number of samples.
I suggest to start by using a PWM (servo, analogWrite) output as a function generator. This is automatic and produces a low frequency square or rectangular wave, with lots of high frequency components, which is ideal for studying the effect of a low pass filter.
In setup(), for example issue the command analogWrite(pin_number, 127); and examine the output of (pin_number).
However, there is no need to even have one of those chips just to produce an function generator output. All you do is to produce a high frequency PWM signal by changing the PWM prescaller registers. Then you use an analog write to that pin to modulate the required function.
You need what is called a "restoration filter" to remove the high frequency and leave just your function. This is just the RC filter shown in post #2.
By using two timers and a wave table to define the wave shape you can automate the signal generation process, leaving you loop function nothing to do. This is the block diagram showing what is going on.
#include <avr/interrupt.h> // Use timer interrupt library
/******** Sine wave parameters ********/
#define PI2 6.283185 // 2*PI saves calculation later
#define AMP 127 // Scaling factor for sine wave
#define OFFSET 128 // Offset shifts wave to all >0 values
/******** Lookup table ********/
#define LENGTH 256 // Length of the wave lookup table
byte wave[LENGTH]; // Storage for waveform
void setup() {
/* Populate the waveform table with a sine wave */
for (int i=0; i<LENGTH; i++) { // Step across wave table
float v = (AMP*sin((PI2/LENGTH)*i)); // Compute value
wave[i] = int(v+OFFSET); // Store value as integer
}
/****Set timer1 for 8-bit fast PWM output ****/
pinMode(9, OUTPUT); // Make timer’s PWM pin an output
TCCR1B = (1 << CS10); // Set prescaler to full 16MHz
TCCR1A |= (1 << COM1A1); // Pin low when TCNT1=OCR1A
TCCR1A |= (1 << WGM10); // Use 8-bit fast PWM mode
TCCR1B |= (1 << WGM12);
/******** Set up timer2 to call ISR ********/
TCCR2A = 0; // No options in control register A
TCCR2B = (1 << CS21); // Set prescaler to divide by 8
TIMSK2 = (1 << OCIE2A); // Call ISR when TCNT2 = OCRA2
OCR2A = 32; // Set frequency of generated wave
sei(); // Enable interrupts to generate waveform!
}
void loop() { // Nothing to do!
}
/******** Called every time TCNT2 = OCR2A ********/
ISR(TIMER2_COMPA_vect) { // Called when TCNT2 == OCR2A
static byte index=0; // Points to each table entry
OCR1AL = wave[index++]; // Update the PWM output
asm("NOP;NOP");
TCNT2 = 6; // Timing to compensate for ISR run time
}
You can probably do a bunch of filter testing just using the square-ish waves output by the tone library available on Arduinos, and that would probably be a more appropriate complexity level for a short timeframe project. While there would be "interesting" side effects because of the harmonics in a square wave, you ought to see the same sorts of low-pass affects on the base frequency as it changes.