|
|
View previous topic :: View next topic |
Author |
Message |
weg22
Joined: 08 Jul 2005 Posts: 91
|
A/D Conversion Causing Noise in RS232 Data |
Posted: Thu Feb 01, 2007 10:50 am |
|
|
Hi all,
I'm reading in data from 2 sensors:
1. IR sensor using A/D conversion
2. SONAR sensor using software RS232
If I disconnect the IR sensor, the SONAR sensor is read flawlessly. However, if I connect the IR sensor then every 10th reading or so the SONAR data will jump 5-10 inches when holding the sensor perfectly still.
I'm powering everything off the same battery which I cannot change. I also have a 0.1 uF cap between the signal pin and ground of the IR sensor. Any suggestions on how I could get rid of the little bit of noise would be appreciated.
Thanks,
-weg |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Thu Feb 01, 2007 11:09 am |
|
|
I've used a couple of ultrasonic distance measurement sensors and they're pretty sensitive to power line variations. They tend to consume a lot of current when they're transmitting. Do you have a relatively large cap on the sonar sensor's power line? If not, try a 10 uF+, and place it close to the sensor.
What is your timing like? What I mean is how do you do your measurements, how often, and in what order? ie. read IR sensor, delay xxxx us/ms, read distance sensor, delay yyyy, repeat. Do you allow some settling time after you change a/d channel before reading the channel? Do you delay long enough to allow for the (relatively) long round trip delay of the sound wave? |
|
|
weg22
Joined: 08 Jul 2005 Posts: 91
|
|
Posted: Thu Feb 01, 2007 11:24 am |
|
|
My code is below:
Code: |
#include <16F877>
#device adc=8
#include <stdlib.h>
#include <math.h>
#define LED PIN_C0
#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0, stream=sonar1, INVERT) // SONAR #1
#use rs232(baud=9600, xmit=PIN_E1, rcv=PIN_E2, stream=PC) // TO PC
main()
{
// IR
unsigned int ir_raw1=0;
// SONAR
int i=0;
char c;
char sonarData[4];
unsigned int sonar_raw1=0, sonar_raw2=0, sonar_raw3=0;
// setup to do A/D conversion
setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
output_high(LED);
delay_ms(1500);
output_low(LED);
while(1)
{
// read in value on AN0
set_adc_channel(0);
delay_us(50);
ir_raw1 = read_adc();
// SENSOR #1
c = 'a';
while(c != 'R') {c = fgetc(sonar1);} // sonar outputs data as "Rxyz"
i=0;
for(i=0; i<=2; i++) // get next 3 bytes
{
sonarData[i] = fgetc(sonar1);
}
if(isdigit(sonarData[0]) && isdigit(sonarData[1]) && isdigit(sonarData[2]))
{
sonarData[3] = '\0';
sonar_raw1 = atoi(sonarData);
}
fprintf(PC, "%u, ", ir_raw1);
fprintf(PC, "%u\r\n", sonar_raw1);
}
} // end of main
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|