|
STLink-V2ST Microelectronics
|
|
|
KiCADKicad
|
|
|
Soldering iron |
Logic Gates Demo
Introduction
I recently started working as a teacher and now I teach the very basics of computer science to young students. I try to keep them entertained during my lesson, to fuel their interest. Next semester I will teach them logic gates and I would love to show the circuits and their behaviour.
These are the "must have" requirements for my idea:
- The circuit boards must be shaped as the symbols for the most common logic gates (and, or, not, nand, nor...)
- They must have LEDs showing the status of all their inputs and outputs
- They must be able to be connected to one another via alligator clips
- Every circuit must be configurable
Some "Nice to have" features:
- The logic gates could be connected to a computer system, for a software implementation of more advanced functions
Schematic
I decided to use a microcontroller as a configurable logic gate, the STM8S003F3P is a good cost-sensitive solution. I added two connectors: one for programming the mcu, the other for power supply and the optional serial communication. Then three inputs (with pull-down resistors), the output, a couple of bypass capacitors and a bunch of LEDs. That's it. All the extra pins are connected to GND through open solder-jumpers. This will allow me to flash all the MCUs with the same code and set the configuration. There is no need for pull-up resistors because the STM8 pins can activate the weak pull-up functionality via software.
Layout
I routed all the tracks and placed some naked copper areas at the inputs and output. I drew all the shapes of the logic gates' symbols on a separate layer, so that the input and output copper areas are always accessible via alligator clips.
I put all the SMD parts on the bottom side and left the top side with only graphics and LEDs.
Cutting
The extra layer is meant to be printed out on paper and serve as a guide for cutting some thicker cardboard. Choose the logic gate you need, set the right solder-jumpers on the board, glue the printed copy to some cardboard and use scissors to cut the right shape. If your work is accurate enough, the cardboard cover should stick to the PCB thanks to the LEDs. You can always glue them together though.
Software
The software just reads the status of the solder-jumpers at reset and implements the corresponding logic gate. Then it continuously polls the inputs, computes the output and sets the LEDs.
I used SDCC to compile it (downloadable for free from the Internet) and STVP to flash the boards. I used the STLink-V2 as a programmer (which can be bought online for a few bucks), connected with four jumper cables and some 90 degrees bent header connectors to make contact with the pads on the PCB for a few seconds.
Cables
You will need some cables with JST female connector. I had a few of them laying around, I'll connect all of them in parallel and plug my bench power supply at 3.3V. A single gate will draw about 15mA with all the LEDs turned on.
That's it!
Now you have a functional educational tool to teach logic networks. I think I'm going to use some suction cups to stick my gates to the blackboard so that all of my students can see them in action. I'm not allowed to take pictures at school but I let you imagine the effect.
Have a nice day building stuff!
Martino
uint8_t A,B,C,OUT,CONFIG, prevC;
void setup(){
PA_DDR = 0x0A; //PA1, PA3 OUTPUT
PB_DDR = 0xFF; //PB OUTPUT
PC_DDR = 0; //PC INPUT
PD_DDR = 0; //PD INPUT
PA_CR1 = 0x02; //OUT PUSH-PULL
PC_CR1 = 0xC0; //C6,C7 PULL-UP
PD_CR1 = 0x0C; //D2,D3 PULL-UP
for (int z=0; z<10000; z++){}
}
void main(){
setup();
//Read configuration (solder-jumpers)
CONFIG = 0;
CONFIG += ((PC_IDR & (1<<6))>0);
CONFIG += (((PC_IDR & (1<<7))>0) << 1);
CONFIG += (((PD_IDR & (1<<2))>0) << 2);
CONFIG += (((PD_IDR & (1<<3))>0) << 3);
while(1){
//Poll INPUTs
A = PC_IDR & (1<<3);
B = PC_IDR & (1<<4);
C = PC_IDR & (1<<5);
//Compute OUTPUT according to configuration
switch (CONFIG){
case 15: //BUFFER
OUT = B;
break;
case 14: //NOT
OUT = !B;
break;
case 13: //OR
OUT = A || C;
break;
case 12: //NOR
OUT = !(A||C);
break;
case 11: //AND
OUT = A && C;
break;
case 10: //NAND
OUT = !(A && C);
break;
case 9: //XOR
OUT = (A!=0) ^ (C!=0);
break;
case 8: //XNOR
OUT = !((A!=0) ^ (C!=0));
break;
case 7: //OR3
OUT = A || B || C;
break;
case 6: //NOR3
OUT = !(A || B || C);
break;
case 5: //AND3
OUT = A && B && C;
break;
case 4: //NAND3
OUT = !(A && B && C);
break;
case 3: //FFSR
if (A) {OUT = 1;}
if (C) {OUT = 0;}
break;
case 2: //FFDQ
if (C!=prevC){
prevC = C;
if (C){OUT = (A>0);}
for (int z=0; z<10000; z++){} //Key bounce
}
break;
default:
break;
}
//Set LEDs and OUTPUT
if (A){PB_ODR &= ~(1<<4);}
else {PB_ODR |= (1<<4);}
if (B){PB_ODR &= ~(1<<5);}
else {PB_ODR |= (1<<5);}
if (C){PA_ODR &= ~(1<<3);}
else {PA_ODR |= (1<<3);}
if (OUT){PA_ODR |= (1<<1);}
else {PA_ODR &= ~(1<<1);}
}
}
Logic Gates Demo
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(0)
- Likes(2)
- Mario Fagiuoli Jan 21,2024
- Martino Schgor Jan 21,2024
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Martino Schgor
-
-
-
-
-
-
X-mas ball, Now with ANIMATED LIGHTS!
106 4 7 -
-
-
-
RC radial engine spark plug heater
29 0 0 -
-