310 likes | 321 Views
Microcontroller Talk – CRES-ARC. Topics To Touch On. History of microcontrollers What are microcontrollers How you can work with microcontrollers Overview of the W8ZPF “Voter ID” project. History Of Microcontrollers. Microprocessors came before Microcontrollers November 1971
E N D
Microcontroller Talk – CRES-ARC microcontrollers_cres_arc.ppt
Topics To Touch On • History of microcontrollers • What are microcontrollers • How you can work with microcontrollers • Overview of the W8ZPF “Voter ID” project microcontrollers_cres_arc.ppt
History Of Microcontrollers • Microprocessors came before Microcontrollers • November 1971 • Intel introduced the world's first single chip microprocessor, the Intel 4004 • April of 1972 • First 8-bit microprocessor appeared on the market under a name 8008 • April of 1974 • 8080 became available • Addressed 64Kb of memory, had 75 instructions, and cost $360 • MOS Technology - WESCON exhibit ( 1975) • a pivotal event in the history of microprocessors • Announced the 6501 and 6502 at $25 each microcontrollers_cres_arc.ppt
What Are Microcontrollers? • Microprocessor – Microcontrollerwhat's the diff? • Microprocessorscan not stand alone • instruction decoder, ALU, address/data/ctl. busses, timing logic, (CPU) • Has no capability to interact with the outside world • memory, I/O ports, UARTS, etc. must be added to make it useful • Microcontrollersare small computing systems on a single chip • Central Processing Unit (CPU) • Program memory • Random Access Memory (RAM) • EEPROM - Electrically Erasable Programmable Read Only Memory • A variety of peripheral devices • USARTs, Timer/Counters, ADC, DAC, I/O Ports, CANs, SPIs, etc., etc. microcontrollers_cres_arc.ppt
What Are Microcontrollers?So, what’s all the excitement about? • They are inexpensive- even in single pieces • You can design complex functionality in a small package • Microcontrollers can be viewed as a universal building block • There are a lot of free tools to work with Microcontrollers • And – The thing I like the best - Next Slide! microcontrollers_cres_arc.ppt
What Are Microcontrollers? microcontrollers_cres_arc.ppt
What Are Microcontrollers?Microchip 16F88 DIP Package $3.90 each – single unit price microcontrollers_cres_arc.ppt
What Are Microcontrollers? 16F88 INTERNAL VIEW (Harvard Architecture) Has 35 instructions Datasheet – 214 pages microcontrollers_cres_arc.ppt
What Are Microcontrollers?ATMEL ATmega8 DIP Package $4.50 Each – single unit price microcontrollers_cres_arc.ppt
What Are Microcontrollers? Atmega8 INTERNAL VIEW (Harvard Architecture) Has 130 instructions Datasheet – 302 pages microcontrollers_cres_arc.ppt
How you can work with microcontrollers • So what’s the catch? • If you are new to software development • You need to think in a new paradigm • Start small and learn the basics first • You can work with microcontrollers on a couple of levels • Walk before you attempt to run microcontrollers_cres_arc.ppt
How you can work with microcontrollers • Ok – So What Do Microcontrollers Do? • Well – out of the box – it does nothing! • But you can make it do fantastic things • Just add software microcontrollers_cres_arc.ppt
How you can work with microcontrollersHow To Get Started • Select a controller family • Based on your goals • Availability of free stuff • set-up a development environment • Not a trivial task for the beginner • You need a way to load programs • Then are you ready to start! microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” • A real project • What are we trying to accomplish • Interface to the repeater system • Microcontroller Selection • Development Environment • Software Design • The Final Board (observations) microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” What are we trying to accomplish? • Identify how each receiver participated in relaying signals to the main transmitter during a “key down session” • Accommodate up to 3 receivers in the design • Use existing repeater interfaces/signals microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller”Simplified Interface Diagram Current Repeater Controller Current Voter Card New “Voter” Microcontroller * CORE (H) RX1 Voted (^) CD ID (M/R) RX1(H) RX2 Voted (^) =>90% of the time – High Pitch CW ID (M/R) (“VOTED”)** RX2 (H) RX3 Voted (^) RX3 (H) RX1 Dominant (^) Sample every 100ms When CORE is active < 90% of the time – Low Pitch CW ID (M/R)** (“DOMINANT”) RX1 Dominant (^) RX1 Dominant (^) *Controller “remembers” last transition ** ACTUALLY 88.8 % Calculate output when CORE goes inactive Inputs, Outputs, & Transformation microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller”INTERFACE FOR THE VOTER CONTROLLER PROJECT CORE LINE Active Idle Accumulate Data (100ms) Ignore RX inputs 1 or 0 Output lines retain previous data until core goes active again RX1 – RX3 output lines (active high) All output lines are cleared after core goes active for debounce time. There are 6 output lines 3 -> rx1 - rx3 “voted” 3-> rx1 - rx3 “dominant” microcontrollers_cres_arc.ppt Version 1.0 - wje
The W8ZPF “Voter Controller”Microcontroller Selection • Looked at 2 controllers For This Project • Microchip 16F88 • Atmel Atmega8 • Basic software structure was implemented using both • Either would have done the job • So how did I choose? microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The development environment • 16F88 Microchip microcontroller (initial choice) • MPLAB • Free environment for assembly language • Create, Edit, Assemble, Link, Load, & emulate programs • I use it on Windows 2K • I have used it for several projects – works well • No limitations on usage microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The development environment • ATmega8 microcontroller (final choice) • Open Software Foundation tool-set • GNU “C” compiler, assembler, linker • Make utility • Avrdude program loader • Runs on Linux (Unix) & Windows • Wanted experience with this environment • Atmega8 is more “compiler friendly” • Generally faster to develop SW using a compiler • However, a not significant issue for this project microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The development environment This is what it physically looks like ATmega8 Development board (Spark Fun) Serial port (program flash memory) LINUX environment (FC3 FC5) Final board microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller”Voter ID Board Schematic microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller”The Microcontroller Board microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The Software Design • This is where it gets a bit philosophical • I think of it in these terms • Software is a solution to a problem • Must understand the problem first • Then think about strategies to solve it microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The Software Design – How does one start? LAYERED MONOLYTH TOP DOWN COLABORATING PARTS BOTTOM UP VARIOUS SOFTWARE STRATEGIES microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The Software Design (STATE MACHINE) 100 MS interrupt HW States are: STARTUP IDLE COUNTING Run Background process Background Processing Return from interrupt Wakes-up foreground Background Responsibilities - Debounce inputs - Watch “core” line - Determine when new state exists - Maintain count for each Rx Foreground Responsibilities - HW initialization - Call action routines on state changes - Processes RX data on “key-up” - Signals main controller regarding RX usage (sets output lines) Foreground Processing New state Call routine To handle the State change Go to sleep microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The Software Design (STATE MACHINE) • Source File Statistics • main.c 155 lines • main.h 17 lines • init_timer1.c 30 lines • init_io.c 103 lines • interrupt.c 118 lines • Makefile 328 lines microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” The Software Design (STATE MACHINE) • More Statistics (Decimal) RESOURCEUSED/AVAILABLE • Text size 1462/8K Bytes (program instructions/tables, etc) • Data size 37/512 Bytes (variables) • TOTAL 1499 Bytes (5DBh) Used • 512 Bytes of EEPROM – none used microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” main.h file – variable declarations #ifdef LOCAL #define LOCAL #define EXTERN #include main.h #else #define EXTERN extern #endif enum { NO, YES }; enum { STARTUP, COUNTING, IDLE }; EXTERN unsigned char state; EXTERN unsigned char new_state; EXTERN int16_t rx1_count; EXTERN int16_t rx2_count; EXTERN int16_t rx3_count; microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” This is the main loop (part of it anyway) of the foreground “state machine” code while(1){ if(new_state == YES ){ new_state = NO; cli(); switch(state){ case COUNTING: // clear out old receiver counts on this state change rx1_count = 0; rx2_count = 0; rx3_count = 0; //clear all "voted" output lines to the repeater PORTB &= ~(_BV(PB0)); PORTB &= ~(_BV(PB1)); PORTB &= ~(_BV(PB2)); //clear all "dominant" output lines to the repeater PORTD &= ~(_BV(PD5)); PORTD &= ~(_BV(PD6)); PORTD &= ~(_BV(PD7)); break; case IDLE: /* Calculate results, set output lines accordingly **** This is long & will not show details here *** */ break; case STARTUP: // Do initialization here break; } sei(); } sleep_mode(); } Fragment of code from main.c microcontrollers_cres_arc.ppt
The W8ZPF “Voter Controller” • THE END !! microcontrollers_cres_arc.ppt