Tiny-Dice Electronic dice using an ATtiny2313



Similar documents
ET-BASE AVR ATmega64/128

STK User Guide

AVR Butterfly Training. Atmel Norway, AVR Applications Group

K128. USB PICmicro Programmer. DIY Electronics (HK) Ltd PO Box 88458, Sham Shui Po, Hong Kong. mailto:

K8025 VIDEO PATTERN GENERATOR. Check the picture quality of your monitor or TV, ideal for adjustment or troubleshooting.

WICE-SPI Hardware Operation Manual

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

K8068 BUS DIMMER FOR HOME MODULAR LIGHT SYSTEM ILLUSTRATED ASSEMBLY MANUAL H8068IP-1

RS232/DB9 An RS232 to TTL Level Converter

CHAPTER 11: Flip Flops

ECEN 1400, Introduction to Analog and Digital Electronics

Build A Video Switcher. Reprinted with permission from Electronics Now Magazine September 1997 issue

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

Joule Thief 3.0 Kit. June 2012, Rev Joule Thief 3.0

Martin County Amateur Radio Association. Nightfire Kits 1 LED Torch Kit Contents. Description

PolyBot Board. User's Guide V1.11 9/20/08

The Programming Interface

POCKET AUDIO GENERATOR K8065

EvB 5.1 v5 User s Guide

Lab 11 Digital Dice. Figure Digital Dice Circuit on NI ELVIS II Workstation

AXE114S BINARY CLOCK. revolution Revolution Education Ltd. Web: Version /09/08 AXE114.PMD.

DS1307 Real Time Clock Breakout Board Kit

Total solder points: 129 Difficulty level: beginner advanced LIQUID LEVEL CONTROLLER K2639 ILLUSTRATED ASSEMBLY MANUAL H2639IP-1

Assembly and User Guide

RC2200DK Demonstration Kit User Manual

DDS VFO CONSTRUCTION MANUAL. DDS VFO Construction Manual Issue 1 Page 1

GLOLAB Universal Telephone Hold

TEECES DOME LIGHTING SYSTEMS

7-SEGMENT DIGITAL CLOCK

2 : BISTABLES. In this Chapter, you will find out about bistables which are the fundamental building blocks of electronic counting circuits.

DUAL ELECTRONIC DICE K3400

!Operation:!1. Connect an external power source to J1 (+ and - IN terminals). The

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

Application Note: Using the Motor Driver on the 3pi Robot and Orangutan Robot Controllers

K6002 TEMPERATURE CONTROLLER. Specifications

Total solder points: 205 Difficulty level: beginner advanced UNIVERSAL BATTERY CHARGER / DISCHARGER K7300 ILLUSTRATED ASSEMBLY MANUAL

15 Channel IR transmitter. Total solder points: 53 Difficulty level: beginner advanced K8049 ILLUSTRATED ASSEMBLY MANUAL

Support:

Glolab Talking Phone Dial Monitor

Arbeitskreis Hardware. Prof. Dr. Michael Rohs, Dipl.-Inform. Sven Kratz MHCI Lab, LMU München

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Controlling a Dot Matrix LED Display with a Microcontroller

USBSPYDER08 Discovery Kit for Freescale MC9RS08KA, MC9S08QD and MC9S08QG Microcontrollers User s Manual

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Total solder points: 248 Difficulty level: beginner advanced. 15 Channel infrared receiver K8050 ILLUSTRATED ASSEMBLY MANUAL

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

PICNet 1. PICNet 1 PIC18 Network & SD/MMC Development Board. Features. Applications. Description

AC-PG-USBASP USBASP AVR Programmer

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

A PIC16F628 controlled FLL (Frequency Locked Loop) VFO for HF

MAINS VOLTAGE DETECTOR K7101

User Guide Reflow Toaster Oven Controller

Introducing AVR Dragon

- 35mA Standby, mA Speaking pre-defined phrases with up to 1925 total characters.

WHO ANSWERED FIRST? FIND OUT WITH THIS QUIZ BUZZER KIT

The $25 Son of a cheap timer This is not suitable for a beginner. You must have soldering skills in order to build this kit.

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

400W MONO/STEREO AMPLIFIER

Total solder points: 115 Difficulty level: beginner advanced 4 CHANNEL RUNNING LIGHT K8032 ILLUSTRATED ASSEMBLY MANUAL

K4401 SOUND GENERATOR. them at the touch of a button. Specifications

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

Lab Experiment 1: The LPC 2148 Education Board

Modifying the Yaesu FT-847 External MHz Reference Input

Total solder points: 167 Difficulty level: beginner advanced DMX CONTROLLED RELAY K8072 ILLUSTRATED ASSEMBLY MANUAL

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

Arduino ADK Back. For information on using the board with the Android OS, see Google's ADK documentation.

In-System Programming Design TM. Guidelines for ispjtag Devices. Introduction. Device-specific Connections. isplsi 1000EA Family.

MFRD52x. Mifare Contactless Smart Card Reader Reference Design. Document information

The components. E3: Digital electronics. Goals:

TURBO PROGRAMMER USB, MMC, SIM DEVELOPMENT KIT

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16

step 1 Unpack the lunchbox And check whether you have got all the components~ If you have questions please contact us at: info@unitunlikely.

Mobius 3 Circuit Board Programming Instructions

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Robot Board Sub-System Testing. Abstract. Introduction and Theory. Equipment. Procedures. EE 101 Spring 2006 Date: Lab Section # Lab #6

Total solder points: 147 Difficulty level: beginner advanced VIDEO SIGNAL CLEANER K8036 ILLUSTRATED ASSEMBLY MANUAL

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

GertDuino Board. User Manual. Exclusively From. By: G.J. van Loo, Version 1.4 Dated: 6 th Nov P age

Real Time Clock USB Evaluation Board V3.0

Kit Watt Audio Amplifier

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

How To Use An Ams 5812 Pressure Sensor With A Usb Starter Kit

Measuring Resistance Using Digital I/O

Controller for AD9850 DDS Modules Andy Talbot G4JNT

Designing VM2 Application Boards

A Digital Timer Implementation using 7 Segment Displays

PCAN-MicroMod Universal I/O Module with CAN Interface. User Manual. Document version ( )

Section 28. In-Circuit Serial Programming (ICSP )

3-Digit Counter and Display

AN-812 APPLICATION NOTE

VOLUME AND TONE CONTROL - PREAMPLIFIER K8084

ICS379. Quad PLL with VCXO Quick Turn Clock. Description. Features. Block Diagram

ARDUINO SEVERINO SERIAL SINGLE SIDED VERSION 3 S3v3 (REVISION 2) USER MANUAL

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AN3265 Application note

How to Move Canon EF Lenses. Yosuke Bando

Transcription:

Tiny-Dice Electronic dice using an ATtiny By Florian Schäffer (Germany) This simple electronic dice is an ideal starter project to introduce youngsters and those still young at heart to the dark arts of microcontrollers and circuit building. We take you step by step through the process. For your troubles you will build a useful electronic dice. It will put an end to you scrabbling around under the table to retrieve a dice that s been carelessly tossed and also an end to cheating It landed on a six! It really did yeah right. This simple circuit simulates the rolling of a dice (or die to pedants). When the roll button is pressed the display shows random numbers in the range of one to six, after a while the display settles with one number on the LED display. To make the project easier to build for beginners we have ruled out the use of any SMD components and used leaded components throughout. The dice circuit The circuit in Figure shows the connections between the pushbutton, the seven-segment display and the Atmel microcontroller I/O pins. Resistors R to R8 are required to limit the current flowing to each of the LED display segments. IC is a simple regulator which converts the 9 V battery voltage to a stable V for the circuit. C4 is used to suppress the signal produced by contact bounce from pushbutton S. This button is used to start the dice rolling. When the circuit has not been used for a while the display is turned off to reduce power consumption and promote longer battery life. The decimal point LED is used to indicate that the circuit is on. The complete dice kit is available from the Elektor Store []. Included in the kit is a pre-programmed microcontroller. The microcontroller s internal R/C oscillator generates an 8-MHz clock signal. The internal :8 divider is used to produce the -MHz controller clock frequency. Accurate timing is not essential in this application so an external crystal is not necessary. R9 is used as a pull-up resistor to lektor post Project No. 0

+V internal pullup 0k R9 4 5 7 8 9 0 RST IC PB0/AIN0 PD/ICP PB/AIN PD5/T PB ATtiny(A) PD4/T0 PB/OC PD/INT PB4 PD/INT0 PB5/MOSI PD/TXD PB/MISO PD0/RXD PB7/SCK XTAL GND XTAL 4 0 5 9 8 7 C 00n R R R R4 R5 R R7 9 7 5 4 b c d e f a g 0 R8 S C4 00n LD SC9- dp CC CC 8 MCP700-00 +9V IC +V C C u u 50 - Figure. The circuit using an Atmel microcontroller looks dicey. tie the high-impedance Reset input up to a logic High (i.e. to disable it). The source code The dice program shown in Listing has been produced using the free WinAVR tool chain []. The GCC compiler contained in the tool chain generated the machine code for the ATtinyA controller. The basic principle of operation is quite simple; the microcontroller does not have a built-in random number generator so we use an 8-bit timer as a counter which is configured to continually count up to a maximum, overflow to zero and count up again. The counter overflows about fifteen times per second. Each press of the pushbutton generates two interrupts (one on pressing and one on releasing). At every second interrupt a loop is initiated which shows on the display (with ever increasing delay) numbers from to to simulate a dice rolling to a halt. Once this loop is executed the value of the counter which is running continually in the background is read and a value from 0 to is calculated (the remainder value after dividing by, plus ). The resulting value is then displayed. Unless you can accurately synchronize your buttoning pushing with the internal counter clock, each number from one to six has an equal probability of being displayed and can be considered random. The displayed LED segments for the numbers are represented in the code (0 to 9, only to are used). The program can of course be changed to show other numbers or even letters on the display. Programming As we already mentioned, the kit for this project includes a pre-programmed microcontroller. There is no reason why you shouldn t change the program and re-program the chip, after all that s half the fun of hacking. Once any changes have been made or new code has been created using an editor program, it will need to be converted into machine code using a compiler. The resulting hex file can then be transferred to the microcontroller s flash memory using a program such as AVR- DUDE []. Here you will need an extra bit of hardware. In addition to a programmer lektor post Project No. 0

50- V.0 lektor post Project No. 0 4 GND ISP 5 MOSI 0k MISO SCK RESET R9 XTAL GND XTAL 4 0 5 Construction Soldering: Should you be lucky enough to have a soldering iron with an adjustable bit temperature set it to around 50 to 70 C for classic rosin-cored, lead/tin solder which produces reliable joints on DIY projects. Leadfree solder will need a temperature of around 80 to 400 C.. Insert the components into the PCB from the component side. See the placement plan near the parts list.. Make good contact with the soldering tip onto the solder pad and the component lead.. After about half a second introduce the solder so that it contacts the pad and lead. 4. When the solder melts and flows (should take around one second) remove the solder and then the iron from the joint. 5. Check the joint is good.. Clip off protruding component lead. Component mounting sequence: Component leads can be bent using flat nose pliers. Always grip the lead on the component side of the bend. Don t make the bend too close to the component body.. Resistors (arrange them so that the color rings indicating their value can be read from left to right).. Capacitors (check their values).. Pushbutton. 4. The IC socket (line up pin one with position on the layout). 5. The seven segment display (check orientasuch as the Atmel AVR-ISP MK you will need a programming adapter with an IC socket; it can be easily built using a small square of perf board (Figure ). This handy bit of hardware will also be useful in the future for reprogramming the microcontroller if you need to make changes. Another aspect of microcontroller programming is setting the internal fuses which are used to configure the microcontroller (i.e. to enable operation with the internal oscillator for example). This project just uses the default settings so it is not necessary to worry about fuse settings at the moment. 0 C 00n RST IC PB0/AIN0 PB/AIN PD/ICP PD5/T 9 4 PB ATtiny(A) PD4/T0 8 5 PB/OC PB4 PD/INT PD/INT0 7 7 8 PB5/MOSI PB/MISO PD/TXD PD0/RXD 9 PB7/SCK 50 - Figure. The small programming adapter with a six pin ISP connector. Component List Resistors R R8 = 9Ω 5%, 0.5W R9 = 0kΩ Capacitors C,C = µf, 5mm pitch C,C4 = 00n, ceramic, 0. pitch Semiconductors IC= ATtinyA, programmed IC = MCP700 LD = SC9 7-segment LED Miscellaneous S = pushbutton, momentary action Clip-on connector for 9-V battery 0-way IC socket. PCB # 50- v.0 50- V.0 Figure. How it should look when you re finished. lektor post Project No. 0

tion of the decimal point lead).. IC (make sure it s correctly orientated). Don t mount this too close to the board. Leave a gap of about 5 mm between the component base and the board surface. A component mounted close to the board can be subjected to relatively large levels of mechanical stress which may cause internal damage to the IC. 7. The battery clip (feed the wires through the strain relief holes first. Black wire to the GND pad and red wire the 9 V pad). Final assembly: After assembling all the components on the board make a close inspection of all the joints. Lead/tin solder produces shiny joints; any crazing is an indicator of a dry joint, check for missing solder or solder bridges shorting two tracks together. It s also worth double checking battery connection polarity and the IC socket orientation. The finished board should look like Figure. Now you can connect up the battery but don t plug in IC just yet. The decimal point LED will light up to show that power is available to the board. Should the LED not light then you can begin with what is any engineer s favorite pastime hardware debugging. Once everything is okay you can carry on: Disconnect the battery. Orientate the pre-programmed IC over its socket ensuring that the notch in the package indicating pin # is nearest to the battery wire connection point and not the other way round. Check that the package leads line up with all their positions in the socket. Apply light pressure to correct the position of any lead. Now carefully apply pressure evenly to the top of the package using two fingers until the IC is inserted. This may require some force. Reconnect the battery. Press the pushbutton and start gambling! Now you re ready to roll! Have fun! Web Links [] Web page for this article: www.elektormagazine.com/articles [] WinAVR: http://sourceforge.net/projects/ winavr/ [] AVRDUDE: www.nongnu.org/avrdude/ (50) Listing. #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> // defined _delay_ms() // IRQ handling int main (void); volatile uint8_t roll=0; volatile uint_t zeit=0; const int8_t numbers [0] = /* A F B G E C D */ 0b00, // 0 0b000000, // 0b000, // 0b000, // 0b0000, // 4 0b000, // 5 0b00, // 0b00000, // 7 0b0, // 8 0b000, // 9 // 0..9: Binary association of ports with numbers. Active high lektor post Project No. 0 4

; /** @brief IRQ Routine PCINT is called at IRQ. Allows the dice to roll */ ISR (PCINT_B_vect) uint8_t i=0; roll++; // How often has IRQ been triggered? PCINT only recognizes a toggle // IRQ is serviced twice per press. // Only need to start rolling once for every two if (roll == ) roll=0; // Start from zero for (i=; i < 40; i++) // Simulates dice throwing PORTD = numbers[(i % )+]; // Output. Counter Modulo = 0-5 => + = - _delay_ms(i*); PORTD = numbers[(tcnt0 % )+]; // Output. Timer value Modulo = 0-5 => + = - zeit=0; // counter to reset LEDs (zeit = time) /** @brief Main routine @param none @return End-Status */ int main(void) PORTD = 0; DDRD = 0xFF; DDRB &= ~( << DDB0); PORTB = ( << PB0); // PORTD all off // PORTD defined as outputs // B0 input // Pull Up active TCCR0B = ( << CS0) ( << CS00); // 8 Bit Timer, Prescaler CLK/04 =>,000,000/5 =.9 khz // => 0.0005 s/pulse => x5 > overflow occurs every 0.05s GIMSK = ( << PCIE); // PCIE IRQs enabled PCMSK = ( << PCINT0); // Assign IRQ to PB0 sei(); // IRQs enabled while () // endless // A loop to turn off the display after x secs for (zeit=0; zeit <=00; zeit++) // 00x00=0.000ms = 0s _delay_ms(00); PORTD = 0; // All segments off. return ; // never lektor post Project No. 0 5