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 support@ccsinfo.com

Why when I got a data is problem?

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



Joined: 23 Sep 2003
Posts: 12
Location: South KOREA

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

Why when I got a data is problem?
PostPosted: Sun Feb 20, 2005 1:12 am     Reply with quote

Dear Master~!

Hi~
When I got a ADC data is problem
It's about 30-40 is different....
1st 129
2nd 135
3th 110
4th 140

That's same volte

and float data is can't operation.

Please check my code....
Thank you~!


Code:
#include<16F874.h>
#device pic16f874 *=8 adc=10
#use delay(clock=4000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C4,rcv=PIN_C5)//,ERRORS,stream = PORT1)
#zero_ram

// A0 (02) = [AD] humidity (0.8 - 3.9 V)
// A1 (03) = [AD] Temp (0.0 - 5.0 V)
// A2 (04) = [AD] Vref - (0.8 V)
// A3 (05) = [AD] Vref + (3.9 V)
// A4 (06) =
// A5 (07) =

int16 value = 0;
float humi = 0 , temp = 0;

void Read_Humity()
{
   setup_adc_ports(RA0_ANALOG_RA3_RA2_REF);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(pin_a0);
   delay_us(10);
   value = read_adc();
   setup_adc( ADC_OFF );
   humi = ((value*5)/1023);
   printf("%c%c%c",0xa1,0,1);
   printf("%cAD=%04lu Humi=%02f %c",0xa2, value, humi, 0);
}

void Read_Temp()
{
   setup_adc_ports(RA0_RA1_RA3_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(pin_a1);
   delay_us(10);
   value = read_adc();
   setup_adc( ADC_OFF );
   temp = ((value*5)/1023);
   printf("%c%c%c",0xa1,0,2);
   printf("%cAD=%04ld Temp=%02f%c",0xa2, value, temp, 0);
}

void main()
{
   ext_int_edge(0,L_TO_H);
   enable_interrupts(int_ext);
   enable_interrupts(global);
                        // 7 6 5 4 3 2 1 0
   set_tris_a(0x3F);    //     I I I I I I
   set_tris_b(0xFF);    // I I I I I I I I
   set_tris_c(0x00);    // O O O O O O O O
   set_tris_d(0x00);    // O O O O O O O O
   set_tris_e(0xFF);    //           I I I

   output_c(0x00);
   output_d(0x00);
   output_e(0x00);

   while(1)
   {
      Read_Temp();
      Read_Humity();
      delay_ms(1000);
   }
}

_________________
Hello~?

This is South KOREA
My name is Sanghyouk Kim But Call me Nick
Sorry I'm poor English
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 6:23 am     Reply with quote

channels are numbered 0-12, so use
Code:
set_adc_channel(0);   //for AN0
set_adc_channel(1);   //for AN1

instead PIN_A0, PIN_A1, these PIN_XX are defined to some higher values, you might have had luck, it got truncated to the lower bits, so this is not causing your problem.
If you get valid readings, but the values are floating, then try to increase the wait time in the delay_us to let thing settle.
It can be a hardware design problem also. Noise can cause these problems, is your VREFs of a proper impedance? (put capacitors on your Vrefs) What is the impedance of your analog signals? If you have a slow moving signal anyway, you can put a capacitor on your signal to filter noise.
To lessen digital noise in the PIC itself, you can also consider putting the PIC into sleep during conversion with (but you should have smoother readings without this sleep thing also)
Code:
read_adc(ADC_START_ONLY);
sleep();
value=read_adc(ADC_READ_ONLY);
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