ADC Help Please


Results 1 to 15 of 15

Thread: ADC Help Please

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    OK it's true, ADCIN do something bad on this chip, now i have to find why. In meantime use something like
    Code:
    <font color="#000000">        <font color="#000080">DEFINE </font>OSC 4
    
            ADCON0=%11000001
            ADCON1=%00000000
            GoDone <font color="#000080">VAR </font>ADCON0.1
                    <font color="#008000">'76543210
            </font>CHSELECT   <font color="#000080">VAR BYTE
            
            </font>CM1CON0 = 0 <font color="#008000">' Comparators off (Do I need these?)
            </font>CM2CON0 = 0 <font color="#008000">' Comparators off
            </font>ANSEL = %00010011<font color="#008000">' Set analog pins
            </font>ANSELH = %00000000
            TRISA = %00100011<font color="#008000">' Set port A
            </font>TRISB = %11000000 <font color="#008000">' Set port B
            </font>TRISC = %00000000 <font color="#008000">' Set port C
            
            </font>ANIN0 <font color="#000080">VAR BYTE </font><font color="#008000">'Cylinder 1 Feedback Pot
            </font>ANIN1 <font color="#000080">VAR BYTE </font><font color="#008000">'Cylinder 2 Feedback Pot
            </font>SW1EXT <font color="#000080">VAR BIT </font><font color="#008000">'Extend Switch
            </font>SW2RET <font color="#000080">VAR BIT </font><font color="#008000">'Retract Switch
            </font>EXT1FLAG <font color="#000080">VAR BIT
            </font>RET1FLAG <font color="#000080">VAR BIT
            </font>EXT2FLAG <font color="#000080">VAR BIT
            </font>RET2FLAG <font color="#000080">VAR BIT
            </font>J <font color="#000080">VAR WORD
            
            </font><font color="#008000">'Initialize Variables and Ports
            </font>PORTA=0
            PORTB=0
            PORTC=0
            EXT1FLAG=0
            EXT2FLAG=0
            RET1FLAG=0
            RET2FLAG=0
    
            <font color="#000080">GOTO </font>START
    
            <font color="#000080">ASM
    ADC_IN MACRO CHANNEL, VARIABLE
            MOVE?CB CHANNEL, _CHSELECT
            L?CALL _DO_AD_CONVERSION
            MOVE?BB ADRESH,VARIABLE
            ENDM
            ENDASM
            
    </font>DO_AD_CONVERSION:
            ADCON0=(CHSELECT&lt;&lt;2) |%11000001
            <font color="#000080">PAUSEUS </font>50
            GoDone=1
            <font color="#000080">WHILE </font>GoDone : <font color="#000080">WEND
            RETURN    
    </font>START:        
            <font color="#000080">FOR </font>J=1 <font color="#000080">TO </font>25 <font color="#008000">'Startup indicator
                    </font><font color="#000080">TOGGLE </font>PortA.2
                    <font color="#000080">PAUSE </font>50
                    <font color="#000080">NEXT </font>J
    
    MAIN:
            <font color="#000080">FOR </font>J=1 <font color="#000080">TO </font>500
                @   ADC_IN 4,_ANIN0
                <font color="#008000">'Poll Switches
                </font><font color="#000080">IF </font>PortB.7=0 <font color="#000080">THEN
                    PAUSE </font>20
                    <font color="#000080">IF </font>PORTB.7=0 <font color="#000080">THEN
                        </font>SW1EXT=1
                        <font color="#000080">ENDIF
                    ELSE
                        </font>SW1EXT=0
                    <font color="#000080">ENDIF
                
                IF </font>PortB.6=0 <font color="#000080">THEN
                    PAUSE </font>20
                    <font color="#000080">IF </font>PORTB.6=0 <font color="#000080">THEN
                        </font>SW2RET=1
                        <font color="#000080">ENDIF
                    ELSE
                        </font>SW2RET=0
                    <font color="#000080">ENDIF
                
                </font>@   ADC_IN 0,_ANIN0
               
                <font color="#000080">IF </font>ANIN0&lt;245 <font color="#000080">THEN
                    </font>EXT1FLAG=0 <font color="#008000">'OK to Extend
                    </font><font color="#000080">ELSE
                        </font>EXT1FLAG=1
                    <font color="#000080">ENDIF
                
                IF </font>ANIN0&gt;10 <font color="#000080">THEN
                    </font>RET1FLAG=0 <font color="#008000">'OK to Retract
                    </font><font color="#000080">ELSE
                        </font>RET1FLAG=1
                    <font color="#000080">ENDIF
                
                </font>@   ADC_IN 1,_ANIN1
                
                <font color="#000080">IF </font>ANIN1&lt;245 <font color="#000080">THEN
                    </font>EXT2FLAG=0 <font color="#008000">'OK to Extend
                    </font><font color="#000080">ELSE
                        </font>EXT2FLAG=1
                    <font color="#000080">ENDIF
                
                IF </font>ANIN1&gt;10 <font color="#000080">THEN
                    </font>RET2FLAG=0 <font color="#008000">'OK to Retract
                    </font><font color="#000080">ELSE
                        </font>RET2FLAG=1
                    <font color="#000080">ENDIF
                
                IF </font>(SW1EXT=1) <font color="#000080">AND </font>(EXT1FLAG=0) <font color="#000080">THEN </font><font color="#008000">'Extend Cylinder 1
                    </font>PORTB.3=1
                    PORTB.4=0
                    PORTB.5=1
                    <font color="#000080">ENDIF
                
                IF </font>(SW1EXT=1) <font color="#000080">AND </font>(EXT1FLAG=1) <font color="#000080">THEN </font><font color="#008000">'Stop Cylinder 1
                    </font>PORTB.3=0
                    PORTB.4=0
                    PORTB.5=0
                    <font color="#000080">ENDIF
                
                IF </font>(SW2RET=1) <font color="#000080">AND </font>(RET1FLAG=0) <font color="#000080">THEN </font><font color="#008000">'Retract Cylinder 1
                    </font>PORTB.3=0
                    PORTB.4=1
                    PORTB.5=1
                    <font color="#000080">ENDIF
                
                IF </font>(SW2RET=1) <font color="#000080">AND </font>(RET1FLAG=1) <font color="#000080">THEN </font><font color="#008000">'Stop Cylinder 1
                    </font>PORTB.3=0
                    PORTB.4=0
                    PORTB.5=0
                    <font color="#000080">ENDIF
                
                IF </font>(SW1EXT=1) <font color="#000080">AND </font>(EXT2FLAG=0) <font color="#000080">THEN </font><font color="#008000">'Extend Cylinder 2
                    </font>PORTB.0=1
                    PORTB.1=0
                    PORTB.2=1
                    <font color="#000080">ENDIF
                    
                IF </font>(SW1EXT=1) <font color="#000080">AND </font>(EXT2FLAG=1) <font color="#000080">THEN </font><font color="#008000">'Stop Cylinder 2
                    </font>PORTB.0=0
                    PORTB.1=0
                    PORTB.2=0
                    <font color="#000080">ENDIF
                    
                IF </font>(SW2RET=1) <font color="#000080">AND </font>(RET2FLAG=0) <font color="#000080">THEN </font><font color="#008000">'Retract Cylinder 2
                    </font>PORTB.0=0
                    PORTB.1=1
                    PORTB.2=1
                    <font color="#000080">ENDIF
                    
                IF </font>(SW2RET=1) <font color="#000080">AND </font>(RET2FLAG=1) <font color="#000080">THEN </font><font color="#008000">'Stop Cylinder 2
                    </font>PORTB.0=0
                    PORTB.1=0
                    PORTB.2=0
                    <font color="#000080">ENDIF
                    
                IF </font>(SW1EXT=0) <font color="#000080">AND </font>(SW2RET=0) <font color="#000080">THEN </font><font color="#008000">'Stop Cylinders
                    </font>PORTB.3=0
                    PORTB.4=0
                    PORTB.5=0
                    PORTB.0=0
                    PORTB.1=0
                    PORTB.2=0
                    <font color="#000080">ENDIF
                
                IF </font>SW1EXT=1 <font color="#000080">AND </font>SW2RET=1 <font color="#000080">THEN </font><font color="#008000">'Stop Cylinders
                    </font>PORTB.3=0
                    PORTB.4=0
                    PORTB.5=0
                    PORTB.0=0
                    PORTB.1=0
                    PORTB.2=0
                    <font color="#000080">ENDIF
                    
                IF </font>(ANIN0&gt;ANIN1) <font color="#000080">AND </font>(SW1EXT=0) <font color="#000080">AND </font>(SW2RET=0) <font color="#000080">THEN
                    GOSUB </font>SLAVE1
                    <font color="#000080">ENDIF
                
                IF </font>(ANIN1&gt;ANIN0) <font color="#000080">AND </font>(SW1EXT=0) <font color="#000080">AND </font>(SW2RET=0) <font color="#000080">THEN
                    GOSUB </font>SLAVE2
                    <font color="#000080">ENDIF
                
                NEXT </font>J
                
            <font color="#000080">TOGGLE </font>PORTA.2 <font color="#008000">'Heartbeat LED
            </font><font color="#000080">PAUSE </font>500
            <font color="#000080">GOTO </font>MAIN
    
    SLAVE1:
            <font color="#000080">IF </font>(ANIN0-ANIN1)&gt;=5 <font color="#000080">THEN
                </font>PORTB.0=1
                PORTB.1=0
                PORTB.2=1
                <font color="#000080">ENDIF
                
            IF </font>(ANIN0-ANIN1)&lt;5 <font color="#000080">THEN
                </font>PORTB.0=0
                PORTB.1=0
                PORTB.2=0
                <font color="#000080">ENDIF
            
            RETURN
    
    </font>SLAVE2:
            <font color="#000080">IF </font>(ANIN1-ANIN0)&gt;=5 <font color="#000080">THEN
                </font>PORTB.0=0
                PORTB.1=1
                PORTB.2=1
                <font color="#000080">ENDIF
                
            IF </font>(ANIN1-ANIN0)&lt;5 <font color="#000080">THEN
                </font>PORTB.0=0
                PORTB.1=0
                PORTB.2=0
                <font color="#000080">ENDIF
                
            RETURN
    </font>
    Last edited by mister_e; - 14th June 2007 at 05:30.
    Steve

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

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. 10 bit ADC display on LCD using 16f873
    By pr2don in forum mel PIC BASIC
    Replies: 3
    Last Post: - 6th March 2010, 18:29
  3. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

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