Weird Problem with ADC

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
jchandir
Posts: 10
Joined: Wed Apr 08, 2009 12:09 am

Weird Problem with ADC

Post by jchandir » Sun Nov 22, 2009 5:39 am

I am using a PIC 18LF2553 for a small project and am trying to sample a pressure sensor. My goal is to set -Vref to 2.0 V and Vdd at 3.0 V to increase my ADC resolution where I need it. I wrote a small piece of test code to test if my hardware is right and I have a weird problem. I am doing three 12 bit A to D conversions.

1) Pressure sensor using -ref (2.0 V) and Vdd

2) Pressure sensor using Vss and Vdd

3) Channel 2 ( my -vref channel to test that I am getting 2.0 V )



This is what my serial output looks like for the code I attached..

"-ref=0 norm=3368 chan2=2710"

My question is why am i getting 0 when using -ref?? I tested using -ref set to 1.0 V and everything was working fine but at 2.0 V (where i need it to be) I get 0?

I have tried the following:

ADC.SetConvTime(fosc_64)
adc.SetAcqTime(50)

with no luck.. I have even tried using delays after switching ADCON1.. Same result.. Any Ideas.. Thank you

Code: Select all


Sub Mode_2()
     Dim 
        achan1 As Word,
        achan2 As Word,
        achan3 As Word
          
    While true
    
      ADCON1=%00101010    // Using -vref
      achan1 = ADC.Read(0)
      DelayMS(500)
      
      ADCON1=%00001010   // Using Vss and Vdd as ref
      achan2 = ADC.Read(0)
      achan3 = ADC.Read(2)
      
      USART.Write("-ref=",DecToStr(achan1),10,"norm=",DecToStr(achan2),10,"chan2=",dectostr(achan3))
      DelayMS(500)
    
        If escape = true Then
            Break
        EndIf
     
    Wend 

End Sub

jchandir
Posts: 10
Joined: Wed Apr 08, 2009 12:09 am

Post by jchandir » Sun Nov 22, 2009 6:15 am

I think I answered my own question by reading the ELECTRICAL CHARACTERISTICS in the data sheet... A minimum delta between the two is needed for the ADC to function properly (3.0 V) .. Thanks

Post Reply