AnalogIn random blips

26 Oct 2010 . Edited: 26 Oct 2010

After a bunch of tweaking and debugging, I have found no valid reason for why I'm getting a ton of random "blips" when I read in an AnalogIn pin. By a "ton" I mean, ranging from every 60ms to 200 ms apart, but consecutive "blips" are never the same interval apart.

Even when NO SIGNAL is attached to the pin, the mbed still detects a few 1.0's or .99's, even some other values. The blips are not periodic and do not hold a constant value. They show up when I do an AnalogIn read followed by an immediate AnalogOut write. They show up when I write the read value to the filesystem or output through serial.

They go away when I comment out the "sample.read()" command. assigning a value to my input buffer, and then assigning that value to an AnalogOut pin does not cause these blips.

Here's my code. It's real simple, read in a value from an AnalogIn pin, at a certain sampling frequency (3000Hz) and output that read value.

The output DOES look like the input signal, but with this bizarre added "noise".


#include "mbed.h"

AnalogOut mout0(p18);
AnalogIn signal(p16);
Ticker sample;
signed int i;
signed int j;
double count=1;
char tog=0;
static float xin[taps];
LocalFileSystem local("local");

Serial pc(USBTX, USBRX);

void Take_sample();


int main() {
 sample.attach_us(&Take_sample,333);
 pc.baud(921600);
 //FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
 //fprintf(fp, "Analog Input Trial\n\n");
 while (1) {
 if (tog==1) {
 /* if(count>50000)
 break;
 else
 fprintf(fp, "%.4f\n",xin[0]);*/
 tog = 0;
 }
 }
 //fprintf(fp, "\n\nEnd of File.");
 //fclose(fp);
 return 0;
}

void Take_sample() {
 if (tog==0) {
 count++;
 xin[0] = signal.read();
 mout0=xin[0];
 tog = 1;
 }
}
26 Oct 2010

Sounds like you're getting noise. See this thread on some ways to reduce it.

26 Oct 2010

oh man, Igor, life saver.

I've been so frusterated the last 2 days, I must have overlooked the years it took to get my electrical engineering degree and forgot that the term "ideal" applies to NOTHING! :-D

 

again, thank you. fixed it with a low pass.

cheers,

Mike.