MCU digital pin output as a voltage reference? - Page 1
Forum section: electronics / beginners

author: HwAoRrDk
author_rank: Super Contributor
timestamp: September 26, 2016, 04:37:41 pm
content: I have been working on a project where I needed a voltage reference which needed to be switchable to either VCC (+5V) or GND - nothing in-between. So, I had the idea to use a digital I/O pin on my microcontroller (ATMega328P) to supply the reference voltage by simply toggling the output on that pin high or low as appropriate. (Note that I don't need anexact5V reference, just whatever VCC is, so the voltage from an I/O is perfectly fine for my purposes.)It seeeeems to work okay... but I can't shake the nagging doubt in the back of my mind that I might be doing something stupid here. Am I?Oh, and a related question: I came to the realisation that, logically-speaking, I don't actually need to dedicate a specific I/O pin on my micro to switching the voltage reference, as the needed change in state there happens to correspond to another I/O I'm using to drive another IC (a darlington transistor driver). If I 'piggy-back' on this other I/O line for my reference, will there be any side effects? Or am I best dedicating a micro I/O pin? (If it is indeed a valid method.)

author: Paul Moir
author_rank: Frequent Contributor
timestamp: September 26, 2016, 05:02:43 pm
content: Sure, internally it's using FETs for driving the pins so it should go all the way down to 0 and all the way up to Vcc. If you were talkin' TTL or something like that here, the story would be different.Regarding the pin driving the darlington, refer to the datasheet Figure 34.1.8 to 34-24 (page 414 - 416). The current driving the darlington's base is going to offset the voltage a bit since the pin drivers have some impedance.

author: ebclr
author_rank: Super Contributor
timestamp: September 26, 2016, 05:16:26 pm
content: I would suggest a RC circuit to void the switching noice on digital output, But you already wrote that accuracy isn't you point then this can be used a big drift is aceptable

author: Ian.M
author_rank: Super Contributor
timestamp: September 26, 2016, 05:22:41 pm
content: The pitfall is internal voltage drops in the Vcc and Gnd busses on the die and the bond wires. If you have other outputs that are heavily loaded and drawing current from the bus your output is set to, the internal Vcc may droop or Gnd may bounce up a bit. Write some code to exercise the other outputs and scope the one you intend to use to see if you can stand the ripple on it . . .If not, you'll need to put it through a well decoupled single gate buffer and route the Vcc and Gnd tracks to the buffer *extremely* carefully.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: September 26, 2016, 06:01:42 pm
content: Quote from: Paul Moir on September 26, 2016, 05:02:43 pmCouldn't find the figures you referenced on those pages (I must have a different revision of the ATmega328 datasheet), so not 100% sure which you were referencing, but was it this one?As far as I make it, I think the current to my darlington driver's base will be under 2mA, so voltage drop on the I/O line should be pretty small (~50mV) across all temperature ranges. I think that should be acceptable, as I'm only taking ADC readings for a signal relative to the reference voltage, not absolute.Quote from: Ian.M on September 26, 2016, 05:22:41 pmI don'tthinkthis will be a problem, as during the period the reference voltage will be in use, while a handful of the I/O outputs will be busy sourcing current to the aforementioned darlington driver, none will actually be being actively toggled, so any drop should be fairly static, right? If the reference voltage doesn't fluctuate, that's probably acceptable.