I notice a couple of oddities in your code that may (or may not!) be part of the problem. You are using the PBP ADCIN command but not any of the PBP defines. I don't know if PBP needs the defines beyond setting some register bits which you do directly. Below is a gentle re-arrangement of your code, trying to follow the exact order recommended in the manual. Also, it explicitly waits until the FVR is ready and, instead of using ADCIN, manually starts the conversion, waits for it to finish, and then reads the result.
Code:
' ---------- Gets a Voltage reading on Port1.0 ---------
' Note: - Application circuit has a 3.3v voltage reg fitted so could use VDD as Vref in ASCON1 register
' - have used the ADC Fixed Voltage Ref Modual in 16F1825.
' - PortA.0 ia also used as Digital Output of Power LED active low via Pch - Mosfet
' - Supply Voltage input range is 8.1V - 3.5V to Voltage divider ( Vsupply --> 27k -|- 15K -- GND) giving ADC input on PORTA.0 = 2.8 - 1.4V
' ( PortA.0 )
Get_volts :
TRISA.0 = 1 ' setup Port A.0 input=1,output=0 for I/O pins ( Note RA3 - is input only (digital)- refer spec)
ANSELA = %00000001 ' Set Port A.0 - Analoge I/O , 0 = Digital 1 = Analog
FVRCON = %10000010 ' Bit 7 =1 enable Fixed Voltage Ref Modual, Bit 6 = VRef ready bit =1 always ok on 16F1825, Bit 5 - Temp indicator 1= enable/0 = disable
' Bit 4 = Temp Indicator Range Sel 0=Vout -Low range / 1= Vout -High range , Bit 3-2 = 00( DAC Fixed volt sel )
' Bit 1-0 = 10 - ADC Fixed Vref of 2.048v
while FVRCON.6 = 0 : wend 'wait for FVR to be ready
ADCON0 = %00000001 ' bit 7 -N/A , Bit 6-2 = ADC chan Sel /Tempature output /FVR output = AN0 sel = 00000 ,
' Bit 1 - Go/_done status flag - 1 = Go do ADC / 0 = Done ADC , Bit 0 = Enable ADC = 1 / 0 = Disable ADC
ADCON1 = %10100011 ' bit 7 = 1 ADFM ( ADRESH, ADRESL - right justify ).Bit 6-4 ADCS = 010 - Fosc/32 conversion clock
' Bit3 - N/A , Bit2 = 0 (Vref- is connected to Vss) , Bit1-0 = 11 - Vref+ connected to FVR Modual
pauseus 10 ' allow Vref to stablise - ??? - not required for the 16F1825/29 ??
' adcin 0, ADval ' Read PortA.0 value into variable , this applies the fixed voltage ref (via ADCON0,ADCON1,FVRCON)
' ' to comparitor and ADC pin selected and gives result ???
ADCON0.0 = 1 'start the conversion
while ADCON0.0 = 1 : wend 'wait for it to finish
ADVal.byte0 = ADRESL
ADVal.byte1 = ADRESH
write $01 ,ADval.byte0 ' debug of voltage measurement - lower byte
write $02 ,ADval.byte1 ' debug of voltage measurement - upper byte
If ADval <= 1024 then ' Have no idea of the value its going to get ?? , but if below value of 1.6V ( 4.5v Vsupply) then set Power low values
Pulse_off = 500 ' Set Pulse_off duration to 500us to signal power low to IR_RX
Flash_rate = 10 ' Set Power Led toggle to fast rate to show low power
Else
Pulse_off = 276 ' Set Pulse_off duration to 300us( adj) to signal NOT power low to IR_RX
Flash_rate = 100 ' Set Power Led toggle to Normal rate to show NOT low power
endif
' Restore PortA.0 to digital . ACD OFF etc
ADCON0 = %00000000 ' Set ADC to Disable - Bit 0 = Enable ADC = 1 / 0 = Disable ADC
ANSELA = %00000000 ' Set Port A.0 = 0 Digital, 0 = Digital 1 = Analog
TRISA.0 = 0 ' setup Port A.0 input=1,output=0 for I/O pins ( Note RA3 - is input only (digital)- refer spec)
return
Hope this helps...
Best Regards,
Paul
Bookmarks