CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Unstable AD readings

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
donnie



Joined: 13 Nov 2003
Posts: 12
Location: Kissimmee Florida

View user's profile Send private message Send e-mail Visit poster's website

Unstable AD readings
PostPosted: Tue Jun 29, 2004 10:01 am     Reply with quote

Has anyone had a problem with port to port isolation ?
I have 10K pullup resistors on the A0,A1,A3 ports.
When a voltage changes on A3 it also changes the value of A0 port.

Thanks,
Donnie
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 29, 2004 12:47 pm     Reply with quote

Are you allowing enough time to pass between switching channels for the S&H capactor inside the PIC to charge/discharge to the new level?

Why did you decide you needed pull-up resistors on your ADC inputs?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
donnie



Joined: 13 Nov 2003
Posts: 12
Location: Kissimmee Florida

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jun 29, 2004 1:00 pm     Reply with quote

Iam using delay_ms(100)
If you apply the voltage from the AD8313 to Channel 4 all the channels change.

Donnie

Here is my code:
[co#include <16F876.h>
#fuses XT,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP
#DEVICE ADC=10
#use delay(clock=4000000)
#include <stdio.h>
#include <math.h>
#include <lcd1.c>
////////////////// START HERE /////////////////////////////
void main()
{
char k;
int16 RAW1;
int16 RAW2;
int16 RAW3;
int16 RAW4;
int16 data1;
int16 data2;
int16 data3;
int16 data4;

//////////////////////////////////////////////////////////
//setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
setup_adc_ports( A_ANALOG_RA3_REF );
setup_adc(ADC_CLOCK_INTERNAL);
CCP_OFF;
lcd_init();
do{

//////////////////////// CHANNEL 1 //////////////////////

set_adc_channel( 0 );
delay_ms(500);
RAW1 = Read_ADC();
//data1 = 2.25 * RAW1 - 902.5;
///////////////////////// MATH ///////////////////////////
//// ////
//// .5V = 1mw and 2V = 250mw, Reference = 2.4V ////
//// (.5V) = 1024 * .5 / 2.4 = 192 Counts ////
//// (2V) = 1024 * 1.75 / 2.4 = 747 Counts ////
//// Assume a linear sensor: The conversion from ////
//// Counts to mW is as follows: ////
//// ////
//// Slope(m) = (250 - 1) / (803 - 201) = ..414 ////
//// Offset(b) = 250 - .414 (803) = -82.44 ////
//// So mW = 0.414 * counts - 82.44 ////
//// ////
//////////////////////////////////////////////////////////
data1 = (RAW1 + (data1 * 15)) / 16;
data1 = .890 * RAW1 - 337.58;
If (data1 >= 552)
{
data1 = 0;
}
else
{
data1 = data1;
}

delay_ms(10);

///////////////////////// CHANNEL 2 //////////////////////

set_adc_channel( 1 );
delay_ms(500);
RAW2 = Read_ADC();
data2 = (RAW2 + (data2 * 15)) / 16;
data2 = 0.890 * RAW2 - 337.58;
If (data2 >= 552)
{
data2 = 0;
}
else
{
data2 = data2;
}

delay_ms(10);


///////////////////////// CHANNEL 3 //////////////////////

set_adc_channel( 2 );
delay_ms(500);
RAW3 = Read_ADC();
data3 = 0.414 * RAW3 - 82.44;
If (data3 >= 552)
{
data3 = 0;
}
else
{
data3 = data3;
}

delay_ms(10);


///////////////////////// CHANNEL 4 //////////////////////

set_adc_channel( 4 );
delay_ms(500);
RAW4 = Read_ADC();
data4 = 0.414 * RAW4 - 82.44;
If (data4 >= 552)
{
data4 = 0;
}
else
{
data4 = data4;
}

delay_ms(10);

//////////////////// DISPLAY /////////////////////////////

lcd_gotoxy(1,1);
printf(lcd_putc,"CH1:%3LumW", data1);
lcd_gotoxy(10,1);
printf(lcd_putc," CH2:%3LumW\n", data2);
printf(lcd_putc,"CH3:%3LumW", data3);
lcd_gotoxy(10,2);
printf(lcd_putc," CH4:%3LumW", data4);

///////////////////////// END ////////////////////////////
} while(true);

}


de][/code]
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 29, 2004 1:15 pm     Reply with quote

Your code looks OK but I dont' see a call to setup_adc() to configure the Tad time. You probably need at least ADC_CLOCK_DIV_8 if that is available in the header file.

Why did you decide to use pull-up resistors on an ADC input?

Is your Vdd level drooping or sagging when you apply your test voltage to AN3? Is the voltage on AN0 changing just a little bit, a lot or is it equal to AN3?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!


Last edited by rwyoung on Tue Jun 29, 2004 1:21 pm; edited 1 time in total
donnie



Joined: 13 Nov 2003
Posts: 12
Location: Kissimmee Florida

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jun 29, 2004 1:18 pm     Reply with quote

No drooping or sagging. But when i feed rf into the AD8313 Channel 1 port, you can see the voltage on channel 2 port change.
The 10K resistors are there to help make it stable incase the AD8313 goes bad.

Donnie
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 29, 2004 1:23 pm     Reply with quote

Ok, I saw your setup_adc() statement. Duh, can't read today. But I would still change it from _CLOCK_INTERNAL to CLOCK_DIV_something and see if that helps.

Also, if you look at the outputs of your AD8313 when they are NOT connected to the PIC ADC pins, do you see the same problem? Could you be coupling signal through the power supplies of the log-amps?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
donnie



Joined: 13 Nov 2003
Posts: 12
Location: Kissimmee Florida

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jun 29, 2004 1:30 pm     Reply with quote

When i take the 8313 chip out it goes to zero and the voltage don't change may have to add some caps to the signal line.
I just don't want to clamp down to much.

Donnie
xav27
Guest







ADC problem
PostPosted: Tue Jun 29, 2004 1:36 pm     Reply with quote

Hello Donnie,
in your code you have define RA3 to be the ref for the ADC !
So I think this is normal that when you change that ref. (RA3) this other input change to !?

part of 16f876.h
#define A_ANALOG_RA3_REF 0x83 // A0 A1 A2 A5 Ref=A3

hope I help you

Xavier
donnie



Joined: 13 Nov 2003
Posts: 12
Location: Kissimmee Florida

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jun 29, 2004 1:53 pm     Reply with quote

Is there a way to get it to work without the RA3 REF?


Thanks,
Donnie
Guest








PostPosted: Tue Jun 29, 2004 2:13 pm     Reply with quote

donnie wrote:
Is there a way to get it to work without the RA3 REF?


Thanks,
Donnie


Hi,

You can use
setup_adc_ports(RA0_RA1_RA3_ANALOG);

Check your device spec for:
#define RA0_RA1_RA3_ANALOG 0x84 // A0 A1 A3 Ref=Vdd

Johny
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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