Menu

Possible compiler error? ADC with 16f876a

Santiago
2009-01-24
2013-05-30
  • Santiago

    Santiago - 2009-01-24

    Hello all...

    I'm starting with this great compiler.. i really think it's great: easy to use, clean generated asm code, and there is good information about it. thanks to do it open source!

    I try to compile this code:
    _______________________________________________________________________
    'General hardware configuration

    #chip 16F876A, 20

    #config HS_OSC, WDT_OFF, LVP_OFF

    #define LED1   PORTB.7
    #define LED2   PORTC.4

    DIR B7 OUT
    DIR A0 IN

    do while true

        set LED1 ON

        rebote = ReadAD(AN0)
        set LED1 OFF

        set LED2 ON
        wait (rebote - ReadAD(AN0)) ms
        set LED2 OFF

    loop

    ______________________________________________________________________

    The compilation works Ok, but when i have a look to the generated .asm i see this in the ADC read routine:

    ;********************************************************************************

    FN_READAD
        banksel    ADCON1
        bcf    ADCON1,PCFG3           ; FROM HERE
        bsf    ADCON1,PCFG2
        bsf    ADCON1,PCFG1
        bcf    ADCON1,PCFG0          ; TO HERE
        banksel    ADCON0
        bcf    ADCON0,ADCS1
        bsf    ADCON0,ADCS0
        bcf    ADCON0,CHS0
        bcf    ADCON0,CHS1
        bcf    ADCON0,CHS2
        btfsc    ADREADPORT,0
        bsf    ADCON0,CHS0
        btfsc    ADREADPORT,1
        bsf    ADCON0,CHS1
        btfsc    ADREADPORT,2
        bsf    ADCON0,CHS2
        bsf    ADCON0,ADON
        movlw    2
        movwf    SysWaitTemp10US
        call    Delay_10US
        bsf    ADCON0,GO_DONE
    SysWaitLoop1
        btfsc    ADCON0,GO_DONE
        goto    SysWaitLoop1
        bcf    ADCON0,ADON
        banksel    ADCON1
        bcf    ADCON1,PCFG3
        bsf    ADCON1,PCFG2
        bsf    ADCON1,PCFG1
        bcf    ADCON1,PCFG0
        banksel    ADRESH
        movf    ADRESH,W
        movwf    READAD
        return

    ;********************************************************************************

    In ADCON1 register the bits PCFG0-PCFG3 are set to 0110, i think that's ALL DIGITAL... the same setting is used for close adc, what's ok, but is not ok for open adc...

    Am i doing something wrong?

    I work it in Linux Ubuntu 8.10 with last update and gpasm, all seem to work ok....

     
    • Santiago

      Santiago - 2009-01-24

      ... The real thing is that it works with your configuration...

      Why?....

       
    • Hugh Considine

      Hugh Considine - 2009-01-24

      Oops, that is a major error! Not sure how it managed to get in without being noticed!

      Try downloading the new update (http://gcbasic.sourceforge.net/newfiles/update-nochipdata.zip), hopefully that will make it behave.

      Thanks for the compliments!

       
    • Santiago

      Santiago - 2009-01-24

      Ok... solved in: http://gcbasic.sourceforge.net/newfiles/update-nochipdata.zip

      Now i have to find how to set Vref inputs with 10 bit ADC... by now i'm using some functions i had in asm adapted for gcbasic... very easy working with inline asm in this compiler.

      Thanks...

      GCBASIC is a Great compiler, i din't know there was an open-source basic pic compiler working in linux, and i'm happy to find this one... now there is a new section for gcbasic in "pic linux" forum (spanish talkers) i hope more people can know it...

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.