EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: AmmarKurd on October 16, 2022, 10:07:20 am

Title: What is the best way to teach practical logic design?
Post by: AmmarKurd on October 16, 2022, 10:07:20 am
I am about to teach a course on logic design for second-year mechatronics and third-year biomedical engineering, this course will have a practical side as well. I want to know what you think is the best way to learn experimental logic design.

When I studied logic design we used a learning kit with 74 series ICs, do you think this is still a good way to learn, or is it outdated? I appreciate any advice on this topic.

Thanks in advance.
Title: Re: What is the best way to teach practical logic design?
Post by: bostonman on October 16, 2022, 01:33:14 pm
I'd start with the basics what a 0 and 1 represent and why a computer uses them.

After I'd go over basic gates (AND, OR, etc...) along with their associated truth table. Eventually do some basic binary math so you're teaching them the fundamentals of how a computer does math functions.

A simulator would be a good visual too, but after a few lessons first.
Title: Re: What is the best way to teach practical logic design?
Post by: tooki on October 16, 2022, 02:19:35 pm
I’m in my last year of an electronics technician apprenticeship, and when we did logic, we did that all first with truth tables and such, and then in simulation software.
Title: Re: What is the best way to teach practical logic design?
Post by: strawberry on October 16, 2022, 02:49:51 pm
I think it should end with some interesting project otherwise it is just 0/1

ttl cmos gates are outdated for consumer products indeed, because production cost is main and only goal
MCU/CPU is not possible without logic gates
Title: Re: What is the best way to teach practical logic design?
Post by: rstofer on October 16, 2022, 03:11:57 pm
All the usual stuff including gates and the various flops plus the 74181-74182 ALU - the introductory stuff.  Here's a video re: the 74181, there are others.

https://youtu.be/xODcIY1Hg5w (https://youtu.be/xODcIY1Hg5w)

Karnaugh maps are vitally important.

Some brief amount of time on Quine-McCluskey minimization.

https://youtu.be/sKu2Yprsp4Y (https://youtu.be/sKu2Yprsp4Y)

State machines and reduction

https://courses.cs.washington.edu/courses/cse370/09wi/LectureSlides/22-Minimization.pdf (https://courses.cs.washington.edu/courses/cse370/09wi/LectureSlides/22-Minimization.pdf)

Most important: microcoding of FSMs and CPUs

There's a book for this level which ends up building a small 16 bit CPU.  The book starts with gates and flops and winds up with microcoding.
https://www.alibris.com/Introduction-to-Computing-Systems-From-Bits-and-Gates-to-C-C-Beyond-Yale-N-Patt/book/42539098 (https://www.alibris.com/Introduction-to-Computing-Systems-From-Bits-and-Gates-to-C-C-Beyond-Yale-N-Patt/book/42539098)

The problem is, the book is now too expensive!  I have both the 2d and 3d edition and I built the LC3 CPU from the 2d edition.  I believe the 3d edition modifies the CPU to allow byte addressing - LC3b.  It's important to pick either LC3 or LC3b when searching

The appendices are online and they describe the entire machine and much of the implementation.  Google for 'LC3 appendix'
https://people.cs.georgetown.edu/~squier/Teaching/HardwareFundamentals/LC3-trunk/docs/LC3-uArch-PPappendC.pdf (https://people.cs.georgetown.edu/~squier/Teaching/HardwareFundamentals/LC3-trunk/docs/LC3-uArch-PPappendC.pdf)
https://www.jmeiners.com/lc3-vm/supplies/lc3-isa.pdf (https://www.jmeiners.com/lc3-vm/supplies/lc3-isa.pdf)

I don't know how far you can get in one semester.  It would be nice to touch on FPGAs because all of the techniques above are done by the software.  Minimization is a lot less of an issue for the designer because a simple change doesn't require another dozen 74 series chips.  It's almost certain that one-hot state encoding won't be done in TTL for machines with more than a few states.  The state word gets too wide.  Not a problem for an FPGA but difficult in discrete logic.

Don't overlook the possibility of hanging some switches and LEDs on an Arduino and coding up some logic.  Even state machines are easy to implement in C/C++

Title: Re: What is the best way to teach practical logic design?
Post by: AmmarKurd on October 16, 2022, 04:01:16 pm
Thank you all for your valuable feedback, I am more interested in what could be the best practical side of this course, the options I have are:

1 - Simulation-based.
2 - Use 74 series components to build circuits.
3 - Go straight to microcontrollers or maybe Arduino.

I know that practically speaking 74 series is outdated and mostly Microcontrollers, MCUs, and FPGAs are the way to go for a practical design, but what will be the best way to teach an introductory course on logic design?

FPGA might be too advanced for someone learning what a truth table is, what do you think?
Title: Re: What is the best way to teach practical logic design?
Post by: RoGeorge on October 16, 2022, 04:20:17 pm
1. meh, too abstract, do that only if hands-on learning is not possible, or as an alternative to practice (there are many online webpages that can simulate logic circuits, some with nice interactive/live GUI, e.g. https://logic.ly/demo/ )

2. yes, breadboards with switches and LEDs at first, then TTL or CMOS digital chips later, LEDs to visualize the outputs, hands-on is the second best way to consolidate any learning, bridges theory with practice (first best way of learning would be to teach to others the very same thing one is trying to learn, not applicable here)

3. too much unrelated MCU details/bloatware, worst option IMHO
Title: Re: What is the best way to teach practical logic design?
Post by: Fredderic on October 16, 2022, 06:01:47 pm
When I learnt this back in Uni, we spent a semester building most of a 6800-series processor in a simulator.  (I think it was based on the 6802 specifically, but encouraging us to choose our own op-codes was a good way to spot cheating students.)  Something roughly along the lines of:

Starting with assembling an SR-Latch from gates in the simulator, and building it through the various kinds up to a D-Latch, then adding another 3, enough to latch data in, and through to some simulated LED's.  (After that, we were allowed to upgrade our register to 8-bit, using D-Latch components.  Partly to remove unnecessary complexity if we wanted, and partly to catch up struggling students who hadn't gotten theirs to work.)

Then address decoding (again out of logic gates), a small ROM (address decoding into a grid of wires, where we placed diodes to make a 1), followed by a few bytes of RAM (this time address decoding into 8-bit D-Latch components), and manually clocking data between ROM, register, RAM, and through to the LED's.  (We were then allowed to upgrade it all to 8-bit D-Latch components.)

Add a simple ALU and another register, so now we can move bytes of ROM into the registers, through the ALU, store them in RAM, repeat with another operator, then again taking the values we'd just computed and stored in RAM back through the ALU, and presenting the final result on the LED's.  (Basically just add, sub, the logic functions, stuff like that.)

Followed by decode logic that takes a manually entered op-code and drives the control lines for you, for the couple simple instructions to exercise the hardware built so far, then adding instruction and instruction pointer registers, allowing an actual simple linear program to be loaded into the ROM (which was also upgraded to a simulated ROM chip with more room, and so we didn't have to manually place all those diodes to set each bit of ROM individually).

Finally replacing our register RAM with a RAM component, and attaching a simulated terminal output and a keypad input interface with memory-mapped IO, fleshing out the ALU (including the flags register), and the instruction set a bit more (like conditional jumps using those flags), finally culminating in writing a small program that actually does something, on our own 6800 compatible processor design, running our own microcode and decode logic.

In the process, we hit all the things rstofer mentioned, had a working (if simulated) thing out of all that "logic stuff", and gained a very good idea of what was going on within those computer things.  (Arduino wasn't yet a thing, though…)  But I credit that grounding for never having struggled with bit twiddling and several other topics that I find myself having to help a lot of aspiring coders with.

For my particular course, I also did some other parallel subjects that tied in rather well; exploring caching, RISC architectures, and other modern processor ideas, writing a 6800 assembler and emulator pair, and around the middle of our analog electronics subject we were building logic gates out of transistors.  So those of us doing that particular course, ended up being able to write a simple program in assembler, assemble and emulate it on our own hand-written assembler, load the binary output into the ROM of our own simulated processor (had to adjust one or the other, since though we were making real 68xx instructions, we weren't actually told that, and were encouraged to choose our own opcodes), and see the output on the simulated terminal device (and that it matches what our simulator produced for the same program), knowing it's all built from gates, and that we know how to build those gates in transistors.  And with the ASIC subject later on I'd have been able to translated it all the way into silicon, too.
Title: Re: What is the best way to teach practical logic design?
Post by: Benta on October 16, 2022, 07:02:08 pm
I think most posters missed the point "second-year mechatronics" and went straight to their hobby horse.
We're talking mechanics, hydraulics, electrics, electronics and diagnostics here. In the second year.
The only poster I can agree with is @bostonman.

The knee-jerk reaction "throw an Arduino at it" I don't understand at all. There are plenty of designs being done with 74HC, 74AHC, 74AC etc.
Title: Re: What is the best way to teach practical logic design?
Post by: tooki on October 16, 2022, 07:33:41 pm
I know that practically speaking 74 series is outdated and mostly Microcontrollers, MCUs, and FPGAs are the way to go for a practical design,
74 series is far from dead. TI even introduced a new 74 logic family (HCS) in 2019!

What we certainly no longer see are large circuits made of discrete logic. But they’re still widely used as “glue” and as level shifters, etc. What have become quite popular are single-gate devices in small packages like SOT-23 and smaller. Perfect when you need a quick inverter or to AND or OR a few lines.
Title: Re: What is the best way to teach practical logic design?
Post by: exmadscientist on October 16, 2022, 08:24:23 pm
I have taught this exact type of student before and it is not so easy. These are not EE or CS people who need to know this stuff to understand their own jobs. These are people who will be either using it as an end to achieve entirely separate goals or who will be doing archaeology on an ancient device to fix it/repurpose it/get one more publication out of it.

74 series MSI etc is dead and you can and should forget about it, at least at this level.

In my opinion the best flow is:
IMO your job is done if they can, after the course, identify a microcontroller on a schematic (in detail!), identify and be comfortable with the various glue logic that keeps it happy, and can write some useful code for it.
Title: Re: What is the best way to teach practical logic design?
Post by: JustMeHere on October 16, 2022, 09:22:50 pm
The computer game Robot Odyssey.  There's a Java prot that runs best on modern hardware.
Title: Re: What is the best way to teach practical logic design?
Post by: Benta on October 16, 2022, 10:52:32 pm
The computer game Robot Odyssey.  There's a Java prot that runs best on modern hardware.
???
Did you by mistake post on the wrong forum? You can still "Remove".

Title: Re: What is the best way to teach practical logic design?
Post by: MathWizard on October 17, 2022, 01:43:47 am
Lately I made a astable multi-vibrator clock, an SR-latch, iirc a JK-latch, and a few other things from pullup-resistor/open collector logic, all 10k's and 100k's except a few 1k's. Combined with a binary counter / period doubler,  I did a few things like trigger of a number, so you can time or count up to stuff. That was pretty cool.

Then in LTSpice w/ transistors, I made a calculator that could add/subtract +/- numbers. And multiply 3d*3d before I gave up.

And wow does the transistor count start going up.

I bought a 50x10LED blocks for future breadboard computer type projects. And a pile of BC547/557's. Now if only common logic chips were a lot cheaper.
Title: Re: What is the best way to teach practical logic design?
Post by: MrAl on October 17, 2022, 09:58:28 am
In a camel back word, BooleanAlgebra.
Title: Re: What is the best way to teach practical logic design?
Post by: rstofer on October 17, 2022, 01:10:15 pm
In terms of mechatronics, the topics would include microcontrollers and IO peripherals (UART, I2C, SPI, GPIO, PWM) both in terms of the hardware and software.  This would include time with the datasheets and other documentation.

Then the external devices such as ultrasonic distance sensors, H-bridges, stepper drivers and any other sensors that seem relevant.

Writing code for all of this in C/C++, microPython (where applicable) and this could apply to the Arduino, Raspberry Pi and now the Raspberry Pi Pico.  The Pi Pico has the advantage of being programmable with C/C++ and microPython and is quite inexpensive.  The Pi Pico W adds WiFi and it particularly easy to use.

I would be all over the computer vision projects with the Pi Pico W - Google search 'pi pico computer vision'
https://mjrobot.org/2021/03/12/tinyml-motion-recognition-using-raspberry-pi-pico/

Mechatronics is a vast field with plenty of real-world industrial applications.
Title: Re: What is the best way to teach practical logic design?
Post by: rstofer on October 17, 2022, 02:55:04 pm
Thank you all for your valuable feedback, I am more interested in what could be the best practical side of this course, the options I have are:

1 - Simulation-based.
2 - Use 74 series components to build circuits.
3 - Go straight to microcontrollers or maybe Arduino.

I know that practically speaking 74 series is outdated and mostly Microcontrollers, MCUs, and FPGAs are the way to go for a practical design, but what will be the best way to teach an introductory course on logic design?

FPGA might be too advanced for someone learning what a truth table is, what do you think?
Other than the constraints file, the rest of FPGA programming flows nicely from logic expressions and FSM state tables.  There are just a few constructs to understand (selector, multiplexor, logic expressions and FSMs) and everything builds from there.   Either of these boards would be excellent for a logic design course with an FPGA
https://digilent.com/shop/basys-3-artix-7-fpga-trainer-board-recommended-for-introductory-users/
https://digilent.com/shop/nexys-a7-fpga-trainer-board-recommended-for-ece-curriculum/      <-- my favorite

There are many other boards available at a MUCH lower cost.  The thing I look for is buttons, LEDs, Displays and switches.  It is quite simple to demonstrate logic expressions on an FPGA.  In fact, given 16 switches and 16 LEDs, several expressions could be generated at the same time.

I suppose the student could write code for a less than optimal expression, reduce it with a Karnaugh map and add code for the optimized expression and compare the outputs on LEDs.  That's still faster than wiring up a bunch of 74xx gates.  And once they get to flops, the FPGA shines.  By definition, FPGAs use D-flops and the student is left to figure out how to create a J-K flop.  There is also a library with J-K flops.  Unclocked latches are highly discouraged.

The cool thing about FPGAs is the small effort required to add a 32 bit register compared to the amount of wire-wrapping required for 7474 devices.  One line of code and it exists, another few lines of code to clock it and set values.  I love FPGAs!

The key topic is combinatorial logic versus sequential logic.  Once the student truly understands FSMs, they are on their way to building just about anything with an FPGA.  That's why I like the LC3 project, the state transition diagram is given, just code up the state actions and the CPU is just about done.  Yes, there are several other components to code up but they are pretty easy.

I would hand out the constraints file and tell the students to name their HDL signals to match.  Or, they can try to figure it out for themselves.

The problem with FPGAs is cost and availability.  It is possible to write state machines in any computer language so there is no reason not to use the Pi Pico W with some switches and LEDs and the logic in microPython.  Obviously, the C 'switch' statement is key.

Here are the first few states for LC3 and if you look in Appendix C you will see how it matches
Code: [Select]
        case State is
            when  0     =>  -- Branch Instruction
                            if BEN = '1' then
                                NextState   <= 22;  -- branch is taken
                            else
                                NextState   <= 18;  -- branch not taken   
                            end if;                             
            when  1     =>  -- ADD Instruction
                            if Immediate = '1' then
                                SR2select <= Sext5sel;
                            else
                                SR2select <= SR2outSel;
                            end if;
                            ALUop           <= ALUadd;
                            GateBusSelect   <= GateALU;
                            LD_Reg          <= '1';
                            LD_CC           <= '1';
                            NextState       <= 18;                           
            when  2     =>  -- LD Instruction
                            Addr1Select     <= Addr1PC;
                            Addr2Select     <= Addr2Sext9;
                            MARselect       <= MARadder;
                            GateBusSelect   <= GateMARmux;
                            LD_MAR          <= '1';
                            NextState       <= 25;
            when  3     =>  -- ST Instruction
                            Addr1Select     <= Addr1PC;
                            Addr2Select     <= Addr2Sext9;
                            MARselect       <= MARadder;
                            GateBusSelect   <= GateMARmux;
                            LD_MAR          <= '1';
                            NextState       <= 23;
            when  4     =>  -- JSR Instruction
                            if IR(11) = '1' then
                                NextState   <= 21;
                            else
                                NextState   <= 20;
                            end if;
How easy is that?  Just follow along from the state transition diagram.  Figure C-2
https://people.cs.georgetown.edu/~squier/Teaching/HardwareFundamentals/LC3-trunk/docs/LC3-uArch-PPappendC.pdf

One key point:  Every signal needs to be defined in every state or latches will be generated.  As a result, there are a LOT of default assignment statements in the process:
Code: [Select]
process(State, BEN, IR,MemReady, Immediate, PSR, Interrupt)
    begin
        -- set default values for all signals
        GateBusSelect   <= GatePC;
        MIOenable       <= '0';
        LD_MAR          <= '0';
        ...
Title: Re: What is the best way to teach practical logic design?
Post by: strawberry on October 17, 2022, 03:47:17 pm
Arduino GPIO shematic . easier to understand what this peripheral really do
Arduino language is for kids to begin some hardware programming
Title: Re: What is the best way to teach practical logic design?
Post by: fourfathom on October 17, 2022, 04:45:31 pm
What happened to designing a simple traffic-light controller with logic gates (probably use the HC74xx or 74LVC series or similar)?  This gets you Boolean logic, Karnaugh maps, and state machines, as well as hands-on experience.  You know, the basics.

Trying to design an ALU isn't perhaps the best task for an introductory course...

After this, you might introduce Verilog/VHDL. and perhaps map that traffic-light design and show how to simulate.
Title: Re: What is the best way to teach practical logic design?
Post by: strawberry on October 17, 2022, 04:50:35 pm
ALU can be a calculator