Skip to content

RoboticsCanada.Com ~ ElectronicsVideoBlog.com

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.

PCB UV Exposure unit

PCB UV Exposure unit

$350 Cad

Double-Sided PCB Exposure Unit
Length Width Height Weight
20.25″ 16.5″ 8.75″ 31 Lbs
Expose top or both PCB layers
Embedded timer with sound indicator
4 security latches to ensure a tight seal

Exposure box will be shipped collect with one of the following carriers: Purolator / FedEx / UPS.

This exposure unit is used to expose PCB artwork onto a Printed Circuit Board (PCB) to be etched with acid.

This unit is capable of doubled-sided exposures to create both the top and bottom PCB artwork layers at the same time, saving you both time and effort.

This unit uses a positive photoresist ? that is, UV transparent areas will be etched away on the final PCB. Artwork should have opaque tracks on a transparent background.

Using consistent methodology will allow PCBs to be made with results for track width and spacing down to 0.2mm (0.008?).

$350 Cad

HT0502_01$60Cad

The Cypress EZ-USB(r) FX2 is the world’s first USB 2.0 integrated microcontroller. By integrating the USB 2.0 transceiver, SIE, enhanced 8051 microcontroller, and a programmable peripheral interface in a single chip, Cypress has created a very cost-effective solution that provides superior time-to-market advantages. The ingenious architecture of FX2 results in data transfer rates of 480 Mb per second, the maximum allowable USB 2.0 bandwidth, while still using a low-cost 8051 microcontroller in a small 100 pin TQFP package. Because it incorporates the USB 2.0 transceiver, the FX2 is more economical, providing a smaller footprint solution than USB 2.0 SIE or external transceiver implementations. With EZ-USB FX2, the Cypress Smart SIE handles most of the USB 1.1 and 2.0 protocol in hardware, freeing the embedded microcontroller for application-specific functions and decreasing development time to ensure USB compatibility. The General Programmable Interface (GPIF) and Master/Slave Endpoint FIFO (8- or 16-bit data bus) provides an easy and glueless interface to popular interfaces such as ATA, UTOPIA, EPP, PCMCIA, and most DSP/processors.

  • Single-chip integrated USB 2.0 Transceiver, Serial Interface Engine (SIE), and Enhanced 8051 Microprocessor
  • Software: 8051 runs from internal RAM, which is downloaded via USB
  • Four programmable BULK/INTERRUPT/ISOCHRONOUS endpoints
  • Buffering options: double, triple and quad
  • 8- or 16-bit external data interface
  • 43mm by 88.46mm
  • General Programmable Interface (GPIF)
  • Allows direct connection to most parallel interfaces; 8- and 16-bit
  • Programmable waveform descriptors and configuration registers to define waveforms
  • Supports multiple Ready (RDY) inputs and Control (CTL) outputs
  • Integrated, industry standard 8051 with enhanced features:
  • Up to 48-MHz clock rate
  • Four clocks per instruction cycle
  • Two USARTS
  • Three counter/timers
  • Expanded interrupt system
  • Two data pointers
  • USB 2.0 kernel (480 MBit/sec)
  • Powered by USB – 3.3v Regulator for 3.3V operation
  • Smart Serial Interface Engine
  • Vectored USB interrupts
  • Separate data buffers for the SETUP and DATA portions of a CONTROL transfer
  • Integrated I2C-compatible controller, runs at 100 or 400 kHz
  • Four integrated FIFOs
  • Brings glue and FIFOs inside for lower system cost
  • Automatic conversion to and from 16-bit buses
  • Master or slave operation
  • FIFOs can use externally supplied clock or asynchronous strobes
  • Easy interface to ASIC and DSP ICs
  • Special autovectors for FIFO and GPIF interrupts
  • Up to 37 general purpose I/Os

Cypress provides development software called the “EZ-USB Control Panel” that allows you to test and debug your firmware without developing the host-based driver for your specific application. You can emulate the USB host controller commands and quickly test different packet sizes for both bulk and isochronous packets.

Source code for a general-purpose Windows device driver is provided by Cypress and you may modify it to your unique requirements.

Source code can be downloaded through the EZ-USB Control panel provided by Cypress or by the RS232 debug port with Keil C51 IDE.

Pinout Diagram:
pinout.gif (20KB)
schematics.gif (131KB)

EZ-USB Control Panel from:
Cypress Webpage
Direct File Link (63MB)
Single EZUSB Control Panel EXE Utility (692KB)

EZ-USB Driver Files Only from:
ezusb.sys (C:\winnt\system32\drivers)

Technical Reference of CY7C68013:
FX2_68013.pdf (5.3MB)

Sample Firmware (Right Click – Save As):
LED_SW_TEST.hex:
This sample program makes the the LED on the
board blink on and off when the button is pressed.
HEX file is straight binary, RAR file includes source and Keil uVision Project Files.
LED_SW_TEST.hex (1KB)
LED_SW_TEST.rar (1KB)
USB_232.hex:
This sample program can be used to verify the rs232
debug port. Connect both USB and Serial
cable to the trainer, open Hyper Terminal with
1200-Baud, 8-Bits, No Parity Bit, 1 Stop Bit, Xon/Xoff Flow Control.
Send a character to the device in Hyper Terminal,
and it will respond with a short string and your character +1.
USB_232.hex (6KB)

Driver Debug Monitor:
dbgmon_v43.zip (166KB)

Keil C51:
You may download a Keil C51 software Tools evaluation version (fully
functional, 2KBytes object size limited) from http://www.keil.com. It has a
C compiler, IDE, linker and debugger.

EZ-USB pinout

$60Cad