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:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
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.