ADCIN query


Closed Thread
Results 1 to 3 of 3

Thread: ADCIN query

  1. #1
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216

    Default ADCIN query

    Hi all.
    Got a little problem with a project:

    I am reading a single Anaolgue pin, and then sterring a particular LED on depending on the reading

    start:

    adcin 1, instate

    select case instate

    case is>220 'actual is 248
    portb = %00010000
    goto finish

    case is>190 'actual is 201
    portb = %00001000
    goto finish

    case is>162 '178
    portb = %00000100
    goto finish

    case is> 139 '154
    portb = %00000010
    goto finish

    case is<133 '108
    portb = %00000001
    goto finish
    case is >132 and is <140 '136
    portb = %00000000
    goto finish

    finish: end select
    pause 20
    goto start


    The first 5 cases are OK, however when I disconnect the input pin so that it is open circuit, rather than setting all LEDs off, for some reason PB1 turns on. The open circuit reading is not in the range for that, as it is 136 which falls into the 6th case.
    Each reading sith within a particular window, but for some reason there is a hiccup.

    There is a resistor divider and Cap on the input line, and have looked at it on my CRO and can't see any noise on the pin. (anyway, any noise would (should) cause a couple of LEDs to blink?))

    Have tried 'F88, 'F819 and 'C715 in the target PCB and in my development board with the same result.
    Have also sent the reading to an LCD and each shows up as what it should be.

    Any ideas (again?)

    Regards,
    Peter Moritz.
    Peter Moritz.
    Up the bush, Western Plains,
    New South Wales,
    Australia.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    muddy0409, Try this...

    case is >133
    portb = %00000000
    goto finish
    case is<134 '108
    portb = %00000001
    goto finish

    I have to ask though, Why are you using all of the "goto finish" statements? The case statement takes care of that for you.. The code would run faster with out them...

    Dave Purola,
    N8NTA

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Peter

    isn't that a Typo ???

    Code:
    case is<133 '108
    Cause the written code matches to what you describe ...

    so, Try this one :

    Code:
    start:
    
    adcin 1, instate
    
    select case instate
    
    case is>220 'actual is 248
    portb = %00010000
    
    case is>190 'actual is 201
    portb = %00001000
    
    
    case is>162 '178
    portb = %00000100
    
    
    case is> 139 '154
    portb = %00000010
    
    
    case is >132 '136
    portb = %00000001
    
    
    case ELSE '108
    portb = %00000000
    
    end select
    
    pause 20
    goto start
    Here, leds will be off for Open input ... if divider present on input !

    Alain

    PS ... I suppose you mix "break" C statement with PbP " go to Finish " ... lol : PbP do not [no]need[no] have it !!!
    ************************************************** ***********************
    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. ADCIN and PIC18F4331 Arghhhhh !
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th December 2010, 20:27
  2. How to make adcin stable?
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th January 2009, 07:41
  3. ADCIN Problem
    By JavPar in forum General
    Replies: 33
    Last Post: - 20th January 2009, 03:36
  4. Adcin or Pot
    By lerameur in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 11th January 2007, 16:46
  5. help using adcin
    By harryweb in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2006, 07:46

Members who have read this thread : 1

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