1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PIC 12F683 ADC problem

Discussion in 'Oshonsoft' started by steve langner, Sep 3, 2014.

  1. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0
    Back again in trouble with this basic stuff. Hope some kind guy can explain why this code doesn't work.
    I thought ANSEL = 1 caused the selected input to be enabled as analog in an AllDigital environment'
    However, the simulator displays the input as digital . So where am I going wrong?

    TRISIO = %00000010
    ANSEL = 1
    AllDigital
    GPIO = %00000000
    Dim x As Word
    main:
    Adcin 1, x
    GP0 = 1
    GP2 = 1
    WaitMs x
    GP4 = 1
    GP5 = 1
    WaitMs x
    GP0 = 0
    GP2 = 0
    WaitMs x
    GP4 = 0
    GP5 = 0
    WaitMs x
    Goto main
    End
     
  2. Gobbledok

    Gobbledok Active Member

    Joined:
    Mar 9, 2008
    Messages:
    452
    Likes:
    34
    Location:
    Toowoomba, Australia
    I haven't used PIC's for a fair while so excuse me if I am wrong.

    TRISIO = %00000010 You are setting pin 1 as an input.
    ANSEL = 1 You are setting pin 0 as analog.

    Perhaps you need to make ANSEL = %00000010 and set pin 1 as analog?

    PIC ANSEL.png
     
    Last edited: Sep 3, 2014
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi steve,
    Run this Sim.
    Code (text):

    '12F683
    Define SIMULATION_WAITMS_VALUE = 1  'SIMULATION ONLY
    Define CONF_WORD = 0x33c4

    Dim cnt1 As Byte
    Dim aval1 As Byte

    ADCON0 = %00000001
    ANSEL = %00000001
    CMCON0 = %00000111

    OSCCON = %01100000  'Internal  osc

    OPTION_REG = %10000111

    TRISIO.0 = 1
    TRISIO.1 = 1
    TRISIO.2 = 0
    TRISIO.3 = 1
    TRISIO.4 = 0
    TRISIO.5 = 0
    INTCON = 0

    start:
    Toggle GPIO.2
    Adcin 0, aval1
    Goto start

    End                                              
     
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0

    hi eric
    As a beginner I won't pretend to understand most of the opening statements in your code example, but would I be wrong in assuming that there would be no error in changing Adcin 0, aval1 to Adcin 1, aval1, leaving everything else the same? I notice that your Tris reg is set up to accommodate this and it's the pin I used in my code. But in doing this, I find your example, like mine, doesn't work either. In fact my code worked with GPIO.0 as the adc input as did yours, and didn't work for any of the other pins substituted. Any suggestions as to why this is happening?
     
  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi steve,


    Code (text):
    Define SIMULATION_WAITMS_VALUE = 1  'SIMULATION ONLY
    Define CONF_WORD = 0x33c4

    Dim cnt1 As Byte
    Dim aval1 As Byte

    ADCON0 = %00000101
    ANSEL = %00000010
    CMCON0 = %00000111

    OSCCON = %01100000  'Internal  osc

    OPTION_REG = %10000111

    TRISIO.0 = 1
    TRISIO.1 = 1
    TRISIO.2 = 0
    TRISIO.3 = 1
    TRISIO.4 = 0
    TRISIO.5 = 0
    INTCON = 0

    start:
    Toggle GPIO.2
    Adcin 1, aval1
    Goto start

    End                                            
     
    E
     
    Last edited: Sep 3, 2014
  7. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0
    Dawning of a bright light. Thanks to you, Eric, I now realise that I was misunderstanding how to use ANSEL. I imagined that setting ANSEL to 1 enabled all analog inputs, and that all one needed to do was specify a particular one in the Adcin statement. I now also realise what Gobbledok meant (he was absolutely right), and I need to thank him too.
     
  8. steve langner

    steve langner New Member

    Joined:
    Aug 2, 2014
    Messages:
    27
    Likes:
    0
    Thanks, Gobbledok, I apologise for not understanding your explanation right away. Of course you were right. Ericgibbs helped me see the light.
     

Share This Page