ADC library of mikroC PRO for PIC v.5.30 questions???

General discussion on mikroC.
Post Reply
Author
Message
bobx
Posts: 115
Joined: 14 Mar 2010 08:35

ADC library of mikroC PRO for PIC v.5.30 questions???

#1 Post by bobx » 30 Nov 2011 18:29

Hello,everybody.Would you please answer to the following questions;

1.What is the difference between these two instructions;


[unsigned ADC_Get_Sample(unsigned short channel);] & [unsigned ADC_Read(unsigned short channel);] ?



2.Is there the instruction;[unsigned ADC_Get_Sample(unsigned short channel);] having to do
with [and related to] oversampling technique ?

Thanks,

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#2 Post by p.erasmus » 30 Nov 2011 18:36

@bobx

You are using V5.3 which is the very lates verion is there a specific reason why you are posting in the mikroC compiler section and not in the mikroC Pro section
this forum is for the old non Pro verions
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

bobx
Posts: 115
Joined: 14 Mar 2010 08:35

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#3 Post by bobx » 30 Nov 2011 18:45

Hello,p.erasmus.
My reasons are;1. I want to write a program and 2. to higher my ADC reading
accuracy from 10-bit[18f8722] into 12-bit or 16-bit?

Thanks,

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#4 Post by p.erasmus » 30 Nov 2011 20:52

bobx wrote:My reasons are;1. I want to write a program and 2. to higher my ADC reading
Well being sarcastic wount bring you any help and secondly it does not change the fact that you post in the in correct forum!
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#5 Post by janko.kaljevic » 01 Dec 2011 09:55

Hello,

Please check the help file for more details.
ADC_Read() function will initialize ADC module and read single value from selected channel.
ADC_Get_Sample() will only read selected channel, and you will need to initialize module prior calling this routine.

Best regards.

mikekehrli
Posts: 111
Joined: 25 Nov 2011 09:52

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#6 Post by mikekehrli » 09 Jan 2012 01:11

janko.kaljevic wrote:Hello,

Please check the help file for more details.
ADC_Read() function will initialize ADC module and read single value from selected channel.
ADC_Get_Sample() will only read selected channel, and you will need to initialize module prior calling this routine.
I've been trying to get one question answered, that doesn't seem to be covered anywhere else:

Does the ADC_Init() have to be called prior to each ADC_Get_Sample()? Or is one ADC_Init() sufficient, and calls to ADC_Get_Sample can occur anytime?

I've seen a description of starting a read in the interrupt routine, then reading the result in a future interrupt. But I haven't seen this well described anywhere. Is that using an ADC_Init(), then using an ADC_Get_Sample later? Is the ADC_Get_Sample fast enough to use in an interrupt routine?

I don't really want to try to learn this by trial and error, as I may not get a definitive answer.

Thanks.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#7 Post by janko.kaljevic » 09 Jan 2012 14:06

Hello,

If you want to use ADC_Get_Sample function, you only need to call ADC_Init once before you begin to read ADC.

Yes, you can use ADC_Get_Sample in interrupt routine.

Best regards.

mikekehrli
Posts: 111
Joined: 25 Nov 2011 09:52

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#8 Post by mikekehrli » 09 Jan 2012 20:04

Thank you. But just a reality check: It seems like I'm missing something that everyone else sees but me.

Why do all the sample code listings I see use ADC_Read() in their loops? Doesn't that take a lot more time? Why don't they just use ADC_Init() once, then just get samples from then on? Is there something wrong with this approach that I'm missing? It seems to me like ADC_get_sample() is the only correct way to read the ADC. I would think that the only use of ADC_Read(), is if you didn't want to write a 2nd line of code and didn't care that the procedure was going to wait for 12 TAD and hold up your program until the ADC returned your value.

Also, the code I'm working with (which I inherited from someone else) goes like this:

Code: Select all

    adc_rd = ADC_Read(0)
    if (adc_rd > 1024) then
        adc_rd = 0
    end if
My processor has 10 bit ADC precision. Is there some case where ADC_Read() can give a value larger than 10 bits? It seems like the check is completely unneeded. But the guy that wrote the program wasn't a dummy or anything, so I'm wondering if there's some way that the ADC_Read instruction can give a larger number, perhaps as an error condition or something. I don't see anything in the manual or help about it.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#9 Post by janko.kaljevic » 10 Jan 2012 11:38

Hello,

ADC_Read() is function that you can use at any time to obtain result from AD converter.
But if you want to use it constantly use ADC_Get_Sample.

There is no need for this if check. Result will never be larger than 1024.

Best regards.

mikekehrli
Posts: 111
Joined: 25 Nov 2011 09:52

Re: ADC library of mikroC PRO for PIC v.5.30 questions???

#10 Post by mikekehrli » 11 Jan 2012 03:43

Ok, thanks a lot. I was having trouble finding answers to those questions. I appreciate it. :)

Post Reply

Return to “mikroC General”