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.
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.