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

Extrange changes in ADC

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



Joined: 17 Aug 2004
Posts: 12

View user's profile Send private message

Extrange changes in ADC
PostPosted: Tue Aug 24, 2004 3:05 am     Reply with quote

Hi, I know another problem.
In the ADC the values moves a lot in my 16f876 with CCS 3.187.
My fuses are NOPUT, NOBRW, NOLVP, WRT
I have this connections:
A0= v. of a fan
A1=LM35 (with 2k2 resistor between out and pic)
A2=v. of another fan
A3=5v reference (7805)
A5=another LM35 (with 2k2 resistor between out and pic)

Now I program this:
Code:
#INCLUDE <16F876.h>
#DEVICE ADC=10
#USE delay (clock = 4000000)
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7)
void main(){
   int channel = 0;
   int16 data = 0;
   set_tris_A(0xFF);
   setup_port_a( RA0_RA1_ANALOG_RA3_REF );
   delay_ms(100);
   setup_adc( ADC_CLOCK_DIV_32 );
   delay_ms(100);
   do{
      delay_ms(100);
      set_adc_channel(channel);
      delay_ms(100);
      data= Read_ADC();
      delay_ms(100);
      printf("C%i=%Lu",channel, data);
      if (channel==5){
         printf("\r"); channel=0;
      }else{
         printf(" - "); channel++;
      }
   } while(true);
}


I run the program and I read this in hyperterminal:
Code:
C0=0 - C1=64 - C2=0 - C3=1018 - C4=51 - C5=58
C0=2 - C1=64 - C2=0 - C3=1023 - C4=58 - C5=56
C0=0 - C1=55 - C2=0 - C3=1022 - C4=60 - C5=56
C0=2 - C1=59 - C2=0 - C3=1023 - C4=64 - C5=56
C0=0 - C1=58 - C2=2 - C3=1022 - C4=60 - C5=60
C0=1 - C1=60 - C2=0 - C3=1022 - C4=55 - C5=56
C0=1 - C1=57 - C2=0 - C3=1023 - C4=60 - C5=56
C0=0 - C1=59 - C2=2 - C3=1023 - C4=57 - C5=57
C0=4 - C1=60 - C2=1 - C3=1021 - C4=57 - C5=55
C0=0 - C1=58 - C2=1 - C3=1023 - C4=61 - C5=58
C0=0 - C1=58 - C2=1 - C3=1022 - C4=60 - C5=56
C0=0 - C1=51 - C2=0 - C3=1023 - C4=58 - C5=56
C0=0 - C1=56 - C2=0 - C3=1021 - C4=60 - C5=57
C0=0 - C1=58 - C2=0 - C3=1022 - C4=56 - C5=57
C0=4 - C1=58 - C2=0 - C3=1019 - C4=51 - C5=60
C0=2 - C1=59 - C2=0 - C3=1022 - C4=56 - C5=56
C0=0 - C1=58 - C2=0 - C3=1023 - C4=56 - C5=56
C0=0 - C1=55 - C2=0 - C3=1023 - C4=59 - C5=51
C0=0 - C1=59 - C2=3 - C3=1023 - C4=59 - C5=51
C0=1 - C1=58 - C2=0 - C3=1022 - C4=60 - C5=56
C0=0 - C1=57 - C2=0 - C3=1022 - C4=55 - C5=60
C0=1 - C1=61 - C2=2 - C3=1023 - C4=60 - C5=60
C0=0 - C1=60 - C2=0 - C3=1023 - C4=57 - C5=58
C0=0 - C1=60 - C2=0 - C3=1023 - C4=57 - C5=56

The fans are OFF and the pic tell that there is v. from 0 to 4 steps, but it doesn�t the matter for me, the problem is in the LM35. I�m reading a polymeter, and the LM35 (after the resistence) give in all moment 0,27 v. (27� * 10 mV/�) continous. But as you can see, the pic oscilate a lot, in a few seconds put values from 51 to 61. Translating it to temperature:
5/1024 = 0,0048828125 * 51 = 0,2490234375 (aprox. 25�)
5/1024 = 0,0048828125 * 61 = 0,2978515625 (aprox. 30�)
5 degrees of diference in 3 seconds!!! Incredible.
I tested the circuit, all the voltages are right, the 7805 is constant, and the LM35, after resistence of 2k2 too. I changed the pic for another new, I changed the divisor for internal_RTC, I changed to all_analog forgetting the reference of 7805, and in all cases, the same results, more or less.
Why the pic is doing that????
How can I get a good measure? Is there anything wrong in my code?
Thank you very much for your ideas
Verba
Ttelmah
Guest







PostPosted: Tue Aug 24, 2004 3:20 am     Reply with quote

I'd be very suspicious that your 78o5, is not stable as a voltage reference. These are not designed to be an accurate voltage reference. The fact that the reading from this (third column), fluctuates by five counts, implies there is a problem here (it should always read 1023). Even though I'd not rate this chip as an accurate source, if stable, it should give a steady reading. I'd perhaps suspect it is oscillating - what load is on it?. Generally the 7805, requires hf decoupling caps by it's output, and a minimum load. The test parameters for a 78L05, have a minimum load of 1mA, and for a 7805, 5mA. The load on the regulator will be changing as the AD reading is made...

Best Wishes
verba



Joined: 17 Aug 2004
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 24, 2004 3:29 am     Reply with quote

Thanks for your answer
I have a professional polymeter and the 7805 is giving me a constant value of 4,985. I have in the circuit the capacitors 0,33 uF and 0,1 uF.
And another question, if I put in the code that the A3 is reference, how can fluctuate there??? It�s supossed that is comparing the same value with itself.
Something is wrong, and I don�t know what is happening.
Ideas please
Thanks
Verba
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Aug 24, 2004 4:21 pm     Reply with quote

A few remarks.
Quote:
I have a professional polymeter and the 7805 is giving me a constant value of 4,985.
Multimeters will give you an average reading. Your PIC measures a maximum voltage difference of 10 units or 0,05V, it is very well possible that a high frequency imposed signal is not showing on your multimeter.

Quote:
I have in the circuit the capacitors 0,33 uF and 0,1 uF.
Are these the only capacitors in your circuit? If yes, then this might be not sufficient. The 7805 regulators are suceptible to oscillation, therefor they require a 100uF - 470uF electrolytic capacitor at the high voltage side and both an 1uF - 47uF tantalum and, very important, a 100nF ceramic or aluminum capacitor at the low voltage side. See this link for a schematic.

Looking at the datasheet for the 7805 you will see that at load fluctuations the output voltage can change 25mV or 0,025V. This might seem like peanuts, but in your circuit this is equal to 5 units or 2.5�C.

With the LM35 output voltage changing between 0,0V and 1,0V from 0 to 100�C and a reference voltage of 5V you are only using 20% of the possible dynamic range.

Do you have long wires on the LM35, or wires running close to motors (fans...)? If yes, you might need to add an RC-damping ciruit, see the LM35 datasheets.

My suggestion: Check the used decoupling capacitors at the 7805 and replace the reference voltage by a true reference voltage generator like the LM385-1.2 which at 1.2V gives you a 4 times improvement in dynamic range.
verba



Joined: 17 Aug 2004
Posts: 12

View user's profile Send private message

I can�t do that now
PostPosted: Thu Aug 26, 2004 3:22 am     Reply with quote

Thank you very much for your suggestions.
Unafortunately, I can�t do that modifications in my circuit now
I only can do 20 measures and then calculate the average, I know that isn�t a true value, but it�s that I can do now to solve the problem, or anybody has any idea to get more accuracy with the circuit in pcb?
Thanks everybody
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Aug 26, 2004 3:30 am     Reply with quote

We think your problem is in the power supply not being stable, but there might be another problem. Just for making sure it would be nice if you could do a quick test with a more stable power supply. I mean a quick and dirty hardware hack, bypassing the 7805.
verba



Joined: 17 Aug 2004
Posts: 12

View user's profile Send private message

Thanks
PostPosted: Thu Aug 26, 2004 11:30 am     Reply with quote

Thank you, I will try your suggestion.
If anybody has more ideas they will be welcomed.
Thanks everybody
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 26, 2004 11:48 am     Reply with quote

For lots of information on the LM35, search the Usenet archives:

Go here:
http://www.google.com/advanced_group_search?hl=en

Paste this string in the top box and hit the search button:
LM35 stable OR stability OR accurate OR accuracy

You get tons of people's experience and comments on the LM35.
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