More ADC questions and output questions

rq3

Senior Member
I trust someone smarter than me can help. I am deep into the A/D converter capabilities of the 8M2 Picaxe, and am very confused by the Microchip 12F1840 data sheet.

I have written, and successfully used, Picaxe code using the internal 1.024 volt reference for the ADC function. I believe it works because changing the reference to 2.048 volts requires double the input for the same response. My test equipment is more than capable of sub-millivolt accuracy and resolution.

However, the base chip data sheet says the reference voltage is set by selecting the gain of a buffer amplifier (1X, 2X, 4X). The data sheet goes on to say that any output of the buffer amplifier can be used as the reference for the A/D converters. The data sheet then goes on to say don't use the 1.024 volt reference (1X) output of the amplifier as an A/D reference. It appears to work just fine, but why? Is it reliable? Does it have lousy tolerances (unlikely, since the 2X and 4X values are derived from it?). I'm aware of the errata sheet from Microchip that Goeytex found specifying that the 1.024 volt reference be approached in steps. That is not a problem. Nor does it appear to be necessary. Microchip gives no reason for the errata sheet. Is this only something that shows up when the chip is running under liquid nitrogen, or boiling water, or when the moon is full?

In a similar vein, the Microchip data sheets don't have any kind of "internal schematic", unlike the old National Semiconductor or Texas Instrument data sheets. It's not possible to determine whether an active logic output pin (high, low) is established through a MOSFET totem-pole. In other words, can an active LOW output pin safely sink current from a logic pin at a voltage lower than Vdd. I'd say: "Of course it can". But there is nothing that I can find in the data sheet that explicitly says so, especially with all of the other functions which may, or may not, be "attached" to any particular pin. I can envision a situation in which releasing the pin from an active low could temporarily put Vdd level voltages on the pin, effectively back-driving the in-coming low voltage logic gate with excessive current.

I know I'm probably asking questions that don't apply to the "normal" Picaxe environment, but even the manufacturer of the silicon seems to be less than forthcoming with answers to questions like these.

Any thoughts?
 
Last edited:

AllyCat

Senior Member
Hi,

Yes, obviously the ADC Reference "can" be connected to the FVR1024 (the data sheet says so) but it also says that the minimum ADC Reference Voltage "should" be greater than 1.8 volts (I think they actually say "must"). That's probably because the data also says (something like) "The ADC is always monotonic with no missing codes" (my .PDF reader is not allowing me to cut and paste :( ). Which means that they are "guaranteeing" that at the specified supply voltages and temperatures, with a rising input voltage, the output will always count 1 .. 2 .. 3, etc. and in particular 511 .. 512 .... But that last step involves 9 "weighted sources" switching off and a larger one switching on in the ADC hardware (with an accuracy of better than 0.2%). So, when you say "It appears to work just fine", have you actually tested the 511 .. 512 step (and preferably all the others) at ALL supply voltages and temperatures, etc.? That's a Rhetorical question as even the Microchip data says "These parameters are characterized (or by design) but not tested". ;)

I suspect the National Semiconductor and Texas Instrument schematic diagrams you saw were for bipolar chips, not MOS? And IMHO they usually weren't particularly "accurate" because many parasitic effects/components weren't shown. As an aside: it's interesting that Microchip appear to use a lot of "resistors" in their designs (e.g. the "Weak Pullups" and the "DAC") whilst most IC manufacturers use (constant) "Current Sources" (which are normally much easier to integrate). I'd be interested to know if (for example) they actually "emulate" resistors from FETs, or if they have a "high resistance" fabrication process. That could be quite significant when used at extremes of voltage or temperature.

I think it's clear that the output pins are driven by "complementary" FETs and the graphs in section 31 of the data sheet give a fair indication of their characteristics (at 5 , 3 and 1.8 volts). I believe we always used to consider a "Totem Pole" output stage to use (power) transistors of the same polarity (i.e. NPN), but I don't know if that's an official definition. However, your comment "... releasing the pin from an active low could temporarily put Vdd level voltages on the pin" depends if by "releasing" you mean switching to a High Logic level or to "Tri-State" (floating, high impedance) selected in PICaxe Basic by an INPUT or REVERSE command. Externally pulling a tri-state output Low should be "safe", but not necessarily an Active High (at least with a 5v Vdd rail).

Cheers, Alan.
 

rq3

Senior Member
Alan, many thanks for your thoughts. I went and looked up old NS, TI, RCA, and Fairchild data sheets, and it used to be very common practice to include a "representative" input and output schematic for various pin functions. I always found that useful during design, and I'm sorry to see that it's no longer "standard practice".

The ADC circuit I'm toying with needs only to detect the first 20 or so counts, so no, I haven't tested it at midrange of a 10 bit A/D conversion, using the 1.024 volt reference. What strikes me odd is that the references all come from the same buffer amplifier, so the "resistor string" (if that is indeed what it is) is in play no matter the reference. I do take your point that maintaining the accuracy of such a string might be problematic over environmental and operating ranges, especially when each count is only 1 millivolt for a 10 bit read on a 1.024 volt reference! But it's 2mV for the 2.048 volt reference, and that is allowed per the data sheet. That implies that the "resistor string" may run out of monotonicity somewhere around 1 mV per count. There is just not enough info to glean from the datasheet to actually know why some things are specified the way they are. Which is frustrating.

Using a very fast o'scope, I can detect no glitches or feedthrough when switching a 20M2 output from active logic low (pulling down a 4.7K resistor from the 5 volt rail) to high Z input, so I feel fairly safe there.
 

Goeytex

Senior Member
Why not open a ticket with Microchip to see if you can get an "official" answer?. There must be a reason for MCHIP saying not to use 1.024 for ADC VREF. Maybe they will spill the official beans. We can speculate forever but that will not provide a satisfactory answer.

My testing and use with FVR 1.024 used as ADC VREF+ has only been done in an environment where the temperature ranged from about 0c to 35c where it performed quite well. However, I did not use $100,000 test equipment calibrated to NSF standards to test with. And I was not measuring to down to 1/2 LSB. What I got was "good enough" for my application. Sometimes good enough is good enough.

If I really needed a 1.024 ADC reference in a critical application I would not use PIC/Picaxe for the ADC. There are better options when accuracy and repeatability are required over a specified range of operating conditions.
 

rq3

Senior Member
Why not open a ticket with Microchip to see if you can get an "official" answer?. There must be a reason for MCHIP saying not to use 1.024 for ADC VREF. Maybe they will spill the official beans. We can speculate forever but that will not provide a satisfactory answer.

My testing and use with FVR 1.024 used as ADC VREF+ has only been done in an environment where the temperature ranged from about 0c to 35c where it performed quite well. However, I did not use $100,000 test equipment calibrated to NSF standards to test with. And I was not measuring to down to 1/2 LSB. What I got was "good enough" for my application. Sometimes good enough is good enough.

If I really needed a 1.024 ADC reference in a critical application I would not use PIC/Picaxe for the ADC. There are better options when accuracy and repeatability are required over a specified range of operating conditions.
So after I got my circuit working to much more than my satisfaction, I did indeed open a ticket with Microchip (thanks for the kick, Goeytex; the last interaction I had with Microchip went no-where) several weeks ago. The initial response from them was to quote the datasheet, basically saying that it's true because the datasheet says its true, and my response to their response was that I knew how to read a datasheet. I wanted to know WHY their datasheet says not to use the 1.024 volt ADC reference. Especially when it appears to work quite well, even over a pretty stressful temperature range, and ALL of their reference voltages are based upon the 1.024 volt reference, just available from the same amplifier with gains of 1, 2, or 4.

The tech assigned to my ticket immediately bumped my request up the line, probably to a chip designer who retired years ago. I notice that the data for a lot of the older Microchip devices is still marked "preliminary", even after 10 years in production, and the use of the 1.024 volt reference is buried in there. I suspect that the 1.8 volt minimum reference is related to the minimum power supply voltage, and really doesn't apply, but we'll see. Or maybe not.

I'll post the final resolution if and when it appears. I know that the Picaxe is intended to be an easy to use educational device, and it certainly is, especially for an old geezer like me, who can't write code to save my life. But getting the underlying electrical details (my life as an EE) can be interesting and useful, especially if it makes the manufacturer of the chip itself realize that they may be asleep at the switch.
 
Last edited:

Goeytex

Senior Member
@rq3,

Glad you opened a ticket on this and that you did not accept the initial reply. I will certainly be interested in the next response. My experiences has been that given time, Microchip will eventually get the correct information to you if you are nice, yet persistent.

I once had an issue with a specific peripheral (USART) on PIC 16F1618. No TX output at all. I followed the datasheet exactly setting the registers just as the datasheet directed. I had done this on many different PICs before with no issues., But with this one... Nada, Nothing. Opened a ticket. In the meantime, by trial and error, I found that the datasheet was incorrect for the Peripheral Pin Select (PPS) setting for TX and got it working. This was confirmed by my assigned Support Tech. He sent me a revised chart 13.2 with the correct settings for all of the registers as several were incorrect. It then took Microchip 1 year to revise the datasheet and this correction was never put in the errata sheet. The wheels turn slowly at Microchip sometimes.
 

rq3

Senior Member
The saga continues. The latest response from Microchip (which makes no sense to me), and my response to their response:

Hi Ripley,
We have heard from our internal team.

The reason for this is a hardware limitation in the ADC internal circuitry. Those circuits are essentially biased by the ADC reference voltage and so doesn’t support references below 1.8V.

Unfortunately due to this being a hardware specification, there is no workaround.

Hope you understand.

Thanks and Regards,

Aarthi




Aarthi, thank you for your response. Your answer begs the question: Why does the 1.024 volt reference work? Because it does. I can understand that the reference voltage source or buffer amplifiers might need SUPPLY voltages of at least 1.8 volts to operate correctly, but not the REFERENCE voltage itself.

Are you sure that Microchip did not confuse the two back in the mists of time? And since the 1.024 volt reference does indeed appear to work well,
here's a really tough question. If what you say is true, why does it work, and under what circumstances could I expect it to not work?

In short, the "master" reference voltage is ALWAYS 1.024 volts, but has a gain of 1, 2, or 4 from the buffer amplifiers to get the 2.048 and 4.096 volt references.

If, as you say, the ADC internal circuitry is biased by the reference voltage, where does the 1.8 volt minimum requirement come from (other than the minimum power supply voltage, which is understandable).

Again, are we sure we are not confusing the minimum reference voltage with the minimum power supply voltage?
 

rq3

Senior Member
Well, a definitive answer that actually makes sense. Various Microchip products have different minimum ADC reference voltages because:

1) The FET switches that shunt the input signal to the sample and hold capacitor need a minimum internal supply to turn on fully. If they don't, then the conversion loses bits and no longer meets the full 10 bit specifications of the data sheet.

2) In the case of the 8M2, the base 12F1840 device outputs the 10 bit conversion in an 8 bit high byte, and a 2 bit low byte. Using the internal 1.024 volt reference MAY cause the device to lose the low byte, so the lower 2 millivolts of resolution MAY be lost.

3) The high byte may have an offset to the low side, but it will be consistent and monotonic (i.e., the conversion output won't reverse direction).

I confirmed this by firmly shorting the AD input of an 8M2 to circuit ground, and ran the conversion in a tight loop, with the output reported via sertxd to a terminal window. Indeed, it consistently reports 3, with a very occasional 2 thrown in as the conversion "trips" over the missing lower bits.

This information did NOT come from Microchip, whose response was to consistently insist that it's true because the data sheet says so. I tracked down a retired Microchip engineer from a forum, and had a nice productive chat with him. It yielded an answer that not only made sense, but one that could be tested in a straightforward fashion. He was quite friendly, but asked me not to share his contact information.

So there you go. You can reliably use the internal 1.024 volt reference, but you must be willing to kiss the low byte goodbye. You still get 10 bits of high byte resolution.
 

AllyCat

Senior Member
Hi,
1) .....the conversion loses bits and no longer meets the full 10 bit specifications of the data sheet.
........ You still get 10 bits of high byte resolution.
I'm not clear if he/you are saying that the low(er) bits may be "lost" or are just potentially "incorrect", but the difference is largely irrelevant. If you "lose" just one bit (i.e. it is possibly inaccurate) then you have basically the same situation as a "genuine" 10-bit conversion using FVR2048. And if you lose the two low bits then you have an 8-bit ADC which gives 4 mV resolution, the same as the 10-bit ADC referenced to the FVR4096. You can't get 10 bits of resolution into a byte !

IMHO the main potential "advantage" of using the FVR1024 as ADC reference is if it gives 1 mV resolution, which I have sometimes recommended on the forum (with the caveat that it might not work). In particular, I would recommend it to "novices" who probably have a better chance of getting a worthwhile (and lower-cost) solution to work, than trying to "bolt on" a 2x Op-Amp circuit to an input to the ADC. ;)

One other potential advantage of using FVR1024 is that (according to the data sheet) it is "more accurate" (i.e. has a slightly smaller tolerance spread), because it avoids any "errors" in the gain of the 2x and 4x Op-Amps, which derive FVR2048 and FVR4096 from the FVR1024 reference. But against that, the Op-Amps probably have a lower source resistance and a much better "rail to rail" capability. In my experience the FR2048 gives more accurate results at a lower supply voltage than FVR1024, when used as a reference for the DAC (not the ADC which I haven't measured exhaustively).

Cheers, Alan.
 

rq3

Senior Member
Hi,

I'm not clear if he/you are saying that the low(er) bits may be "lost" or are just potentially "incorrect", but the difference is largely irrelevant. If you "lose" just one bit (i.e. it is possibly inaccurate) then you have basically the same situation as a "genuine" 10-bit conversion using FVR2048. And if you lose the two low bits then you have an 8-bit ADC which gives 4 mV resolution, the same as the 10-bit ADC referenced to the FVR4096. You can't get 10 bits of resolution into a byte !

IMHO the main potential "advantage" of using the FVR1024 as ADC reference is if it gives 1 mV resolution, which I have sometimes recommended on the forum (with the caveat that it might not work). In particular, I would recommend it to "novices" who probably have a better chance of getting a worthwhile (and lower-cost) solution to work, than trying to "bolt on" a 2x Op-Amp circuit to an input to the ADC. ;)

One other potential advantage of using FVR1024 is that (according to the data sheet) it is "more accurate" (i.e. has a slightly smaller tolerance spread), because it avoids any "errors" in the gain of the 2x and 4x Op-Amps, which derive FVR2048 and FVR4096 from the FVR1024 reference. But against that, the Op-Amps probably have a lower source resistance and a much better "rail to rail" capability. In my experience the FR2048 gives more accurate results at a lower supply voltage than FVR1024, when used as a reference for the DAC (not the ADC which I haven't measured exhaustively).

Cheers, Alan.
Alan, I didn't state that well. The conversion is still 10 bits. Each bit holds 1 millivolt of resolution (1024 counts with a 1.024 volt reference). But the output is in two bytes. The lower byte, of two bits, holds the potentially worthless first two counts. The upper 8 bit byte holds the remaining 8 bits, but still at the 10 bit resolution (1 millivolt per count).

The DAC and ADC references come from different reference buffer amplifiers, and I haven't pursued the DAC reference, nor will I at this time.

The accuracy of all of the reference voltages is pretty bad (due to the accuracy of the baseline 1.024 volt reference and the gains of the buffers), so no one should be expecting to do lab quality voltage measurements with them. But if you want to trigger off of a 10 bit readadc10 measurement at some reasonable level above, say, 4 millivolts, my research indicates that you can. The count will be stable and reliable. The actual value that the count represents will not be accurate, but it will be stable and reliable.
 

AllyCat

Senior Member
Hi,
The upper 8 bit byte holds the remaining 8 bits, but still at the 10 bit resolution (1 millivolt per count). ..... The count will be stable and reliable.
The upper byte contains a value with a resolution of 8-bits, or 1 in 256. Thus (as far as that byte value is concerned) the resolution is 1.024 / 256 V = 4 mV. The byte value will only change for (approximately) each increase or decrease of 4 mV input signal. Yes, of course the repeatability will be better than the accuracy, but that normally applies; however, I'm not convinced it will (always) be <1mV, which the data sheet is attempting to "protect" (or exclude).
.... The accuracy of all of the reference voltages is pretty bad (due to the accuracy of the baseline 1.024 volt reference and the gains of the buffers),
Generally, the "real" devices are far better than their data sheet. An extreme example appears to be the Weak Pullup resistors which are specified as 17k - 200k, but rarely seem to be far outside the range of 30k - 40k. In passing, I was also going to mention the Watchdog Timer (used for PICaxe's Sleep facility) which is still specified in the PICaxe (on-line) Manual as: "The sleep command is not regulated and so due to tolerances in the microcontrollers internal timers, this time is subject to -50% to +100% tolerance". But I see in my 08M2 Data Sheet, it is now quoted as 10 - 27 ms (around -35% to +70%), and the 20M2 Data Sheet (now) as 12 - 20 ms (i.e. +/- 25%). In practice it's probably better than +/- 5% and similarly I suspect the FVR is normally within +/- 1%, maybe not "Lab. Quality", but probably not far from a measurement on a low-cost hobbyist multimeter. ;)
.... if you want to trigger off of a 10 bit readadc10 measurement at some reasonable level above, say, 4 millivolts, ....
Again, I'm not clear whether you mean a "change" in level of 4 mV, or a "bias" (sit-up) voltage, but a practical example might be a 3 mV "step" or pulse signal, (biassed between 0.04 and 1.02 volts) at the ADC input. Reading the "high byte" (only) with a FVR1024 might detect that change (but might not), whilst a normal READADC10 referenced to FVR2048 should always detect it (because the Data Sheet says so). Using FVR1024 really only becomes "useful" if it detects reliably a change of less than 2 mV.

My reason for mentioning the DAC is because I've successfully used it to extend the ADC resolution up to about 15 "real" bits, by employing a combination of Oversampling and the DAC (see various Code Snippets, mainly concerned with extending CALIBADC measurements). Those techniques worked well with FVR2048 and FVR4096 references, but failed abysmally (below a Vdd of about 2.7 volts) when using FVR1024.

Cheers, Alan.
 

Goeytex

Senior Member
The 10-bit ADC result is formed by registers ADRESH:ADRESL Where the upper 2 bits of ADRESL are the LSB of the 10-Bit WORD.

The result will always be a 10-bit word with 10-bit resolution but the 2 LSB "MAY" be inaccurate if using FVR1024 as the ADC reference . It's not like the lower byte ( 2- bits) disappears and the result becomes an 8-bit byte as determined by ADRESH alone.

To me the FVR1024 issue is very close to being a nothing burger for most practical purposes. PIC 8-bit microcontrollers will not generally give 2-bit ADC accuracy over the specified temperature range, regardless of the FVR setting. Even more so when put on a breadboard with sloppy wiring and dodgy grounding.

I have over 50 different PIC 8-bit microcontrollers from baseline 12F1840 to Advanced 18FxxQ43. A random sampling shows no significant issues using FVR1024 with using good grounding technique. All return a 0 when the ADC input is grounded and all return 1023 when very near 1.023 volts. ( I used 5V for VDD)

However, given today's choices, I would not rely upon a PIC/PICAXE ADC for critical applications where a 1 bit error could be detrimental. There are better options
 
Top