Author Topic: MCU digital pin output as a voltage reference?  (Read 1348 times)

0 Members and 1 Guest are viewing this topic.

Online HwAoRrDk

  • Frequent Contributor
  • **
  • Posts: 595
  • Country: gb
MCU digital pin output as a voltage reference?
« on: September 27, 2016, 02:37:41 am »
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 an exact 5V 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.)
 

Offline Paul Moir

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: ca
Re: MCU digital pin output as a voltage reference?
« Reply #1 on: September 27, 2016, 03:02:43 am »
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. 
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 1750
  • Country: 00
Re: MCU digital pin output as a voltage reference?
« Reply #2 on: September 27, 2016, 03:16:26 am »
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
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 7818
Re: MCU digital pin output as a voltage reference?
« Reply #3 on: September 27, 2016, 03:22:41 am »
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.
 

Online HwAoRrDk

  • Frequent Contributor
  • **
  • Posts: 595
  • Country: gb
Re: MCU digital pin output as a voltage reference?
« Reply #4 on: September 27, 2016, 04:01:42 am »
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.

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

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.

I don't think this 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf