I am confuse


Closed Thread
Results 1 to 20 of 20

Thread: I am confuse

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I am probably missing something but give this a shot.
    Code:
    @ __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF
    
    INCLUDE "modedefs.bas"
    ANSEL = %00001111 'set RA0-RA3 as analog inputs
    OSCCON = $60 'Sets the internal oscillator to 4 Mhz
    CMCON = 7 'Comparators off
    
    ti var byte
    ti = 50 '20 MILLISECONDS DELAY' 
    A VAR word
    B VAR word
    C VAR word
    D VAR word 
    TRISA = %00001111 
    TRISB = 0 'TURN PORT B as outputs but RB1 WHEN USE ICD FOR COMMUNICATION
    
    '* * * * * MAIN PROGRAM START HERE * * * * * * * * 
    
    PAUSE 1000
    Serout PORTB.1, 0, [254,1] 
    Serout PORTB.1, 0, [254,2]
    PAUSE 20
    
    READSENSORS: 
    ADCON1 = %10000000 'SET FOR 10 BITS 
    ADCON0 = %00000001 'Turn ON CHAN 0 
    GOSUB ADCON
    A.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR 
    SEROUT PORTB.1 , 0, ["Ch 0= ",# A.LOWBYTE]
    pause 20
    ADCON1 = %10000000 'SET FOR 10 BITS 
    ADCON0 = %00001001 'Turn ON CHAN 1 
    GOSUB ADCON 
    B.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR
    SEROUT PORTB.1 , 0, [" Ch 1= ",# B.LOWBYTE]
    PAUSE 20
    SEROUT PORTB.1,0,[$FE,$C0]
    ADCON1 = %10000000 'SET FOR 10 BITS 
    ADCON0 = %00010001 'Turn ON CHAN 2 
    GOSUB ADCON
    C.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR
    SEROUT PORTB.1 , 0, ["Ch 2= ",# C.LOWBYTE]
    PAUSE 20 
    ADCON1 = %10000000 'SET FOR 10 BITS 
    ADCON0 = %00011001 'Turn ON CHAN 3 
    GOSUB ADCON
    D.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR
    SEROUT PORTB.1 , 0, [" Ch 3= ",# D.LOWBYTE]
    PAUSE 1000
    Serout PORTB.1, 0, [254,1] 
    GOTO READSENSORS ' PROVISIONAL LOOP TO CHECK THE A/D CONVERTION.
    '* * * * * * * * * SELECTING THE MOTOR MOVEMENT * * * * * * * * 
    
    '* * * * * * * * * MOTOR'S MOVEMENTS SUBRUTINES * * * * * * * * 
    ADCON: 
    ADCON0.2 = 1 'IT'S ONE TILL IT READS
    WHILE ADCON0.2 = 1 : WEND
    RETURN 
    END
    This is what I am basing the sequence on. From the data sheet.
    1. Configure the A/D module:
    • Configure analog/digital I/O (ANSEL)
    • Configure voltage reference (ADCON1)
    • Select A/D input channel (ADCON0)
    • Select A/D conversion clock (ADCON0)
    • Turn on A/D module (ADCON0)
    I am pretty sure this sequence needs to be followed. I am not at the shop so I can not test your code now.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Dave and Tim

    I had a look to the TEST section of this program ... It gave that, with a " classic " PBP use. :

    Code:
    'Config
    
    @	__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_ON & _INTRC_IO
    
    @ 	__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    
    
    
    '@ __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF
    
    DEFINE ADC_BITS 10 ' Sets the number of bits in the result to 10
    
    
    ANSEL = %00001111 'set RA0-RA3 as analog inputs
    
    'ADCON1 = %10000000 'Right Justifies 10-bit value 
    
    'OSCCON = $60 'Sets the internal oscillator to 4 Mhz
    
    OSCCON 	= %01101110 'Internal RC w/ I/Os
    
    INTCON	= 0
    PIE1	= 0
    PIE2	= 0
    CMCON 	= 7 'Comparators off
    CVRCON 	= 0
    
    INCLUDE "modedefs.bas"
    
    ti var byte
    ti = 50 '20 MILLISECONDS DELAY'
     
    A VAR word
    B VAR word
    C VAR word
    D VAR word
    
    _A CON 0
    _B CON 1
    _C CON 2
    _D CON 3
     
    TRISA = %00001111 
    TRISB = 0 'TURN PORT B as outputs but RB1 WHEN USE ICD FOR COMMUNICATION
    
    '* * * * * MAIN PROGRAM START HERE * * * * * * * * 
    
    PAUSE 1000
    Serout PORTB.1, 0, [254,1] 
    Serout PORTB.1, 0, [254,2]
    PAUSE 20
    
    READSENSORS: 
    
    'ADCON0 = %00000001 'Turn ON CHAN 0 
    'GOSUB ADCON
    
    ADCIN _A, A
    
    'A.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR
     
    SEROUT PORTB.1 , 0, ["Ch 0= ",# A.LOWBYTE]
    pause 20
    
    'ADCON0 = %00001001 'Turn ON CHAN 1 
    'GOSUB ADCON
    
    ADCIN _B, B
    
    'B.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR
    
    SEROUT PORTB.1 , 0, [" Ch 1= ",# B.LOWBYTE]
    PAUSE 20
    
    SEROUT PORTB.1,0,[$FE,$C0]
    
    'ADCON0 = %00010001 'Turn ON CHAN 2 
    'GOSUB ADCON
    
    ADCIN _C, C
    
    'C.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR
    
    SEROUT PORTB.1 , 0, ["Ch 2= ",# C.LOWBYTE]
    PAUSE 20 
    
    'ADCON0 = %00011001 'Turn ON CHAN 3 
    'GOSUB ADCON
    
    ADCIN _D, D
    
    'D.LOWBYTE = ADRESL 'PLACES THE LOW BYTE INTO VAR
    
    SEROUT PORTB.1 , 0, [" Ch 3= ",# D.LOWBYTE]
    
    
    PAUSE 1000
    Serout PORTB.1, 0, [254,1] 
    
    GOTO READSENSORS ' PROVISIONAL LOOP TO CHECK THE A/D CONVERTION.
    I just commented out original lines for comparison ...

    Hope it Helps

    Alain
    Last edited by Acetronics2; - 20th October 2009 at 09:02.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  3. #3
    Join Date
    Aug 2009
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Problem solved.

    I did the two editing of my program as Acetronics and as Mackrackit subjected. I ran both versions and ran with the same faulty results. I can’t understood how three persons could be wrong so I started again a check of my hardware. I found the problem on the breadboard. At the two power lines that runs on the outside of the board (-,+) the + line had 50 ohms! from one end to the other. I found a fault connection and restored it with a new line, problem goes. Now every input goes to zero. I want to thanks all of you including Melanie. Every time I come across an obstacle there is a reason to learn. Thanks.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    COOL!!!
    At least now you have a couple different ways to read the ADC.

    Have FUN!!!
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Aug 2009
    Posts
    33


    Did you find this post helpful? Yes | No

    Default I had fun.

    Thank you. Yes I had a lot of fun with every project. I had to unassembled the breadboard and run a soldered copper line under all around it to ensure a good contact. That’s part of the fun also. Thanks.

Similar Threads

  1. Replies: 288
    Last Post: - 25th August 2008, 16:53

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