• AVR Freaks

Hot!16F18346 with MikroC, how to read ADC

Author
newbadboy
Starting Member
  • Total Posts : 46
  • Reward points : 0
  • Joined: 2019/03/01 03:15:18
  • Location: 0
  • Status: offline
2019/08/23 05:40:16 (permalink)
0

16F18346 with MikroC, how to read ADC

So the ADC read command is called ADC_Read(chX); in Mikro C but for this chip they are calling the different adc inputs ANAA ANAB ANAC. How should i interpret this.
 
Lets say i want to read the adc channel ANA4.
 
i cannot write ADCA_Read(4) , the compiler won't accept it.
Also i cannot write ADC_Read(4) because there is also one ANA4 input. So what to do?
 
 
#1

11 Replies Related Threads

    mbrowning
    Just a Member
    • Total Posts : 1504
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 06:33:05 (permalink)
    +1 (1)
    I would think by using the datasheet. You have read it I presume?
    REGISTER 22-1: ADCON0: ADC CONTROL REGISTER 0
    bit 7-2 CHS<5:0>: Analog Channel Select bits
    111111 = FVR (Fixed Voltage Reference)(2)
    111110 = DAC1 output(1)
    111101 = Temperature Indicator(3)
    111100 = VSS
    111011 = Reserved. No channel connected.



    010111 = ANC7(4)
    010110 = ANC6(4)
    010101 = ANC5
    010100 = ANC4
    010011 = ANC3
    010010 = ANC2
    010001 = ANC1
    010000 = ANC0
    001111 = ANB7(4)
    001110 = ANB6(4)
    001101 = ANB5(4)
    001100 = ANB4(4)
    001011 = Reserved. No channel connected.



    000101 = ANA5
    000100 = ANA4
    000011 = Reserved. No channel connected.
    000010 = ANA2
    000001 = ANA1
    000000 = ANA0

    Oh well - there's always next year
    #2
    newbadboy
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2019/03/01 03:15:18
    • Location: 0
    • Status: offline
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 07:25:33 (permalink)
    0
    Yes i have read an tried to understand it but still no clue.
    #3
    mbrowning
    Just a Member
    • Total Posts : 1504
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 08:06:12 (permalink)
    0
    Hmm. Each port has a number. Use that number.

    Oh well - there's always next year
    #4
    katela
    Super Member
    • Total Posts : 1378
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 08:48:41 (permalink)
    0
    newbadboy
     
    i cannot write ADCA_Read(4) , the compiler won't accept it.
     

    This will generate errors because that's not the required syntax for ADC.
    newbadboy
     Also i cannot write ADC_Read(4) because there is also one ANA4 input. So what to do?


    What make you think you cannot write it that way?
    As mbrowning has explained above, Use the channel number.
    This code below using 16F18346 has compiled with no errors.

    unsigned int temp_res;
    void main() {
    temp_res = ADC_Read(4); // Get results of AD conversion
    }

    If you can't compile, post the actual error messages you are getting.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #5
    newbadboy
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2019/03/01 03:15:18
    • Location: 0
    • Status: offline
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 08:57:30 (permalink)
    0
    The adc_read(4) could be whichever of anc4 anb4 and ana4. I do not see/understand which port adc_read(4) relates to.
    #6
    mbrowning
    Just a Member
    • Total Posts : 1504
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 09:07:12 (permalink)
    0
    Look at the table I posted !!
    It isn't hard to understand if you don't make it hard.
     
    010100 = ANC4  = 0x14
    001100 = ANB4  = 0x0c
    000100 = ANA4  = 0x04



    Oh well - there's always next year
    #7
    katela
    Super Member
    • Total Posts : 1378
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 09:33:08 (permalink)
    0
    newbadboy
    The adc_read(4) could be whichever of anc4 anb4 and ana4. I do not see/understand which port adc_read(4) relates to.

    This will refer to 000100 = ANA4  = 0x04

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #8
    newbadboy
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2019/03/01 03:15:18
    • Location: 0
    • Status: offline
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 09:46:00 (permalink)
    0
    Goddammit now i see it. Wtf don't they just name them as usual.
    #9
    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 14:40:54 (permalink)
    0
    "Names" only work if SOMEWHERE they have been defined as numbers. The function itself really needs a number.
    If you want to use the name, just add this line to the start of your C file.
    #define ANA4 4

     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    newbadboy
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2019/03/01 03:15:18
    • Location: 0
    • Status: offline
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 15:55:07 (permalink)
    0
    I agree, i just mean that they should not use anaA b c. They should stick to one way of naming their ads pins...
    #11
    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: 16F18346 with MikroC, how to read ADC 2019/08/23 15:59:27 (permalink)
    0
    Who should?
    It's the MikroC compiler that failed to define those names for you.
    Complain to them.
    Then when you get no response, just do what everyone else would do, and make a table of #defines for your own use.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5