Page 2 of 2

Re: Using FVR on a adc channel

Posted: Tue Jun 16, 2026 7:19 am
by mnfisher
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

Re: Using FVR on a adc channel

Posted: Tue Jun 16, 2026 12:51 pm
by siliconchip
hi martin
thanks for the reply, im a little baffled about setting up the fvr, i originally set FVRCON and thought then the rest of the setting up was done by the properties box for the potentiometer acting as the adc input, therefore i dont understand why in your 'setupadc' macro you have gone to great lengths to set this up, am i missing something, this isnt a critisism, im baffled by the concept and interested to learn

cheers bob

Re: Using FVR on a adc channel

Posted: Tue Jun 16, 2026 1:18 pm
by mnfisher
Hi Bob,

I did everything myself - as using the component wasn't giving the expected result. I wanted to check that the hardware was playing nicely. It should be possible to use the component - with the extra FVR setup (although i didn't have time to check this morning) but if the component sets these registers every 'sample' it might not be - although there is the FVR option...

Martin