MOV AX, BLOG

Electronics, Photography, Gadgets

Tag: electronics (page 1 of 2)

Building a Full Adder Using NPN Transistors

Building upon the last two posts where I showed how to build NAND, NOR, AND, OR, NOT and XOR gates using NPN transistors, this post will show how these gates can be used to build a full adder. A full adder is one of the circuits used in an Arithmetic and Logic Unit (ALU) which a central component in a microprocessor. The screenshot below shows the full adder circuit using combinational logic running in Circuit Simulator.

Full Adder Circuit Using Combinational Logic

The next screen shot shows the same full adder circuit built using NPN transistors.

Full Adder Circuit Using NPN Transistors

As always, the code for the circuit can be found here. Just copy and import the code into the free Java Circuit Simulator to get a feeling for the circuit.

Building An XOR Gate Using NPN Transistors

Following on from my last post on building logic gates from NPN transistors, I’ve now designed the XOR gate needed to build our Full Adder. As can be seen in the screen shot below, the top circuit shows an XOR gate built using 4 NAND gates and the second circuit shows the same XOR circuit built using 8 NPN transistors.

XOR Gate Built Using NPN Transistors

As Always, copy and paste the following code into the free Java Circuit Simulator to get a feeling for the design.

$ 1 5.0E-6 1.500424758475255 50 5.0 50
151 432 160 544 160 0 2 5.0
151 544 112 656 112 0 2 5.0
151 544 208 656 208 0 2 0.0
w 544 160 544 192 0
w 544 160 544 128 0
151 656 160 768 160 0 2 5.0
w 656 112 656 144 0
w 656 176 656 208 0
w 432 96 432 144 0
w 432 96 544 96 0
w 432 176 432 224 0
w 432 224 544 224 0
M 768 160 816 160 0 2.5
L 432 96 384 96 0 0 false 5.0 0.0
L 432 224 384 224 0 1 false 5.0 0.0
x 302 51 840 57 0 24 XOR Using Combinational Logic (NAND Gates)
x 284 341 866 347 0 24 XOR Using Combinational Logic (NPN Transistors)
R 320 576 288 576 0 0 40.0 5.0 0.0 0.0 0.5
R 320 624 288 624 0 0 40.0 5.0 0.0 0.0 0.5
t 448 576 480 576 0 1 -4.769244679759966 0.09853954879251582 100.0
t 448 624 480 624 0 1 0.5721119236721417 0.572360682090304 100.0
w 480 592 480 608 0
r 400 576 448 576 0 10000.0
r 400 624 448 624 0 10000.0
s 320 576 368 576 0 1 false
s 320 624 368 624 0 0 false
r 480 512 480 560 0 100.0
R 480 512 448 512 0 0 40.0 5.0 0.0 0.0 0.5
g 480 640 480 656 0
g 368 672 368 688 0
r 368 624 368 672 0 10000.0
w 480 560 512 560 0
w 656 448 688 448 0
r 576 512 576 560 0 10000.0
g 576 560 576 576 0
g 656 528 656 544 0
R 656 400 624 400 0 0 40.0 5.0 0.0 0.0 0.5
r 656 400 656 448 0 100.0
r 576 512 624 512 0 10000.0
r 576 464 624 464 0 10000.0
w 656 480 656 496 0
t 624 512 656 512 0 1 0.5713598382462943 0.5716085966689409 100.0
t 624 464 656 464 0 1 -4.875710385258664 0.09853954878803152 100.0
t 624 688 656 688 0 1 -0.11894285435755281 0.6683177341910094 100.0
t 624 736 656 736 0 1 0.5011262498555432 0.6685976279719069 100.0
w 656 704 656 720 0
r 576 688 624 688 0 10000.0
r 576 736 624 736 0 10000.0
r 656 624 656 672 0 100.0
R 656 624 624 624 0 0 40.0 5.0 0.0 0.0 0.5
g 656 752 656 768 0
g 576 784 576 800 0
r 576 736 576 784 0 10000.0
w 656 672 688 672 0
w 512 560 528 560 0
w 528 560 528 512 0
w 528 512 576 512 0
w 528 560 528 688 0
w 528 688 576 688 0
t 784 576 816 576 0 1 0.554942286102126 0.6083225786232598 100.0
t 784 624 816 624 0 1 -1.2089972951264762 0.607048116653794 100.0
w 816 592 816 608 0
r 736 576 784 576 0 10000.0
r 736 624 784 624 0 10000.0
r 816 512 816 560 0 100.0
R 816 512 784 512 0 0 40.0 5.0 0.0 0.0 0.5
g 816 640 816 656 0
g 736 672 736 688 0
r 736 624 736 672 0 10000.0
w 688 448 688 576 0
w 688 576 736 576 0
w 688 672 688 624 0
w 688 624 736 624 0
162 864 560 864 640 1 2.1024259 1.0 0.0 0.0
w 816 560 864 560 0
w 864 640 816 640 0
w 400 464 400 576 0
w 400 464 576 464 0
w 400 624 400 736 0
w 576 736 400 736 0
w 368 624 400 624 0
w 368 576 400 576 0

Building Logic Gates Using Transistors

Moving on from the NOT gate we built using a single transistor and described in a previous post, I decided to show my son how to build more complex logic gates and ultimately much more complex combinational logic circuits using transistors; which is the basis of all modern computers including the one you are using right now to read this blog. The video attached below from Make is a great overview to the transistor, but I would also suggest performing some simple experiments with NPN transistors before moving onto combinational logic.

[youtube=http://www.youtube.com/watch?v=-td7YT-Pums&feature=related]

The circuits below for the gates NAND, NOR, AND, OR and NOT have been designed using NPN transistors and these circuits will be the basis of the Full Adder which we intend to build using them; please note that these circuits may not be the most efficient as I designed them just for fun. In the screen shot you will also see the symbol for each of these gates and if you are unfamiliar with them and their truth tables, I suggest taking a look at the wikipedia article for each.

NAND, NOR, AND, OR and NOT Gates Using NPN Transistors

In order to get a feeling for how they work, I would recommend getting a copy of the excellent and free Java Circuit simulator and importing the following code into the program.

$ 1 5.0E-6 10.20027730826997 50 5.0 50
t 304 176 352 176 0 1 0.5607262480623159 0.6439221594808273 100.0
t 304 224 352 224 0 1 0.5610808902467164 0.6446279101012331 100.0
w 352 192 352 208 0
g 352 240 352 272 0
r 304 224 240 224 0 10000.0
r 304 176 240 176 0 10000.0
R 176 176 128 176 0 0 40.0 5.0 0.0 0.0 0.5
s 176 176 240 176 0 0 false
s 176 224 240 224 0 0 false
w 176 224 176 176 0
w 176 176 176 128 0
w 176 112 352 112 0
162 352 160 400 160 1 2.1024259 1.0 0.0 0.0
w 400 160 400 240 0
r 352 160 352 112 0 330.0
w 176 112 176 128 0
x 242 86 313 92 0 24 NAND
t 560 720 592 720 0 1 -1.7015314369328909 0.0985395491791375 100.0
R 416 720 368 720 0 0 40.0 5.0 0.0 0.0 0.5
s 416 720 480 720 0 1 false
r 480 720 544 720 0 10000.0
w 544 720 560 720 0
r 592 704 592 656 0 330.0
w 592 656 416 656 0
162 592 704 640 704 1 2.1024259 1.0 0.0 0.0
g 592 736 592 768 0
x 489 626 541 632 0 24 NOT
w 416 656 416 720 0
w 640 704 640 736 0
w 176 416 176 432 0
r 352 464 352 416 0 330.0
w 176 416 352 416 0
w 176 480 176 432 0
w 176 528 176 480 0
s 176 528 240 528 0 0 false
s 176 480 240 480 0 0 false
R 176 480 128 480 0 0 40.0 5.0 0.0 0.0 0.5
r 304 480 240 480 0 10000.0
r 304 528 240 528 0 10000.0
g 352 544 352 576 0
w 352 496 352 512 0
t 304 528 352 528 0 1 0.5610808902472575 0.6446279101002914 100.0
t 304 480 352 480 0 1 0.5607262480628803 0.6439221594798585 100.0
w 448 448 448 480 0
162 400 448 448 448 1 2.1024259 1.0 0.0 0.0
t 352 464 384 464 0 1 -1.6333280543612416 0.1667429312700123 100.0
w 592 736 640 736 0
w 352 240 400 240 0
w 400 480 448 480 0
r 352 416 400 416 0 330.0
w 400 416 400 448 0
w 384 448 400 448 0
w 384 480 400 480 0
x 255 369 308 375 0 24 AND
w 832 240 880 240 0
x 685 85 737 91 0 24 NOR
w 608 112 608 128 0
r 784 160 784 112 0 330.0
w 880 160 880 240 0
162 832 160 880 160 1 2.1024259 1.0 0.0 0.0
w 608 112 784 112 0
w 608 176 608 128 0
w 608 224 608 176 0
s 608 224 672 224 0 0 false
s 608 176 672 176 0 1 false
R 608 176 560 176 0 0 40.0 5.0 0.0 0.0 0.5
r 736 176 672 176 0 10000.0
r 736 224 672 224 0 10000.0
g 784 240 784 272 0
t 736 224 784 224 0 1 0.561235418839239 0.6443539216856129 100.0
t 736 176 784 176 0 1 -0.01047151862990496 0.07264698421646892 100.0
w 784 208 800 208 0
w 784 192 832 192 0
w 784 160 800 160 0
w 800 160 800 208 0
w 832 192 832 240 0
w 832 240 784 240 0
w 800 160 832 160 0
w 384 480 384 544 0
w 384 544 352 544 0
w 800 464 832 464 0
w 832 544 784 544 0
w 832 496 832 544 0
w 800 464 800 512 0
w 784 464 800 464 0
w 784 496 832 496 0
w 784 512 800 512 0
t 736 480 784 480 0 1 -0.010470026008861447 0.07264847683763566 100.0
t 736 528 784 528 0 1 0.561235418839193 0.6443539216856902 100.0
g 784 544 784 576 0
r 736 528 672 528 0 10000.0
r 736 480 672 480 0 10000.0
R 608 480 560 480 0 0 40.0 5.0 0.0 0.0 0.5
s 608 480 672 480 0 1 false
s 608 528 672 528 0 0 false
w 608 528 608 480 0
w 608 480 608 432 0
w 608 416 784 416 0
r 784 464 784 416 0 330.0
w 608 416 608 432 0
x 696 372 730 378 0 24 OR
w 864 544 832 544 0
w 864 480 864 544 0
w 864 480 880 480 0
w 864 448 880 448 0
w 880 416 880 448 0
r 832 416 880 416 0 330.0
w 880 480 928 480 0
t 832 464 864 464 0 1 -1.7169524832810044 0.0831185028464971 100.0
162 880 448 928 448 1 2.1024259 1.0 0.0 0.0
w 928 448 928 480 0
w 784 416 832 416 0
151 336 64 432 64 0 2 5.0
153 768 64 864 64 0 2 5.0
150 336 352 432 352 0 2 0.0
152 768 352 864 352 0 2 0.0
I 560 608 656 608 0 0.5

First Project Using The PICAXE-08 Proto Board Kit

After building the first prototype of our timer device and then making preparations to use the PICAXE 08M and save space by using a single NPN transistor as a NOT gate, we have finally completed our project using the PICAXE-08 Proto Board Kit. As usual, I purchased the Proto Board and PICAXE chips from those reliable folks at techsupplies in the U.K. For around 5 Euros, the  PICAXE-08 Proto Board Kit with a PICAXE-08M microcontroller is a real bargain. It has almost everything you need to get going – the only extras you will require are a USB cable for programming the PICAXE and a battery box for holding 3 AA batteries to supply the circuit with 4.5v. I found the size of the prototyping area on the board to be ample for simple projects. Please note that the kit comes in component form, shown in the picture below, and has to be assembled using a soldering iron and a little bit of time – it is not complicated.

PICAXE-08 Proto Board kit

Moving the timer to the PICAXE-08M from the PICAXE-20M prototype was relatively straight forward. The new circuit uses pins 0, 1 and 2 to power the “minute/seconds LEDs” while pin 3, which is an input pin only, is used to select the device’s function (eggs or teeth) and pin 4 is used to power the piezo buzzer. On the prototyping area I placed the resistors to drive the LEDs and a voltage regulator to power the circuit from a 9v battery. In our circuit pin 3 is also pulled down to 0v using a 10k resistor. Below is the code for the device.

symbol counter = b0
symbol teeth = b1
symbol eggs = b2
symbol loopCounter = b3
init:
pause 200
loopCounter = 0
if pin3 = 1 then
teeth = 1
eggs = 0
else
eggs = 1
teeth = 0
endif
start:
for counter = 1 to 60
low 0
pause 500
high 0
pause 500
next
for counter = 1 to 60
low 1
pause 500
high 1
pause 500
next
for counter = 1 to 60
low 2
pause 500
high 2
if counter > 55 and teeth = 1 then
high 4
elseif counter > 55 and eggs = 1 and loopCounter = 1 then
high 4
endif
pause 500
low 4
next
if eggs = 1 and loopCounter = 0 then
loopCounter = 1
goto start
endif
end:
high 4
pause 1000
low 4

Luckily, as mentioned previously, we had prepared to save space in the enclosure – which is good because the space available turned out to be even smaller than I thought. The wiring to the LEDs and switches added quite a bit of bulk and as a result the whole circuit plus battery only just squeezes in. The image below helps to illustrate just how much bulk the wiring added to the internals of the device.

Unexpected Added Bulk Through Wiring

After many hours of work, the device is now completed and we used it tonight to time the brushing of our teeth. Tomorrow morning, we’ll use it for the first time to time our soft boiled eggs ;-).

The Completed Eggs-Teeth Timer

Building A NOT Gate With A Single NPN Transistor

Moving the timer device described in a previous post from the PICAXE 20M to the 08M in order to save space has brought with it the problem that one has a limited number of out pins at one’s disposal. In particular, when the user selects the timer function of the device, i.e. teeth or eggs, we want to indicate the selected function via two LEDs. In the 20M version of the circuit we could wastefully use two output pins (out4 and out5) for this purpose but with the 08M a little thought is required. One option would be to use a NOT gate to inverse the output of the selected function thus saving a pin. However given the space limits, using a NOT chip for just one NOT gate takes up too much room. The images below give you a good impression of how tight the space is inside the selected enclosure.

Short On Enclosure Space

As can be seen in the image above, the enclosure is too small for the PICAXE-08 Proto Board with 3 AA cells which provides the required 4.5v to power the circuit. To cut down on space, we have used a 9v battery but this requires a 5v voltage regulator to be built onto the PICAXE-08 Proto Board.

Using a 9v Battery to Save Space

Given the now limited space on the Proto Board, adding a 14 pin NOT chip for one gate is pretty wasteful. In comparison a single NPN transistor has just three pins for the base, the collector and the emitter. As a side note, the transistor is a truly incredible device and it is viewed as one of the most important inventions of the 20th century which is why it’s inventors (Shockley, Bardeen and Brattain) were awarded the Nobel Prize for Physics in 1956. I recommend taking a look at it in more detail. Below is an image of a CD4069 six gate NOT chip compared to a C547B NPN transistor which we will be using in this post to create a single NOT gate.

Saving Space By Using a Single Transistor

The construction of a NOT gate from the NPN transistor is pretty straight forward as one can see in the circuit diagram below. The input +5v is connected to a switch and then a 10k resistor to the base, the collector is also connected to +5v via a 330 ohm resistor. The output of the gate is connected to the collector and will be high when the switch is open and low when the switch is closed. Using this circuit saves a substantial amount of space on our Proto Board – as well as being an excellent way to introduce the transistor to my son.

NOT Gate Using a Single NPN Transistor

As always, the code for the circuit is listed below – simply copy and import it into Circuit Simulator to give it a try.

$ 1 5.0E-6 10.20027730826997 50 5.0 50
t 624 432 688 432 0 1 -1.7015314360087241 0.09853955010330427 100.0
r 544 432 624 432 0 10000.0
s 480 432 544 432 0 1 false
R 480 432 432 432 0 0 40.0 5.0 0.0 0.0 0.5
w 688 320 496 320 0
w 480 320 480 432 0
w 480 320 496 320 0
g 688 480 688 512 0
r 688 320 688 416 0 330.0
w 688 416 768 416 0
162 768 416 768 480 1 2.1024259 1.0 0.0 0.0
w 688 448 688 480 0
w 688 480 768 480 0

Building Something Useful With Counters

After building a 4bit counter using JK flip-flops last week, my son and I thought about what we could build using counters which would be of use around the house. We thought of two things – a 3 minute timer for timing how long you have brushed your teeth and a 6 minute timer for soft boiled eggs. The 9bit counter circuit required to build a 6 minute timer using JK flip-flops would require 5 chips plus a 555 timer set to “tick” once per second and quite a bit of discrete logic to turn on and blink the LEDs at the correct times. Knowing how much work this would involve to design it and then build it using strip board, I turned to the trusty PICAXE microcontroller to simplify things.

The advantage of using a microcontroller is that it is pretty simple to build what would be complex using discrete logic and therefore we decided to build an egg-teeth timer, i.e. both of the timers in one device. We used a PICAXE 20M to build the first prototype with output pins 0, 1 and 2 connected to 330 ohm resistors and then yellow LEDs. Input Pin5 is used to select the function of the device, i.e. eggs or teeth with output pins 4 and 5 connected to 330 ohm resistors and then green LEDs to indicate which function has been selected. A piezo buzzer is connected to output pin 3 to give an audible signal once the counter has reached either 3 or 6 minutes depending on the selected function. The code for the device is listed below:

symbol counter = b0
symbol teeth = b1
symbol eggs = b2
symbol loopCounter = b3
init:
pause 200
loopCounter = 0
if pin5 = 1 then
teeth = 1
eggs = 0
high 4
else
eggs = 1
teeth = 0
high 5
endif
start:
for counter = 1 to 60
low 0
pause 500
high 0
pause 500
next
for counter = 1 to 60
low 1
pause 500
high 1
pause 500
next
for counter = 1 to 60
low 2
pause 500
high 2
if counter > 55 and teeth = 1 then
high 3
elseif counter > 55 and eggs = 1 and loopCounter = 1 then
high 3
endif
pause 500
low 3
next
if eggs = 1 and loopCounter = 0 then
loopCounter = 1
goto start
endif
end:
high 3
pause 1000
low 3

Having built the first prototype, the next step was to build an enclosure for the device, below is an image of the prototype and the device’s enclosure.

The Eggs, Teeth Timer Prototype and Enclosure

The next step is to move the prototype into the enclosure, but before doing so we are going to redesign the device around a PICAXE-08 Proto Board and a PICAXE-08M microcontroller in an effort to reduce the space required in the enclosure and to use a “simple” microcontroller more appropriate to the devices’ functionality.

Building a 4bit Counter Using JK Flip-Flops

This weekend’s electronics project with my son was to build a 4bit counter using JK flip-flops. Before implementing the circuit in hardware, I first explained the binary system and we then designed the counter using the free Circuit Simulator which I described in a previous post. Interestingly, he was amazed by the fact that adding just one more bit doubles the size of the counter – exponential growth is not intuitive ;-). The counter circuit, which chains together the flip-flops can be seen below: 

4bit Counter Using JK Flip-Flops

One important feature of the design is that we tie both J and K to +5v which turns the JK flip-flop into a T or Toggle flip-flop. Below is the code for the circuit. Copy and import the code into Circuit Simulator to get a better feeling of how the counter works – just press the switch to activate the next “tick” of the counter. 

$ 1 5.0E-6 10.20027730826997 50 5.0 50
162 496 272 496 208 1 2.1024259 1.0 0.0 0.0
g 320 208 320 176 0
w 320 208 496 208 0
r 496 272 496 352 0 330.0
r 544 272 544 352 0 330.0
162 544 272 544 208 1 2.1024259 1.0 0.0 0.0
r 592 272 592 352 0 330.0
162 592 272 592 208 1 2.1024259 1.0 0.0 0.0
r 640 272 640 352 0 330.0
162 640 272 640 208 1 2.1024259 1.0 0.0 0.0
w 496 208 544 208 0
w 544 208 592 208 0
w 592 208 640 208 0
156 368 464 432 464 0 5.0
R 288 432 256 432 0 0 40.0 5.0 0.0 0.0 0.5
w 288 432 288 464 0
w 288 464 368 464 0
w 288 464 288 528 0
w 288 528 368 528 0
s 288 432 352 432 0 1 true
w 368 496 352 496 0
w 352 496 352 432 0
156 528 464 560 464 0 0.0
w 528 464 512 464 0
w 512 464 512 528 0
w 512 528 528 528 0
w 512 528 512 576 0
w 512 576 288 576 0
w 288 576 288 528 0
w 464 464 480 464 0
w 480 496 528 496 0
w 640 352 640 416 0
w 640 416 464 416 0
w 624 464 624 384 0
w 624 384 624 352 0
w 624 352 592 352 0
156 704 464 736 464 0 5.0
w 512 576 672 576 0
w 688 528 688 576 0
w 672 576 688 576 0
w 688 528 704 528 0
w 704 464 688 464 0
w 688 464 688 528 0
w 624 464 640 464 0
w 640 464 640 496 0
w 640 496 704 496 0
w 800 464 800 368 0
w 800 368 544 368 0
w 544 368 544 352 0
156 864 464 896 464 0 5.0
w 688 576 864 576 0
w 864 576 864 528 0
w 864 528 848 528 0
w 848 528 848 480 0
w 848 480 848 464 0
w 848 464 864 464 0
w 800 464 816 464 0
w 816 464 816 496 0
w 816 496 864 496 0
w 496 352 496 384 0
w 496 384 960 384 0
w 960 464 960 384 0
w 464 416 464 464 0
w 480 464 480 496 0

The next step was to build the circuit using real JK flip-flops. We used dual HEF 4027BP JK flip-flops from NXP Semiconductors, 4 LEDs, 4 330 ohm resistors, a 10k resistor and a push button. Please note that these flip-flops are triggered on the rising edge and therefore, we chained them together via NOT Q and used Q to power the LEDs. As we used a push button to activate the clock on the first flip-flop, we pulled the clock pin down to 0v using a 10k resistor connected to ground. One last detail is that the Set and Reset pins for each flip-flop are connected to 0v. Below is the finished result built by Luke. 

4bit Counter

AXE029 PICAXE Breadboard Adapter

As we use breadboard quite extensively in our microprocessor experiments I decided to take a look at the AXE029 breadboard adapter for the PICAXE which I purchased from the reliable people at tech supplies. The first thing that surprised me after receiving it was that it is not pre-assembled but in kit form; in retrospect it was perhaps a little naïve to think that it would pre-built. After a few minutes soldering, as the kit is not hard to put together, everything was in place and working fine – before and after shots below. On the AXE029 device there is a jumper which enables you to select between an 18 pin or 28/40 pin PICAXE and this allows you to place the AXE029 directly next to the PICAXE pins on the breadboard – works a treat with the 28X1 PICAXE microprocessors but not the 20M. For the 20M, you will have to place the AXE029 somewhere on your breadboard and connect it to the 20M via wires – not a big deal.

AXE029 Breadboard Adapter

One problem that I have had for a while now, and which is unrelated to the AXE029, is reliably getting a connection to the PICAXE. Using the MacAXEpad and connecting to the PICAXE via a USB cable, I often get connection errors. I’ll have to take a closer look at this – I suspect the USB driver on the Mac but it is hard to tell.

Alarm Project 2.0 Beta

Our second version of the alarm project is now in beta! All we have to do now is update our design in circuit simulator, do a tiny bit of debugging and move it all over to perforated board. Over the next few weeks, there will be a series of posts describing how each module of the alarm circuit works. This design consists of 5 J-K Flip-Flops, 8 AND gates, 2 OR gates, 4 NOT gates, 1 NPN transistor, 3 555 timers, a darlington driver, a 5v relay, a 5v voltage regulator, 12 diodes, 7 LEDs, a magnet switch, a speaker, a piezo buzzer, a numeric keypad, various resistors and capacitors and lots of single core wire and time.

Alarm 2.0 Beta

PICAXE Traffic Light Project and Using PICAXE 20M Interrupts

In a previous post describing how to build a traffic light (or stop light) system using a PICAXE microcontroller, I did not include the details of how to implement a pedestrian crossing part of the project. This post will describe the two ways we tried to implement the feature. Our first attempt used the interrupt feature of the PIXACE 20M and a push button connected to +5v and input pin 5 on the microcontroller. By using the setint instruction, the PICAXE can detect changes on its input pins and match given states, for example: setint %00000000, %00100000 will trigger and interrupt when pin 7 is low and setint %00100000, %00100000 will trigger and interrupt when pin 7 is high. Once an interrupt has been activated, the PICAXE does a gosub to the subroutine at label interrupt and returns to the place it left from on completion. Below is the code we implemented for the first version of the pedestrian crossing using the interrupts described:

symbol rot = 1
symbol gelb = 2
symbol gruen = 3
symbol fgrot = 5
symbol fggruen = 4
let w0 = 0
setint %00100000,%00100000
high fgrot
ampel:
high rot
if w0 = 1 then
gosub fussgaenger
let w0 = 0
setint %00100000,%00100000
else
pause 3000
endif
high gelb
pause 1000
low rot
low gelb
high gruen
pause 3000
low gruen
high gelb
pause 1000
low gelb
goto ampel
interrupt:
let w0 = 1
return
fussgaenger:
high fggruen
low fgrot
pause 3000
high fgrot
low fggruen
return

Unfortunately, this design has a pretty big issue. Namely, when the push button is pressed, the interrupt breaks out of pause statements and does not return to within the pause but immediately after it. This means that a pedestrian can influence the speed at which the traffic light system switches from one phase to another. To get around this, we decided to replace the use of interrupts by a hardware flag in the form of a latch built from an AND gate and a diode. When the user presses the pedestrian crossing button the AND gate latches the input and during the red phase, a check is made to see if the button was pressed. If it was, the pedestrian light sequence is started and the program loops around as normal. In the picture below, you will be able to see the AND gate latch, the traffic light LEDs and the pedestrian crossing LEDs.

PICAXE 20M Traffic Light Project With Pedestrian Crossing

The schematic for this circuit, drawn using tinyCAD, can be seen below.

PICAXE-20M Traffic Light Schematic

Below is the final piece of code for the hardware shown above. There are of course, improvements that could be made, but for the time being, I think that this was a good first step into the PICAXE world.

symbol rot = 1
symbol gelb = 2
symbol gruen = 3
symbol fgrot = 5
symbol fggruen = 4
high fgrot
ampel:
high rot
if  pin5 = 1  then
pause 800
gosub fussgaenger
else
pause 3000
endif
high gelb
pause 1000
low rot
low gelb
high gruen
pause 3000
low gruen
high gelb
pause 1000
low gelb
goto ampel
fussgaenger:
high fggruen
low fgrot
pause 3000
high fgrot
low fggruen
pause 800
return
Older posts

© 2017 MOV AX, BLOG

Theme by Anders NorenUp ↑