16F88 Analog In


Closed Thread
Results 1 to 12 of 12

Thread: 16F88 Analog In

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116

    Question 16F88 Analog In

    Hi Gurus of Picland!

    yeeees I know thats quite simple thing for you all and I could find it in the data sheet.....but thats my first time on 16F88 . LCD works of course, its just this ansel adcon thingy....
    and i searched in the forum but everyone uses RA inputs for analog. They are used for the lcd so I like to use RB7 which hasnt anything else to do.

    I would appreciate Your help.

    code:
    '************************************************* ***************
    '* Name : Ananlog1.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 23.03.2008 *
    '* Version : 1.0 *
    '* Notes : 16F88 LCD 2x8 connected as ususal *
    '* : Portb.7 analog IN 0-2V *
    '************************************************* ***************


    Include "modedefs.bas"



    CMCON = 7 ' PortA = digital I/O
    ANSEL = %00000110 ' Will set RB7 as analog I hope
    ADCON0 = %11100001
    ADCON1 = %10000010
    adval var word 'Create adval to store result




    Define ADC_BITS 8 'Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSbut show on LCD Value:3
    Define osc 4

    loop: ADCIN 7, adval ' Read channel 0 to adval

    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value: ", DEC adval ' Display the decimal value

    Pause 100 ' Wait .1 second

    Goto loop ' Do it forever
    End

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Your ANSEL setting is wrong... RB7 is AN6 and must be set to 1 in ANSEL bit 6.

    Seems you revert bit order or something like that.

    ANSEL=%76543210
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Question Ansel setting?

    Mister_E,
    thaks for your suggestion.

    I tried several ansel settings

    from
    ANSEL=%01000000
    to
    ANSEL=%10000000
    to
    ANSEL=%01000110
    and a dozen similar versions.

    when I switch on the LCD shows for half a second "Value:03" and then
    "Value:00"
    Yes..its because of internal bit during startup.
    Switched an Lcdout $FE,1,"Hello"
    Pause 500
    into just to show the PIC works and goes through the loop.

    I could switch input to any RB exept RB03 which is used for the LCD.

    Input voltage is now 0-2,5V .just for checking purposes.

    Do I need a reference voltage?

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Unhappy

    Hi Mügel

    the obvious thing here ...

    - is you select Channel 7 ( ADCIN 7 ),
    - Choose channel 1 and 2 for the ADC ,
    - choose channel 4 as default Analog channel,
    - right justify the result ( Ok, here , why not ? ) ,
    - use a 16 bits variable for the result,
    - and , at last use an 8 bits conversion ...

    Might I add your comment tells "read channel 0" for an " ADCIN 7 " ...


    is that clear enough for you ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default first time 16F88

    Hello Ace,

    I changed (tried to) the channel but not the comment .

    Puzzling together the analog thing is difficult for me as its the first time.
    Did that with a 12F675 worked great.
    You were second in the following "code saving contest": http://www.picbasic.co.uk/forum/show...ghlight=12F675

    Now I try to save one simple 12F675 and I´m in trouble again.

    No, What you told below isn´t clear enough for me although it shows the typical "Newbie defines rubbish"
    in this thread:http://www.picbasic.co.uk/forum/show...ht=16f88+adcon
    Melanie tells us that the adcon thingy affects only Porta.
    But the data sheet page 114 tells us (you, not me) how to set the adcon0 register bit to select channel 6 = RB7.

    So, thats REALLY irritating to me.

    so I hope thats clear enough for you.

    I know I´m juggling bits like shooting in the dark but its always the same:
    search a code that works for me and then modifiing.
    All codes used RA ports as analog input. Can´t use that.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mugelpower View Post
    Hello Ace,

    But the data sheet page 114 tells us (you, not me) how to set the adcon0 register bit to select channel 6 = RB7.

    So, thats REALLY irritating to me.

    so I hope thats clear enough for you.

    .
    Mhhhh,

    I do not understand you : you ask for code ready to paste !!!

    No, no, no ...



    Forget the ' 675


    Just take your '88 datasheet ADC section ...
    READ it carefully,

    beginning by the ANSEL config

    WHAT do you have to write to select Channel 6 ( RB 7 ) ???

    Now ADCON 0 Config

    WHAT do you have to write to select RC clock ?, Channel 6 ?, AD OFF ( ADCIN will turn it ON in time )

    Now, ADCON 1 Config

    WHAT do you have to write to select Right justif. ?, Voltage refs ???

    THAT's all you have to do ... but that must suit your harware config !!!


    You don't see here ANY ref to other existing devices ... so, forget that " cut ( ? ) and paste" horrible habit.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  2. analog data acquisition with 16f88
    By dru_x in forum Code Examples
    Replies: 3
    Last Post: - 29th January 2008, 13:38
  3. 16f88 - pin RA4 as analog input
    By savnik in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 15th December 2006, 13:55
  4. Anyone Got a 16F88 to Work in Analog?
    By thunderstrike44 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st August 2004, 22:34
  5. 16F88 reading Analog Input
    By thunderstrike44 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2004, 22:41

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts