Skip to content

RoboticsCanada.Com ~ ElectronicsVideoBlog.com

Archive

Category: Circuits

The Circuit

HEads or Tails Schematic

Circuit Description

Powered by a 9V battery, this is an electronic version of the simple “Heads or Tails” coin toss. When you press the Spin Button, the Heads and Tails LEDs begin to alternately flash very quickly. The flashing slows and finally stops with only one of the LEDs illuminated. Which LED is lit is determined by chance (or at least as close to chance as a simple circuit can provide.)

How it works

Pressing the Spin Button (S1) causes: capacitor C3 to charge very quickly through the R3-R4 voltage divider; and, transistor Q1 to turn on connecting the 555’s timing network (R1, R2, and C2) to power. The 555 now begins astable operation providing clock pulses to the 4013’s two D-Latches.

Releasing the Spin Button (S1) disconnects capacitor C3 from power allowing it to begin discharging through transistor Q1 and the 555’s timing network. As C3’s charge and Q1’s base voltage decreases, transistor Q1’s collector-emitter resistance increases and it slowly turns off causing the 555’s output to decrease in frequency. Eventually the charge on C3 is sufficiently low that Q1 turns fully off causing the 555’s astable operation to cease providing clock pulses to the 4013.

D-Latch A of the 4013 is wired in toggle mode (Q’ tied to its D input) so that its output will turn on and off with each successive clock pulse. The D input of D-Latch B is tied to the Q output of D-Latch A so that it will follow Latch A’s output one clock pulse later.

The output of each D-Latch drives the base of an output transistor (Q2 and Q3) through biasing resistors (R6 and R7). These transistors allow the LEDs to be sourced from the full 9V battery voltage rather than from the CMOS IC output directly. This provides maximum LED illumination.

The PCB

Our final board size is 2.2” x 1.7”.

Silk

heads or tails.brd.silk

Top

heads or tails.brd.top

Bottom (mirrored)

heads or tails.brd.bot

Parts List

heads or tails part list

The ZIP File

The available heads or tails ZIP file contains the following documents:

* Heads or tails.pdf – this document

* Heads or tails.part sch.jpg – circuit schematic

* Heads or tails.brd.silk.jpg – PCB silk layer

* Heads or tails.brd.top.jpg – PCB top copper

* Heads or tails.brd.bot.jpg – PCB bottom copper

Also included in the ZIP file are original EAGLE files:

* Heads or tails.sch – schematic

* Heads or tails.brd – PCB layout

* Heads or tails parts.txt.pdf – parts list

LCD is up and running on the 8051.

Got the LCD up and running.

Got the LCD up and running.

I will format the code a little nicer, and post it shortly. Had hours of problems with this thing, until I tracked down a 3 channel Logic Analyzer (PICKit2! to the rescue!) and found that some pins were floating. I thought I read through all the “Port” sections in the Atmel 8051 Hardware Manual, and it looked like Port 0 sinks and sources current as an output. However, it only uses both when used for external addressing, as a general output it is open drain…Rookie mistake!

Needless to say I switched to Port 2 (internal pullups resistors!)  and all problems were solved!

Code to follow…

Finally had a chance to play with the 8051 and get back into programming it in assembly and C, using Keil software.

Got basic interrupts going,  and managed to write up a simple PWM routine using Timer0 interrupt. The pictures show PWM 8-bit input and the output on logic probe outputs (green = 1, red =0). The routine is not perfect, or the LED’s don’t dim linearly, but it shows the basic workings of it.

High duty cycle, LED is bright!

High duty cycle, LED is bright!

Duty cycle somewhere around 30%

Duty cycle somewhere around 30%

The dip switches set the value used for the PWM, the LEDs show the high and low of the signal. You can see that as more switches are set high, the brighter the green, and the darker the red LED.