ECE Homework #10

Similar documents
Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Timer1 Capture Mode:

More Fun with Timer Interrupts

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Speed Control of a DC Motor using Digital Control

These 3 registers contain enable, priority,

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

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

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

Flow Charts and Assembler Programs

Tel: Fax:

Chapter 11: Interrupt On Change

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

SRF08 Ultra sonic range finder

Accurate Time and Interrupts

EE 361L Digital Systems and Computer Design Laboratory

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

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

ME 6405 Introduction to Mechatronics

Embedded System Design

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Team 8: Robert Blake Craig Goliber Alanna Ocampo

ELEG3923 Microprocessor Ch.9 Timer Programming

The University of Texas at Arlington Lecture 21_Review

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

Lecture (04) PIC 16F84A programming I

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

LCD. Configuration and Programming

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Interrupts. Embedded Systems Interfacing. 08 September 2011

ECE Test #1: Name

Using Timers of Microchip PIC18F Microcontrollers

Interrupts on PIC18F252 Part 2

Contents. PIC Mini Data Sheets

Human Response Timer

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

Lecture (03) PIC16F84 (2)

NOTICE: 1, the timing for Start, Stop, ACK, NACK, write and read is same as I2C

EEE111A/B Microprocessors

Relay. bit4 bit5 bit6 bit7

Analog Output with a Digital to Analog Converter

Lecture (04) PIC16F84A (3)

PIC Discussion By Eng. Tamar Jomaa

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

Chapter 6 Interrupts. (I. Scott Mackenzie) By: Masud-ul-Hasan

Laboratory 10. Programming a PIC Microcontroller - Part II

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

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

The University of Texas at Arlington Lecture 5

Microcontroller Overview

ECE Homework #3

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

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

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17, MSP430F5529 Launchpad User's Guide

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

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

Binary Outputs and Timing

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

PIC 16F84A programming (II)

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

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

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

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

Embedded Systems Programming. ETEE 3285 Topic HW3: Coding, Compiling, Simulating

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

PIC Discussion By Eng. Tamar Jomaa

Electromyogram Based Controls Acting on Lego Mindstorm Car

Section 14. Timer1 HIGHLIGHTS. Timer1. This section of the manual contains the following major topics:

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

The MCU s Pulse. Internal clock or oscillator to synchronize operation. One clock cycle = 1 TOSC = 1/fOSC. t TOSC

WINTER 14 EXAMINATION Subject Code: Model Answer Page No: 1/ 26

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

CprE 288 Spring 2014 Homework 5 Due Fri. Feb. 21

NET3001 Fall 12. Assignment 4 (revised Oct 12,2012) Part 1 Reaction Time Tester (15 marks, assign41.c)

ECE-6170 Embedded Systems Laboratory Exercise 3

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

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

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

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

Chapter 13. PIC Family Microcontroller

Embedded programming, AVR intro

The new HP-01. Inside the HP-01

Experiment 9: Using HI-TECH C Compiler in MPLAB

CENG-336 Introduction to Embedded Systems Development. Timers

Learning Objectives:

CPE/EE 323 Introduction to Embedded Computer Systems Homework V

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

Model Answer Microcontrollers. MCQ Problems Total Q1 Q2

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Homework. Reading. Machine Projects. Labs. Intel 8254 Programmable Interval Timer (PIT) Data Sheet. Continue on MP3

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

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

ECED 3204 Microprocessor Midterm Reference Solution


8051 Microcontroller

Transcription:

Timer 0/1/2/3 ECE 376 - Homework #10 Timer 0/1/2/3, INT Interrupts. Due Wednesday, November 14th, 2018 1) Write a program which uses INT and Timer 0/1/2/3 interrupts to play the cord C#major for 1.000 seconds when button RB0 is pressed. C#maj C# F G# RA0: C#3 138.59 Hz ( Timer 1 ) RA1: F3 174.61Hz ( Timer 2 ) RA2: G#3 207.65Hz ( Timer 3 ) 1.000 second: ( Timer 0 ) Rising edge on RB0 ( INT0 ) RB0 INT0 1 second Timer0 RA3 RA0 138.59Hz Timer1 RA1 174.61Hz Timer2 RA2 207.65Hz Timer3

Interrupt Service Routine: void interrupt IntServe(void) { if(int0) { TMR0 = -39062; RA3 = 1; INT0IF = 0; if(tmr0if) { RA3 = 0; TMR0IF = 0; if(tmr1if) { TMR1 = -36026; if(ra3) RA0 =!RA0; TMR1IF = 0; if(tmr2if) { if(ra3) RA1 =!RA1; TMR2IF = 0; if(tmr3if) { TMR1 = -24027; if(ra3) RA2 =!RA2; TMR3IF = 0;

Interrupt Initialization // set up Timer0 for PS = 256 T0CS = 0; T0CON = 0x87; TMR0ON = 1; TMR0IE = 1; TMR0IP = 1; // set up Timer1 for PS = 1 TMR1CS = 0; T1CON = 0x81; TMR1ON = 1; TMR1IE = 1; TMR1IP = 1; // set up Timer2 for 174.61Hz ( N = 28,635 = 7 * 256 * 16 ) T2CON = 0x3F; PR2 = 255; TMR2ON = 1; TMR2IE = 1; TMR2IP = 1; // set up Timer3 for PS = 1 TMR3CS = 0; T3CON = 0x81; TMR3ON = 1; TMR3IE = 1; TMR3IP = 1; // set up INT0 for rising edges INT0IE = 1; TRISB0 = 1; TRISB1 = 1; INTEDG0 = 1; // turn on all interrupts GIE = 1; Term Project 2) Specify the requirements for your term project subject to including At least two interrupts, At least three things we covered in ECE 376 (neopixel, stepper motor, LCD display, keypad, etc.), and Some statistical analysis

Insanely Precise Chess Clock: 3) Requirement: Keep track of two player's times to 0.1ms. Input: Output: Buttons RB0, RB1, RB2 LCD display How they relate: Press RB1 to start the game. That sets each player's time to 5 minutes (300 seconds) When RB0 is pressed (player A), his/her clock stops and player B's clock starts When RB1 is pressed (player b), his/her clock stops and player A's clock starts When running, a player's clock decrements down to 0:00 and stops at 0. The LCD display displays the time to 100us Tolerance: 50 clocks Interrupts Used: INT0: Player 1's button (Player 2's clock starts to decrement) INT1: Pause the game (both clocks stop) INT2: Player 2's button (Player 1's clock starts to decrement) Timer2 100us timer (1000 clocks) Reset: Return times to 5:00.0000 (not really an interrupt)

4a) Analysis: Give computations for setting up Timer interrupts Pre-scalars are set to 1 for a resolution of 100ns INT interrupts are set up for rising edges Timer2 = 1000 clocks = 1 * 250 * 4 T2CON = 0x05; PR2 = 249 4b) C-Code and Flow Chart Note: It looks like there are five programs running in parallel: the main routine and four interrupts. Each interrupt is fairly simple. Interrupt, do something, then get out. Don't do loops or complex operations inside the interrupt - there may be another interrupt coming shortly. Start (Reset) INT0 (RB0 pressed) INT1 (RB1 pressed) INT0 (RB0 pressed) Timer2 100us Initialize Interrupts Time = 5:00.0000 TURN = 2 TURN = 0 TIME = 5:00.0000 TURN = 1 1 2 TURN? other Compute min / sec Exit Exit Exit Dec Player 1 Time Dec Player 2 Time Display Times Exit

// Chess Clock #include <pic18.h> // Global Variables unsigned long int TIME1, TIME2; unsigned char TURN; // Interrupt Service Routine void interrupt IntServe(void) { if (TMR2IF) { if (TURN == 1) if (TIME1) TIME1 = TIME1-1; if (TURN == 2) if (TIME2) TIME2 = TIME2-1; TMR2IF = 0; if (INT0IF) { TURN = 2; INT0IF = 0; if (INT1IF) { TURN = 0; INT1IF = 0; if (INT2IF) { TURN = 1; INT2IF = 0; // Subroutines #include "lcd_portd.c" void LCD_Out(unsigned long int DATA, unsigned char N) { unsigned char A[10], i; for (i=0; i<6; i++) { A[i] = DATA % 10; DATA = DATA / 10; for (i=6; i>0; i--) { if (i == N) LCD_Write('.'); LCD_Write(A[i-1] + '0'); // Main Routine void main(void) { unsigned int i; unsigned long int M1, S1; unsigned long int M2, S2; TRISA = 0; TRISB = 0xFF; TRISC = 0x04; TRISD = 0; ADCON1 = 0x0F; // capture every rising edge // Turn on Timer2 for 1000 clocks T2CON = 0x05; PR2 = 249; TMR2ON = 1; TMR2IE = 1; // Turn on INT0 for rising edges INTEDG0 = 1; INT0IE = 1; TRISB0 = 1; // Turn on INT1 for rising edges INTEDG1 = 1; INT1IE = 1; TRISB1 = 1; // Turn on INT2 for rising edges INTEDG2 = 1; INT2IE = 1; TRISB2 = 1; LCD_Init(); Wait_ms(100);

TIME1 = 3000000; TIME2 = 3000000; // turn on all interrupts GIE = 1; while(1) { M1 = TIME1 / 600000; S1 = TIME1 % 600000; M2 = TIME2 / 600000; S2 = TIME2 % 600000; LCD_Move(0,4); LCD_Write(M2 + 48); LCD_Write(':'); LCD_Out(S2,4); LCD_Move(1,4); LCD_Write(M1 + 48); LCD_Write(':'); LCD_Out(S1,4); Memory Summary: Program space used A7Eh ( 2686) of 10000h bytes ( 4.1%) Data space used 6Ah ( 106) of F80h bytes ( 2.7%) EEPROM space used 0h ( 0) of 400h bytes ( 0.0%) ID Location space used 0h ( 0) of 8h nibbles ( 0.0%) Configuration bits used 0h ( 0) of 7h words ( 0.0%) The resulting code compiles into 1343 lines of assembler. It takes up 4.1% of program memory (the PIC can do a lot more)

5) Validation: Include Measurements of the Timer interrupt (is is correct?) Checking that the number generated is in fact random (use a Chi-squared test) RA0: Timer2 is interrupting every 100us (check) Resulting Display Checking the functionality: Time starts on 5:00.0000 on reset. RB0 starts Player #2's clock. It decrements to zero and stops at zero (shown) RB1 pauses the clock. Both times stop decrementing. RB2 starts Player #1's clock. It decrements to zero and stops at zero. 6) Demo (30pt): In person or with a video.