Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I don't understand the .4v offset thing. I have set the circuit to give 2.48v at 1A but then the LCD shows garbage at 0A, I assume its going less than 0.
Hi Eric,
The problem may be something different as when I set the circuit to 2.44 then I have to multiply by 4 to get 1000 as the ADC count is only 250ish. But doing that means its fine at 1A but reads 56 for 16mA.
I must be doing something wrong? But what?
Al
adval = (adval */ 500)>>2 ' Equates to: (adval * 500)/1024
Hi Eric,
If I set the OPA to 2.44v out at 1A and then use the ADC on it it shows 500 when multiplied by 2. So do I adjust the OPA to output enough to make the ADC 500 or what else? Really puzzled at this. But thats normal at least. hehehe
EDIT. Is this line doing the damage?
Code:adval = (adval */ 500)>>2 ' Equates to: (adval * 500)/1024
Al
Hi Eric,
I followed the datasheet for the 872 and it does say that the first 4 "As are 0,1,2,3 channels then the last AD channel is "A5 missing out RA4.
I think I got the hex numbers right s0 ADC1 = $41, 1 = $49, 2 = $51, 3 = $59 and 4 = $61 though I wasn't sure if the last one should be $69 even though that would be RA5 I understood it that they didn't count RA4 at all?
How do you read it?
Al
'Subroutine to get pot x value
getposval:
ADCON0 = 41h 'Set A/D to Fosc/8, AN0, On
Gosub getad
posval = adval
Return
'Subroutine to get pot negval value
getnegval:
ADCON0 = 49h 'Set A/D to Fosc/8, AN1, On
Gosub getad
negval = adval
Return
'Subroutine to get 5v current value
getfive:
ADCON0 = 51h 'Set A/D to Fosc/8, AN2, On
Gosub getad
five = adval
Return
'Subroutine to get variable amps value
getvaramp:
ADCON0 = 59h ''61h 'Set A/D to Fosc/8, AN3, On
Gosub getad
varamp = adval
Return
'Subroutine to get temperature value
gettherm:
ADCON0 = 61h 'Set A/D to Fosc/8, AN4, On
Gosub getad
therm = adval
Return
getad:
WaitUs 50 ''pauseus 50 ' Wait for A/D channel acquisition time
ADCON0.2 = 1 'Start conversion
While ADCON0.2
Wend 'Wait for it to complete
adval.HB = ADRESH 'Write conversion result
adval.LB = ADRESL
'''adval = adval * 2
WaitMs 2 ''pause 2
Return