I am using the Fixed Voltage Reference (FVR) of a 16F18325 to measure Vdd using the ADC using the following code.
For anyone interested how this works,
I set the FVR to 1.024V and feed it to the ADC module. The ADC is set to use Vdd and Vss as the reference.
The result should be ADCresult = (1.024/Vdd)*1024. Switching this around gives Vdd = ADCresult/(1.024*1024).
As I want this as millivolts I end up with the equation Vdd=1048576/ADCresult.
Now, all was working as expected and I was storing Vdd every 15 minutes (running on single Lipo battery).
Then, yesterday I starting getting readings around 1038 mV without any change to the code.
I am monitoring the results in Tera term via a USB to RS232 converter and it seems this is the culprit.
With the converter connected I get stupidly low readings, disconnect it and I get the correct readings.
Anyone got any theory why this is so?
I only have Gnd, RX & TX connected but it is still capable of powering the circuit on it's own!
I'm wondering if using current limiting resistors (22k) on RX and TX might fix this.
However, I'm still at a loss as to how this is possible. I can't see and change in Vdd using a multimeter and no noise with a scope. It's just completely baffling.
Edit, The resistors (22k) stopped the serial working completely. The USB - RS232 module is a Prolific PL2303.
Thanks for reading and for any suggestions.
Mike.
Code:
uint16 Measure_Vdd(){
uint32 result;
FVRCON=0b10000101; //FVR set to 1.024V
ADCON0=0b11111101; //adc on and select FVR
ADCON1=0b10010000; //Right Justify, Tosc/8, Vss - Vdd as reference
__delay_us(50); //delay for settling time of FVR and ADC acquisition time
GO=1; //Start ADC
while(GO); //Wait for conversion to complete
ADCON0=0; //Turn ADC off
FVRCON=0b00000101; //Turn FVR off
result = 1048576L/ADRES;
return((uint16)result);
}
I set the FVR to 1.024V and feed it to the ADC module. The ADC is set to use Vdd and Vss as the reference.
The result should be ADCresult = (1.024/Vdd)*1024. Switching this around gives Vdd = ADCresult/(1.024*1024).
As I want this as millivolts I end up with the equation Vdd=1048576/ADCresult.
Now, all was working as expected and I was storing Vdd every 15 minutes (running on single Lipo battery).
Then, yesterday I starting getting readings around 1038 mV without any change to the code.
I am monitoring the results in Tera term via a USB to RS232 converter and it seems this is the culprit.
With the converter connected I get stupidly low readings, disconnect it and I get the correct readings.
Anyone got any theory why this is so?
I only have Gnd, RX & TX connected but it is still capable of powering the circuit on it's own!
I'm wondering if using current limiting resistors (22k) on RX and TX might fix this.
However, I'm still at a loss as to how this is possible. I can't see and change in Vdd using a multimeter and no noise with a scope. It's just completely baffling.
Edit, The resistors (22k) stopped the serial working completely. The USB - RS232 module is a Prolific PL2303.
Thanks for reading and for any suggestions.
Mike.
Last edited: