Human Response Timer

Similar documents
Accurate Time and Interrupts

Analog Output with a Digital to Analog Converter

Serial Terminal EEPROM Interface

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c

Capture Mode of Pic18F252

Interrupts on PIC18F252 Part 2

Using Timers of Microchip PIC18F Microcontrollers

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Speed Control of a DC Motor using Digital Control

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Topic 10 10/24/2010. C with Embedded Extension

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Embedded Systems Lab 2 - Introduction to interrupts

LCD. Configuration and Programming

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Timer1 Capture Mode:

Microchip 18F4550 Interface, Signal conditioning, USB, USB- RS-232, 16x2 LCD Interface

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

16.317: Microprocessor Systems Design I Fall Exam 3 December 15, Name: ID #:

Getting acquainted with the development tools June 27, 2006 ELE492 Embedded System Design Exercise 1

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics

ME 6405 Introduction to Mechatronics

8051 Microcontroller Interrupts

More Fun with Timer Interrupts

Chapter 11: Interrupt On Change

ECE Homework #10

Microcontrollers and Interfacing week 8 exercises

Input/Output Ports and Interfacing

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

Signature: 1. (10 points) Basic Microcontroller Concepts

Embedded System Design

BME 361 Biomeasurement Laboratory Demonstration Biomedical Engineering Program University of Rhode Island June 10, 2015

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

GPS Reader. Figure 1: RMC NEMA Tag Definition

Simon. Final Project Report December 11, 2009 E155. Julia Karl and Kirsten McAfee

Department of Electronics and Instrumentation Engineering Question Bank

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

Remote Controlled KitchenAid Mixer for the Clients at ADEC. Appendices. Arnaud Bacye Karina Dubé Justin Erman Matthew Martin

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

Team 8: Robert Blake Craig Goliber Alanna Ocampo

UNCA CSCI 255 Exam 3 Fall 2011

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

MicroToys Guide: PS/2 Mouse N. Pinckney April 2005

EE 361L Digital Systems and Computer Design Laboratory

8051 Microcontroller

EXPERIMENT NO.1. A Microcontroller is a complete computer system built on a single chip.

C Language Programming, Interrupts and Timer Hardware

Microcontroller Overview

ECE 476 LABORATORY 3 SECURITY SYSTEM WEDNESDAY, MARCH 7, 2007

The University of Texas at Arlington Lecture 21_Review

INTERRUPTS in microprocessor systems

ME 4447/ME Microprocessor Control of Manufacturing Systems/ Introduction to Mechatronics. Instructor: Professor Charles Ume

Embedded Systems Module. 6EJ505. C Tutorial 3: using the ICD3 rev tjw

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

ELCT 912: Advanced Embedded Systems

CHAPTER 11 INTERRUPTS PROGRAMMING

Interrupt Basics Karl-Ragmar Riemschneider

C Language Programming, Interrupts and Timer Hardware

Final Design Report 19 April Project Title: Pneumatic Exercise Machine

The University of Texas at Arlington Lecture 5

Flow Charts and Assembler Programs

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

80C51 Block Diagram. CSE Overview 1

Micro II and Embedded Systems

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.


Interrupts. Embedded Systems Interfacing. 08 September 2011

UNIT V MICRO CONTROLLER PROGRAMMING & APPLICATIONS TWO MARKS. 3.Give any two differences between microprocessor and micro controller.

Introduction to Embedded Systems

Reprinted by permission of T&L Publications Inc. Copyright 2001 USB MICROCONTROLLERS FOR THE MASSES

Interrupts and Timers

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Introduction to general architectures of 8 and 16 bit micro-processor and micro-controllers

Embedded Systems Lab Lab 8 EEPROM

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

Microprocessors B (17.384) Spring Lecture Outline

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Laboratory 10. Programming a PIC Microcontroller - Part II

Microprocessors B Lab 1 Spring The PIC24HJ32GP202

MEMO TO: ECE 4175 students February 8, 2008 FROM: SUBJECT: First quiz on Wednesday, February 13 Open book, open notes.

Three criteria in Choosing a Microcontroller

Question Bank Microprocessor and Microcontroller

Laboratory 9. Programming a PIC Microcontroller - Part I

MPLAB C1X Quick Reference Card

Write LED display data, in accordance with the address from the display from low to high, from low to high data byte operation.

Basic Embedded Software C Review Using MPLAB SIM. Loops. Embedded Systems Interfacing. 25 August 2011

AVR Timers TIMER0. Based on:

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

Performance & Applications

Transcription:

Human Response Timer Matthew Beckler beck0778@umn.edu EE2361 Lab Section 007 March 29, 2006 Abstract In this lab, we create a very useful application, a human response timer. The user s reaction time is measured as the duration between observing a lit LED, and pressing a push-button switch. This duration is accurately measured using Timer0, and the computed value is displayed on two, 7-segment LED displays. When user error is encountered, customized error codes help guide the user to productive operation. Introduction In an attempt to create a useful project, this human response timer has been created. While working with timers, interrupts, and parallel I/O is not particularly new, the complexity of this project, and the way in which is combines all three has some inherent challenges. We set up a finite state machine to control the operation of the circuit. There are five states, with multiple paths between some of the states. A global integer variable controls the current state. Timer 0 is used to provide a one millisecond clock in conjunction with the interrupt handlers. In this lab, we will only be using the high-priority interrupt handler. The random number generating routine has been recycled, but slightly modified to produce integers between 1000 and 10000, which is used as the random wait time (in milliseconds), before lighting the LED. The 7-segment display routine has also been recycled, but modified to include a digit of E, for displaying coded error messages. Observations For the scope of the main program, we have created a number of helper functions. The void display(void) function has returned from previous labs. The initial values of the digits are set to off. A digit for the letter E has been added, to provide a method for displaying useful error codes. There are two error possibilities in this device, and they are enumerated E0 and E1. Other than these small changes, the display() function is the same as before. Since we are using interrupts in our program s source code, a brief explanation of the PIC microcontroller s implimentation of interrupts is is necessary. The microcontroller has the ability to use two classes of interrupts, known as low-priority and high-priority interrupts. For most applications and devices, 1

only one class of interrupts is necessary. Under normal operation, the microcontroller starts execution at program memory location 0. When interrupts are in use, two additional addresses in program memory have special meaning. When an interrupt occurs, the processor will jump the program counter to one of two interrupt handlers, which are specific locations in program memory. The high-priority interrupt handler starts at program memory location 0x8, and the low-priority interrupt handler starts at program memory location 0x18. Normally, there is not enough space to store your complete interrupt handling code in these locations, so a goto instruction is often used to branch somewhere else in the program memory. In this experiment, we will only be using the high-priority interrupts. Nearly every microcontroller includes timing devices on-chip. The PIC18F452 is no exception, with a total of four timers available, with many features and options to customize their operation. For this experiment, we will be using the TIMER0 device. This is a 16-bit counter/timer, with internal/external clock inputs, variable edge-detection settings, and an 8-bit programmable prescaler. In 16-bit mode, Timer 0 has two registers that store the current count, TMR0L and TMR0H. The high byte is latched, so reading/writing from/to TMR0L will do the same operation between TMR0H(the latched register) and the actual register. Another important feature of Timer 0 is the ability to pre-set the count to customize the time to interrupt. This is done by loading the uppper byte of the desired value into TMR0H, and writing the lower byte of the desired value into TMR0L. There are a number of options available for Timer 0; our timer is setup for 16-bit mode with a pre-scaler of 1. This is done by writing the value 0x80 into the T0CON register. We also must enable global interrupts and the Timer 0 interrupt. We will be loading a starting count of 60543 = 0xEC7F into the TMR0 registers. We must load this value at the start of the program, as well as every time an interrupt occurs. This value corresponds to a very accurate timer period of 1 millisecond. The output to the LED display is handled with PORTC for the 8 data lines, and PORTD pins 0 & 1 for the digit select lines. We enable output for these ports and clear their values at the start of the program. The LED is connected to RB0, and the switch is connected to RB7; On initial power-on, the device s displays should be blank. When the switch is first pressed, the device will wait a random amount of time, between 1 and 10 seconds. If the user presses the switch before the LED is turned on, the error code E0 is displayed. When the device has waited the random amount, the LED will be turned on. At this point, the device will start the timer on the response time. If the users does not press the switch within the next 999 miliseconds, the error code E1 is displayed. Assuming the user pushes the switch withing 999 miliseconds, the processor waits for 1 second before displaying the user s reaction time. The number displayed is only two digits, and the digits are simply the most significant digits of the milisecond count. A software-controlled finite state machine has been implimented for this device. A global integer value is used to control the finite state machine. Here is a summary of the states: STATE 0: Display digits, wait for button press, then proceed to state 1. STATE 1: Wait for button release, generate random wait time, then 2

proceed to state 2. STATE 2: Enable Timer0, wait for random time, or until premature button press, which leads to state 5. If the random time expires, set the LED and reset the timer to upward counting mode, then proceed to state 3. STATE 3: Wait for button press (go to state 5), or timer reaches 999 miliseconds (go to state 4); turn off LED. STATE 4: Wait one second to display results, update display digits, then proceed to state 5; STATE 5: Display digits, wait for button release, then return to state 0; Conclusion Altogether, this is the first truly useful project we have created in this course. It has summarized the implimentations of timers, counters, parallel I/O, and multiplexed displays. The use of a finite state machine has helped to streamline and compartmentalize the program s code into easily tested and understood sections. Program control flows logically from one state to the next depending on the inputs to the processor. 3

Circuit Schematic Figure 1: Circuit Schematic - Courtesy Professor Rennolet 4

FSM Flowchart Figure 2: Flowchart for Finite State Machine 5

C Language Program #include <p18f452.h> #pragma config OSC=HSPLL, WDT=OFF, BOR=OFF, PWRT=ON #define TVAL 60543 static unsigned volatile int state = 0; static unsigned int wait = 0; static unsigned int reaction = 0; void low_isr(void); void high_isr(void); #pragma code high_isr_entry=0x8 void high_isr_entry(void) _asm GOTO high_isr _endasm #pragma code low_isr_entry=0x18 void low_isr_entry(void) _asm GOTO low_isr _endasm #pragma code /* pragma for generating interrupt code */ #pragma interrupt high_isr void high_isr(void) //reset to one millisecond TMR0H = TVAL >> 8; TMR0L = TVAL & 255; INTCONbits.T0IF = 0; switch(state) case 3: reaction++; case 2: case 4: wait--; #pragma interrupt low_isr 6

void low_isr(void) static unsigned long int SEED_X = 521288629L; static unsigned long int SEED_Y = 362436069L; unsigned int random(void) volatile unsigned float tempf = 0; unsigned int tempi = 0; static unsigned int a = 18000, b = 30903; SEED_X = a*(seed_x&65535) + (SEED_X>>16); // requires 16X16 multiply, 32bit add SEED_Y = b*(seed_y&65535) + (SEED_Y>>16); // requires 16X16 multiply, 32bit add tempi = ((SEED_X&65535) + (SEED_Y&65535))/2; tempf = (unsigned float) tempi / (unsigned float) 65535; // 0 < temp < 1 tempf = tempf * 9000; // 0 < temp < 9000 tempf = tempf + 1000; // 1000 < temp < 10000 return (int) tempf; static unsigned char values[] = 10, 10; //start out off void display(void) static unsigned char numbers[] = 0b00000011, 0b10011111, 0b00100101, 0b00001101, 0b10011001, 0b01001001, 0b01000001, 0b00011111, 0b00000001, 0b00001001, 0b11111111, 0b01100001 ; static unsigned char which = 0; if (!which) PORTDbits.RD0 = 0; PORTC = numbers[values[0]]; PORTDbits.RD1 = 1; 7

else PORTDbits.RD1 = 0; PORTC = numbers[values[1]]; PORTDbits.RD0 = 1; which =!which; return; void debounce(void) unsigned int count = 0; while (count < 0x2FFF) display(); count++; void main(void) TRISC = 0; TRISD = 0; PORTC = 0; PORTD = 0; INTCON2bits.RBPU = 0; TRISB = 0x80; PORTBbits.RB0 = 1; PORTBbits.RB1 = 1; PORTBbits.RB2 = 1; while (1) switch (state) case 0: /* case 0 = wait for button press, debounce*/ while( PORTBbits.RB7 == 1 ) display(); //turn off display: values[0] = 10; values[1] = 10; debounce(); state = 1; 8

case 1: while( PORTBbits.RB7 == 0 ); debounce(); wait = random(); // random generates integer from 1000 to 10000 ms state = 2; case 2: T0CON = 0x80; /* enable timer 0 16 bit op w prescaler = 1 */ INTCONbits.T0IF = 0; INTCONbits.T0IE = 1; INTCONbits.GIE = 1; TMR0H = TVAL >> 8; TMR0L = TVAL & 255; while( PORTBbits.RB7 == 1 && wait > 0 ); if( PORTBbits.RB7 == 0 ) // Pushed the button prematurely = E0 T0CON = 0; values[0] = 0; values[1] = 11; state = 5; debounce(); else //timer finished PORTBbits.RB0 = 0; TMR0H = TVAL >> 8; TMR0L = TVAL & 255; reaction = 0; state = 3; case 3: while ( PORTBbits.RB7 == 1 && reaction < 999 ); PORTBbits.RB0 = 1; if( PORTBbits.RB7 == 0 ) T0CON = 0; debounce(); state = 4; else T0CON = 0; 9

//too slow = E1 values[0] = 1; values[1] = 11; state = 5; case 4: //wait one second to display results wait = 1000; TMR0H = TVAL >> 8; TMR0L = TVAL & 255; T0CON = 0x80; while ( wait > 0 ); values[0] = (reaction \% 100) / 10; values[1] = reaction / 100; state = 5; case 5: //wait for button up while( PORTBbits.RB7 == 0 ) display(); debounce(); state = 0; 10