Menu

Using Alias for A2D input names

Help
2009-08-04
2013-05-30
  • Edward LaBudde

    Edward LaBudde - 2009-08-04

    Hi all, newbie here.  Have encountered an “interesting” problem.  I have built a power monitor that measures the amps and volts of a battery charger.   I used an alias for the two A2D channels as “Amps” and “Volts” thusly:

    #define Amps PORTA.0
    #define Volts PORTA.1

    Using this code
    Amp_sample=readAD(Amps)    '(Amps)
    Volt_sample=readAD(Volts)        '(Volts)

    It does not work correctly.  It works only when the two channel inputs are tided together.
    When the two inputs have separate sources the readings are wrong, and there is a significant interaction between the two channels.

    Here is the assembler code it produces:
    .ASM File
    SAMPLE
        clrf    ADREADPORT
        btfsc    PORTA,0
        incf    ADREADPORT,F
        call    FN_READAD
        movf    READAD,W
        movwf    AMP_SAMPLE
        clrf    ADREADPORT
        btfsc    PORTA,1
        incf    ADREADPORT,F
        call    FN_READAD
        movf    READAD,W
        movwf    VOLT_SAMPLE
       
    If I use the ports directly it works correctly.
    As in the following:

    Amp_sample=readAD(AN0)        '(Amps)
    Volt_sample=readAD(AN1)        '(Volts)

    .ASM  File
    SAMPLE
        clrf    ADREADPORT
        call    FN_READAD
        movf    READAD,W
        movwf    AMP_SAMPLE
        movlw    1
        movwf    ADREADPORT
        call    FN_READAD
        movf    READAD,W
        movwf    VOLT_SAMPLE

    Does anyone have any idea why there is a problem?

    Regards, Ed.
       

     
    • kent_twt4

      kent_twt4 - 2009-08-05

      Had to look at the old RV voltmeter project.  Just change the define to:

      #define volt AN0

      I think you have to view this quirk, as an effort to standardize across device lines regardless of what port AN0 is actually on.

       
    • Edward LaBudde

      Edward LaBudde - 2009-08-05

      Kent, thanks for the response.  Another "undocumented feature" no doubt. 
      And just when I was getting to think I was getting the hang of things.  GCB has to keep me in my place!

      Regards, Ed.

       

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.