I'm trying to read voltage and current draw from a battery. I'm using an Allegro current IC to provide 0-5v as a representation of current (2.5v being 0 amps.) I now have code working that gives me the proper voltage from RA0, but readings from RA1 (my second ADC source) are not working. I get the same output from the PIC whether there is voltage present or not (the output being about 3.9v)
After I execute one ADCIN command and get the result, is there something I need to do (reset, change banks, etc.) in order to read another port?
Here are the relevant parts of my code as it stands tonight:
And here's an example of the output:Code:TRISA = %11111111 ' Set PORTA to all input CMCON = %00000111 ' Disable analog comparators ANSEL = %00000011 ' Set PORTA.0 = A/D in, rest digital ADCON1 = %10000000 ' Right Justify A/D result OSCCON = %01110000 ' INTRC = 8MHz ' =================================== ' Get the voltage from RA0 ' =================================== ADCIN 0, ADval ' Read A/D on RA0 ADval = (ADval*10) */ Quanta ADval1 = (ADval/10) * 2 SEROUT2 PORTB.1,Baud,["Volts: ",dec ADval1 dig 3,".",dec3 ADval1," Vdc",$0D,$0A] ' =================================== ' Get the voltage from RA1 ' =================================== ADCIN 1, ADval2 ' Read A/D on RA1 SEROUT2 PORTB.1,Baud,["Amps: ",bin ADval2 ," A",$0D,$0A]
Note that the voltage is verified and correct. The problem is that the amperage value is the same whethere voltage is present or not at RA1.Code:Volts: 7.854 Vdc Amps: 1100100111 A Volts: 7.862 Vdc Amps: 1100101000 A Volts: 7.854 Vdc Amps: 1100101000 A Volts: 7.854 Vdc Amps: 1100101000 A
Any thoughts here?
Thanks,
Jeff





Bookmarks