Re: 5V tolerant i/o pins and also my comments on Circular buffers
2004-03-08 by Owen Mooney
It strikes me that your are hitting at the problem the wrong way.
Why don't you feed the 3.3.V output directly into the gate of a N
channel enhancement mode MOSFET, and use the drain directly connected to
your load - forget the UDN2981's.
The circuit is simple. Micro output direct to mosfet gate, source to
ground, drain to load. You can switch amps this way (depending on the
size of FET you use), and hey! its cheap and circuit board efficient (if
you use surface mount fets - does anyone use anything else these days).
There are several simple FET circuits for handling a range of
multivoltage I/O conditions. I can put them in the files section if
there is interest (I just have to work out how to submitt them!)
Owen
> I want to connect the LPC2114 (or other LPC2xxx) to 5V solenoid
> drivers (eg. UDN2981's). Can I pull up the outputs of the LPC to 5V
> with say 10K, to satisfy the input reqmts of the driver?
Circular Buffers
I was suprised at the sheer NOISE created by my comment on circular
buffers. Of course it was a simplified example. I do feel obliged to
clear up.
There are two exception conditions, underflow and overflow. I showed a
(very) simple handling of underflow as it is the most common condition
Handling overflow is far more complicated as it depends on the scenario.
Some times you want to fail on overflow, sometimes you wnat to overwrite
the oldest data on overflow. It depends.
In the simple case - one producer one consumer - no exception handling,
there are no thread safe problems as consumers and producers are
operating on different variables at all times.. Exception handling is
not thread safe, as this code operates with both pointers.
In the obvious scnenario - interrupt handling - my psuedo code would be
modified:
buffer[1024];
int onpointer=0,offpointer=0;
procedure addbyte(data) { // no exception handling
buffer[onpointer]=data;
onpointer++;
onpointer= onpointer & 1023;
}
function getbyte() {
res // an integer, byte, float or string - depending on what you want
disable interrupts
if (onpointer==offpointer) {
enable interrupts
return 0; // no data available
}
enable interrupts
res=buffer[offpointer];
offpointer++;
offpointer=offpointer & 1023
ret res;
}