Re: Using FVR on a adc channel
Posted: Tue Jun 16, 2026 7:19 am
I got something working - so at least the hardware is good?
My first test - I used the potentiometer component - and didn't get the result I was expecting
I'd connected 3v3 from an Arduino to rd1 as a simple test value (and of course connected the ground pins) I connected the UART Tx to a logic analyser to read the results (though a USB-UART FTDI device would have been better!)
The MCU is powered from a PSU - set at 5v (although it insists this is 5.02V) and I used a PICKit5 to program.
I then tried a simple ADC setup in C - and this works AOK (I get 3.28V with slight variations +/- in the 6 digits result)
As a further sanity check - I changed the gain to 2 (2.048v) and got the expected overflow value.
So this is hardcoded to rd1 - and I am using a external 20MHz crystal - but the code **should** work pretty much as is on your hardware after tweaking the pin if needed (and the target/clock) In GetADC - the pin address is 0x19 (for RD1) - this should really be set using a constant or calculated to allow a different pin to be selected...
I also setup the ADC and then leave it enabled - unless you are doing continuous readings (as here) then you should probably disable it after a measurement.
Next - why doesn't the potentiometer give the correct result?
Martin
My first test - I used the potentiometer component - and didn't get the result I was expecting
I'd connected 3v3 from an Arduino to rd1 as a simple test value (and of course connected the ground pins) I connected the UART Tx to a logic analyser to read the results (though a USB-UART FTDI device would have been better!)
The MCU is powered from a PSU - set at 5v (although it insists this is 5.02V) and I used a PICKit5 to program.
I then tried a simple ADC setup in C - and this works AOK (I get 3.28V with slight variations +/- in the 6 digits result)
As a further sanity check - I changed the gain to 2 (2.048v) and got the expected overflow value.
So this is hardcoded to rd1 - and I am using a external 20MHz crystal - but the code **should** work pretty much as is on your hardware after tweaking the pin if needed (and the target/clock) In GetADC - the pin address is 0x19 (for RD1) - this should really be set using a constant or calculated to allow a different pin to be selected...
I also setup the ADC and then leave it enabled - unless you are doing continuous readings (as here) then you should probably disable it after a measurement.
Next - why doesn't the potentiometer give the correct result?
Martin