A/D problem on 18F2550 ?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default A/D problem on 18F2550 ?

    Before i get flamed, i have read the data sheet many times, but its perhaps that i am not understanding it !

    If i change the Swicth input to say PORTC.1, all works fine, on PORTA.1 it does not.

    I am missing something in this code. I have been trying for a day and it is driving me mad !!

    Code:
    Clear
    ADCON1 = %00001111
    DEFINE OSC 20          
    DEFINE LOADER_USED 1
    
    ' ---------- [ I/O Definition ] ----------
    TRISA = %00000011       ' Set PORTC (0-2 input) rest Outputs
    TRISB = %10000001       ' Set PORTB (0)INPUT (1-5)OUTPUTS
    TRISC = %01000111       ' Set PORTC (0-2 input) rest Outputs
    PORTB = 0
    
    Switch      VAR PORTA.1    ' use a pin with Schmitt Trigger input
    RedLED      VAR PORTB.1
    X           VAR word
    Presses     VAR BYTE
    LOOP        VAR BYTE
    confirm_flag var byte
    
    Main:
        if Switch = 1 THEN
            WHILE Switch = 1 : WEND
            COUNT  Switch, 1500, Presses
            BRANCHL Presses,[routine1, routine2, routine3]
            GOTO MAIN
        endif
    GOTO Main
    
    '--------------
    routine0:        ' button was not pressed again
                     ' or pressed more than 3 times
    GOTO Main
    
    '--------------
    routine1:        ' pressed once
        HIGH REDled
        PAUSE 500
        LOW REDled
        GOSUB Confirmation
        if confirm_flag = 1 then gosub flash
    Goto main
    
    '--------------
    routine2:        ' pressed twice
        FOR X = 1 TO 2
            HIGH REDled
            PAUSE 500
            LOW REDled
            PAUSE 500
        NEXT X
        GOSUB Confirmation
        if confirm_flag = 1 then gosub flash
    
    GOTO Main
    
    '--------------
    routine3:        ' pressed thrice
        FOR X = 1 TO 3
            HIGH REDled
            PAUSE 500
            LOW REDled
            PAUSE 500
        NEXT X
        GOSUB Confirmation
        if confirm_flag = 1 then gosub flash
    
    GOTO Main
    
    Flash:
        For loop = 1 to 10
            Redled = 1
            Pause 50
            Redled = 0
            Pause 50
        Next Loop
    Return
    
    Confirmation:
        confirm_flag=0
        x=0
    
        WHILE (x<300) and (confirm_flag=0)
    
        Pause 10 'check for button every 10ms
        if Switch = 1 then confirm_flag = 1  ' if button pushed then set the flag
        x=x+1 ' increment the pause counter
        WEND
    
    Return
    Many thanks,

    Steve

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


    Did you find this post helpful? Yes | No

    Default

    Well the only pointer i can say

    look for ADCON, ADCON0, ADCON1 and/or CMCON register. PORTA can be set as analog i/o by default. So you nbeed to set it to digital.
    Steve

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

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    I thought i have, the register that i thought was applicable was the ADCON1 which has been set to ADCON1 = %00001111.

    Are there any others that i am missing.

    I thought this was the only one, as if i set the code to:

    Code:
    Main:
        if Switch = 1 THEN
            gosub flash
            endif
    GOTO Main
    
    Flash:
        For loop = 1 to 10
            Redled = 1
            Pause 50
            Redled = 0
            Pause 50
        Next Loop
    Return
    When you push the button, it does jump to the Flash routine. So i am guessing it is in digital mode.

    I have a pull-down resistor on the input pin, which when the switch is pressed the input line goes to 5v.

    I'll keep trying for a solution. Of course it could be my code up the spout !!

    Steve

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Tissy,

    Well, my original comment is still there, but I guess the thought behind it didn't make it through.

    ' use a pin with Schmitt Trigger input
    <br>
    DT

Similar Threads

  1. A/D converter problem
    By netstranger.nz in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th September 2009, 08:56
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 17:26
  3. Array problem (18F2550)
    By Ronald123 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th January 2008, 19:47
  4. Problem with A port on 18F2550
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 9th May 2007, 23:59
  5. A/D conversion problem with pic16F88
    By Tapio Linkosalo in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th August 2006, 12:42

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