Adc for pic 18f87k90

General discussion on mikroC.
Post Reply
Author
Message
engahmed
Posts: 92
Joined: 14 May 2013 19:13

Adc for pic 18f87k90

#1 Post by engahmed » 16 Aug 2017 21:56

I really I will ahead to wall


I try to interface 8lm35 to adc (an0 -an7)
Avdd=3.3v. Avss=0v

I try every thing first

AnCon0=0XFF //ANALOG INPUTS
ANCON1=0///. DIGITAL INPUT
ANCON2=0//DIGITAL INPUTS

ADCON1=0
Adcon2=0

Then I use function of Microsoft c for adc

Temp=adc_read(0)
Temp1=adc_read(1)

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: Adc for pic 18f87k90

#2 Post by darko.ilijevski » 17 Aug 2017 17:38

Hello,

You shouldn't be touching registers, did you try to simply use ADC_Read(0) function with nothing else in project ?
Set the TRIS register of course, just in case. Also RA0 is actually AN0 so ADC_Read(0) means 'read from the AN0 channel'

I do not have that MCU at hand, but I will look for it and report back with my findings...

Best regards
BR,
Darko

engahmed
Posts: 92
Joined: 14 May 2013 19:13

Re: Adc for pic 18f87k90

#3 Post by engahmed » 17 Aug 2017 18:40

I will. Really I try to use adc function for micro c.

But the problem is give me always 4095
But I notice that if reduce the analog volt input to .0025 v
Tha adc value change to 1215 but if increase to 3.3v give me 4095.
I don't k :oops: :D :shock: :shock: now

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: Adc for pic 18f87k90

#4 Post by darko.ilijevski » 17 Aug 2017 21:55

Hi,

In a lack of the physical device, I can only suggest you one more thing you could try: Use ADC_Init_Advanced() function and check the compiler's HELP for the proper parameters for the external voltage reference. That might easily be the problem. Also try using ADC_Get_Sample(). See if that helps. Also as a tip - do not touch registers when you use a library, at least not before you know it really helps. Messing with the registers might render the function inoperable. That's why I say to try using pure library calls before you resort to setting the registers. I hope I'll have the device soon so I can see what is going on with it.

p.s. 3.3V should give you 4096, as that is the highest 12bit value you can get from that MCU for the highest voltage. If it changes as you drop down the voltage, then it actually works. You can calculate the voltage by using the formula :

voltage = value_read / 4096 * Vref

where vref = 3.3v, voltage is the voltage value and the value_read is the value you get from the 12bit ADC, up to 4096.

Best regards
BR,
Darko

Post Reply

Return to “mikroC General”