ADC quirks

rq3

Senior Member
I've been playing with the 20M2 ADC functions, and think I can confirm that the selection of an internal reference (whether 1.024, 2.048, or 4.096 volts) does NOT need to be re-invoked after making a readadc or readadc10 measurement, nor does any other ADC configuration or setup. This is contrary to the Picaxe manuals, but MAY be device specific. Only tested on a 20M2, and soon to be tested on an 08M2.

However, there is a a Microchip errata sheet (yes, I'm trying to find it again) which DOES state that, when using the 1.024 volt reference, it needs to be declared, once, in steps from 4.096, to 2.028, and finally 1.024 volts. In other words, you can't just fvrsetup FVR1024. Sometimes it works, sometimes it doesn't.

You need:
fvrsetup FVR4096
fvrsetup FVR2048
fvrsetup FVR1024

in sequence during the initialization of your chip. It's not clear whether the 4096 stage is necessary, nor do I care, since it only happens once during the boot of the chip.
I have verified this by with very simple code that toggles an output at a very low ADC level input, and then changing the reference voltage between tests. The input and output were monitored on a Tektronix 2465 oscilloscope, with an input sensitivity of 2 millivolts per division.

Another odd artifact is that the ADC seems to be more sensitive, yet more consistent, at higher clock rates. At least on the 20M2, a clock of 32 MHz works better than the default. I'm not looking to capture fast inputs (25 milliseconds or so), so that one has me stumped for now.

Just my $0.02 worth.
 

Goeytex

Senior Member
Good information.

Not sure how Picaxe sets the sample ADC sample rate conversion clock. But I imagine that it is radiometric with with FOSC. You might be able to play with the ADC (ADCON1 Register) settings using POKEFSR to change the ADC conversion clock speed.

See page 151 of the PIC 16F1829 Datasheet.
 
Last edited:

PhilHornby

Senior Member
In other words, you can't just fvrsetup FVR1024. Sometimes it works, sometimes it doesn't.
You may have just found the answer to the strange problem I have just spent two weeks chasing.

(I have a slightly unstable feedback circuit, which monitors the output of a filtered PWM signal). At one point, I was convinced I was getting different results from the same changes, in different debug sessions. Maybe I was?

I will investigate further!
 

Goeytex

Senior Member
@rq3

I think the Errata Sheet you are referring to may be for the PIC 12F840 (Picaxe 08M2). This would apply ONLY to the 08M2.
It reads as follows:

-------------
When using the FVR module, if the gain
amplifier outputs are set via the CDAFVR or
ADFVR bits in FVRCON while the module is
disabled (FVREN = 0), the internal oscillator
frequency may shift, device current
consumption can increase, and a Brown-out
Reset may occur.

Work around:

Set the FVREN bit of FVRCON to enable the
module prior to adjusting the amplifier output
selections with the CDAFVR and ADFVR bits. If
switching from the 4x output setting to the 1x
output setting, select the 2x output setting as an
intermediary step. Always set the amplifier
output selections to off (‘00’) before disabling
the FVR module.
-------------
 

rq3

Senior Member
@rq3

I think the Errata Sheet you are referring to may be for the PIC 12F840 (Picaxe 08M2). This would apply ONLY to the 08M2.
It reads as follows:

-------------
When using the FVR module, if the gain
amplifier outputs are set via the CDAFVR or
ADFVR bits in FVRCON while the module is
disabled (FVREN = 0), the internal oscillator
frequency may shift, device current
consumption can increase, and a Brown-out
Reset may occur.

Work around:

Set the FVREN bit of FVRCON to enable the
module prior to adjusting the amplifier output
selections with the CDAFVR and ADFVR bits. If
switching from the 4x output setting to the 1x
output setting, select the 2x output setting as an
intermediary step. Always set the amplifier
output selections to off (‘00’) before disabling
the FVR module.
-------------
@Goeytex , thanks for finding that, it is indeed the errata sheet I stumbled across, as I intend to run an 08M2. However, I am currently using a 20M2, and the same thing seems to apply. I don't know how the Picaxe interpreter does its thing between the Microchip register settings and the Picaxe BASIC, so there may be some "technical crosstalk" even between different devices (08M2 and 20M2 silicon)?
 
Top