Sunday, August 22, 2021

Digital FUN-damentals: Inputs, Outputs, and a great + free Sim

Couldn't help the wordplay.

While reading datasheets for digital IC's general purpose I/O ("GPIO") pins I kept coming across electrical engineering terms that seemed opaque.  

For instance, what is a "HiZ" state for a input/output pin?  How about an "open collector"?  What is "push pull?"  

Continuing the discussion from the last several posts: let's review some basic terms used in digital circuit design. Also: I also found a great logic simulation application for Windows, Linux and so on called Logisim Evolution. 1001+ uses! I'll briefly discuss this cool digital simulation software towards the end of this post.

Electronics terms--"what I think they mean". Pro EE's and all those smarter than I am: please correct in the comments below if you find mistakes or feel something isn't clear.

First up: 

GPIO fundamentals--"Hi Z"


I summarize HiZ to mean "nothing hooked up here".  

Here is an example: a processor's input pin is connected to something, but in HiZ mode the pin fools what it is connected to into a sense that nothing is connected to it. 

In this condition, the input pin is neither seen as a digital "high" nor "low--it is in HiZ mode. 

When and why would you need that? 

A common use for HiZ is when you have a bus of shared components; that is, all components share a single trace. 

See the post here. The idea of "chip select" is fundamental to the discussion, and to digital circuit design in general. When CS is high (5v for instance), the data input becomes "HiZ", allowing other chips using to use the same data bus to not be impacted (shorted, for instance) by a chip whose connected pin must be ignored.

In my drawing above, the Chip Select is represented by the "C" input.  

Acroynms for "Hi-Z" are "tri-state", "tri-stated", has "tristate logic" and/or (somewhat confusing) "floating".  

Frequently GPIO pins on microcontrollers will be tri-stated.  On Atmel MPUs it is a feature you can turn on and off by poking bits into its MCU's registers.  See the document here section 12-4 which covers the Atmel 165.  A code example in C for this processor would be this:

PORTA &= !(1<<PA1) 

DDRA &= !(1<<DDA1)  

Interesting to note that you can change these states "on the fly" via code; the processor will respond nearly instanteously.  There are many interesting applications for this--I have used it to ground out an op amp buffer's inverting feedback loop for example--post for that specific application is here.  


next up: 

"Open Drain"

 Note: I use a transistor in my bench drawings below, but that's to make this easier to visualize, most modern IC's use some sort of FET setup internally for GPIO.




I also sometimes see this same idea called "Open collector".  

A drain is found in MOS technology while a collector is a term found in old school transistors, but the two terms are sometimes used interchangably, even when one describes most modern digital I/O better than the other.

How does "open drain" work and what does this mean? 

The circuit fragment above represents an open collector; everything to the left is built into a microcontroller or other digital integrated circuit.

How do you use this?  The output is energized by the IC, creating an electrical connection between C and E (or in MOS terms, drain and source). 

To make this useful in the real world, we often use a pullup resistor as you see drawn below: 




Using this simple design, you are not sourcing any current from the MCU, rather from VDD.  This is beneficial in general as you don't want your IC's to source current; you want your power supply to source current.

Let's next see this used as an input. it's the same idea.

Even better: some processors and digital ICs have the pullup resistor built into the chip, meaning one less part for your design. The Atmel 328 for instance has the feature, available through programming (for arduino sketch, here; syntax is something like 


pinMode(2, INPUT_PULLUP)









for C and Atmel 328's registers code is like this: 


DDRC = 0;
PORTC = (1 << 5)


......see the tutorial here.


The final idea:

"Push Pull"

This is where a pin on the MCU can source or sink current....not endless amounts, so we must limit the current with resistors as needed and in general design our loads and current sources with some forethought, but for applications where you want to source and sink relatively small amounts of current it's a useful feature.

If more push/pull current is needed, you'd need external components--say, driving a solenoid.  

With all these terms in mind I can now better understand IC datasheets. 

Of course there are a lot of other web pages about all of this--here is a good summary....another good summary page including C programming examples for AVR 328 is here.  

All these concepts will come up again in future posts.

Logisim Evolution: Amazing Digital Simulator!

I was eating breakfast and watching youtube geek videos about GPIO pins and came across this:

https://www.youtube.com/watch?v=gYmDpcV0X7k

The vid above is a tutorial for this incredible free sim: LogiSim Evolution. Wow!  

I probably would have never heard about LogiSim Evolution unless I was always watching CuriousMarc--finding this app alone makes it worthwhile watching a hours of his guys practicing digital kung fu.....I never miss a CuriousMarc vid. I really enjoy how CuriousMarc, the righto.com guy, Ken, and the rest of the CM crew, show off their jaw dropping digital engineering skills, full Eddie Van Halen style, it's a great channel.  

I went through the tutorial and then used Logisim Evolution to better understand something very basic that never made a lot of sense to me: flip flops.

   


In about 5 minutes I wrote up simple sims for JK, T and D flip flops. Now I think I understand them a bit better. Of course there is more to understanding this corner of digital electronics, and I could have spent hours watching vids on each (Ben Eaters JK vid, great as usual, is here) and LogiSim Evolution makes it that much faster to get started.

Oh yes--LogiSim Evolution is free!  Free? Are you kidding me? Update: you can get my Logisim's-- few CMOS chips and other logic newbie tidbits on Github, here)

The obvious question: why play video games when you could be messing around with gates?

That's it for now--all typing, no breathing fumes. Back to the bench. See ya next time.



No comments:

Post a Comment

Anything to Clock Subcircuit

Readers:  If you want to build the project featured in today's post, please go to  PCBWAY's  Community pages --a gerber ready to dow...