UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz V

Similar documents
UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz IV

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz III

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Lab Test III

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Lab Test III

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz II

Marten van Dijk, Syed Kamran Haider

Interrupts & Interrupt Service Routines (ISRs)

Supplementary Materials: Fabrication of a Lab on Chip Device Using Material Extrusion (3D Printing) and Demonstration via Malaria Ab ELISA

ADC: Analog to Digital Conversion

Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

CSCE 236 Embedded Systems, Spring 2012 Quiz/Test 2

School of Electrical, Computer and Telecommunications Engineering University of Wollongong Australia

// filename pwm.c // ATtiny84 (14 pin DIP)

AVR Timers TIMER0. Based on:

Digital and Analogue Project Report

Topic 11: Timer ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

ADC: Analog to Digital Conversion

Weekly Update Michael Jorgensen Week of 3/18/11 3/24/11

AVR Board Setup General Purpose Digital Output

Laboratory 4 Usage of timers

Distributed Real- Time Control Systems. Lecture 7 Real- Time Control

Software debouncing of buttons

Unit 14 Timers and Counters 14.1

Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

Marten van Dijk, Syed Kamran Haider

Distributed Real-Time Control Systems. Chapter 10 Real-Time Digital Control

12.1. Unit 12. Exceptions & Interrupts

Arduino. (Digital-to-Analog Converter D/A D2A) (Digital to Analog Conversion) 3. (Analog to Digital conversion)

UNIVERSITY OF MANITOBA Midterm

Physics 120B: Lecture 11. Timers and Scheduled Interrupts

The Atmel ATmega328P Microcontroller

EE 308: Microcontrollers

Unit 13 Timers and Counters

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

CprE 288 Introduction to Embedded Systems (Timers/Input Capture) Instructors: Dr. Phillip Jones

Use a semaphore to avoid the enqueue and dequeue functions from accessing and modifying count variable at the same time.

Physics 124: Lecture 12. Timer Basics. Timers and Scheduled Interrupts

onetesla Interrupter Firmware Guide General Overview

Signature: 1. (10 points) Basic Microcontroller Concepts

Interrupts Arduino, AVR, and deep dark programming secrets. What is an Interrupt?

Introduction. Unit 4. Numbers in Other Bases in C/C++ BIT FIDDLING. Microcontrollers (Arduino) Overview Digital I/O

TIMSK=0b ; /* enables the T/C0 overflow interrupt in the T/C interrupt mask register for */

The Atmel ATmega168A Microcontroller

Interrupts & Interrupt Service Routines (ISRs)

INTERRUPTS in microprocessor systems

CSCE374 Robotics Fall 2013 Notes on the irobot Create

Context Switching & Task Scheduling

Embedded Systems and Software

Final Exam. Date: May 12, 2017

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Turbidostat Hardware and Software Design

Newbie s Guide to AVR Timers

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

An SPI interface for the 65(C)02 family of microprocessors

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

May the Schwartz be with you!

Nano102/112 Series Errata Sheet

[TUT] ATTiny817, 12-bit timer, TCD, servos, 1 & 2 Ramp PWM, HXT900. There is a One Ramp mode example and a Two Ramp mode example.

UNIVERSITY OF MANITOBA Final Exam

chip1controller /* * SeniorDesignI2C.c * * Created: 11/24/2014 6:54:26 PM * Author: Robert Bower / Alonzo Ubilla * Chip 1 control */

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Newbie's Guide to AVR Timers (C) Dean Camera, 2007

NUC123xxxAN Series Errata Sheet. Errata Sheet for 32-bit NuMicro Family Rev May 19, 2016

EECS 373 Practice Midterm & Homework #2 Fall 2011

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2003

Robosoft Systems in association with JNCE presents. Swarm Robotics

- Open-source and open-hardware modular robotic platform specially created for educational purposes.

MEDIS Module 2. Microcontroller based systems for controlling industrial processes. Chapter 4: Timer and interrupts. M. Seyfarth, Version 0.

ECE 2300 Digital Logic & Computer Organization. More Finite State Machines

WEATHER STATION WITH SERIAL COMMUNICATION

CN310 Microprocessor Systems Design

+1 Alex Weinert. EEL Jan 31 Dr. Schwartz Dr. Arroyo Adam Barnett Mike Pridgen Sara Keen

Introduction to Embedded Systems

Lecture-55 System Interface:

X X X. VGA - Standard:

RTC rtc(dst_on); U8GLIB_SH1106_128X64 u8g(u8g_i2c_opt_none U8G_I2C_OPT_DEV_0);

Mark Redekopp, All rights reserved. EE 357 Unit 10b. Interrupts Timers

FACULTY OF ENGINEERING LAB SHEET

Introduction to Embedded Systems

SquareWear Programming Reference 1.0 Oct 10, 2012

University of Florida EEL 4744 Spring 2014 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 1 April Apr-14 9:03 AM

ECE 271 Microcomputer Architecture and Applications University of Maine

ECE PRACTICE EXAM #2 Clocks, Timers, and Digital I/O

EECS 373 Midterm 2 Fall 2018

#include <avr/io.h> #include <avr/interrupt.h> #define F_CPU UL // 8 MHz.h> #include <util/delay.h>

EECS 373 Midterm 2 Exam Winter 2018

Interrupts and Timers

EE445L Fall 2018 Final EID: Page 1 of 7

EECS 373 Midterm Winter 2017

CprE 288 Translating C Control Statements and Function Calls, Loops, Interrupt Processing. Instructors: Dr. Phillip Jones Dr.

EC4205 Microprocessor and Microcontroller

Section 001. Read this before starting!

Lecture-50 Intel 8255A: Programming and Operating Modes

Microcontroller & Interfacing

C Language Programming, Interrupts and Timer Hardware

Summer 2003 Lecture 21 07/15/03

Building Interactive Devices and Objects. Prof. Dr. Michael Rohs, Dipl.-Inform. Sven Kratz MHCI Lab, LMU München

University of Florida EEL 3744 Spring 2018 Dr. Eric M. Schwartz. Good luck!

Table of Figures Figure 1. High resolution PWM based DAC...2 Figure 2. Connecting the high resolution buck converter...8

ENGR 40M Project 3c: Switch debouncing

Transcription:

Department of Electrical and Computing Engineering UNIVERSITY OF CONNECTICUT ECE 3411 Microprocessor Application Lab: Fall 2015 Quiz V There are 3 questions in this quiz. There are 10 pages in this quiz booklet. Answer each question according to the instructions given. You have 45 minutes to answer the questions. Some questions are harder than others and some questions earn more points than others you may want to skim all questions before starting. If you find a question ambiguous, be sure to write down any assumptions you make. Be neat and legible. If we can t understand your answer, we can t give you credit! Write your name in the space below. Write your initials at the bottom of each page. THIS IS A CLOSED BOOK, CLOSED NOTES QUIZ. PLEASE TURN YOUR NETWORK DEVICES OFF. Any form of communication with other students is considered cheating and will merit an F as final grade in the course. Do not write in the boxes below 1 (x/40) 2 (x/40) 3 (x/20) Total (xx/100) Name: Student ID:

ECE 3411 Fall 2015, Quiz Page 2 of 10 1. [40 points]: Assume a clock frequency of f clk = 20MHz and the following initialization: DDRD = 0x10; OCR1A = 39062; OCR1B = 13020; TCCR1A = 0b00110011; TCCR1B = 0b00011101; Answer the following questions: a. In which mode is Timer1 running? b. What is the numerical value of TOP for Timer1 in this mode? c. How much time (in seconds) does it take for Timer1 to complete one full cycle, i.e. going from BOTTOM TOP BOTTOM? Be as accurate as possible in your calculations.

PB2 TCNT1 ECE 3411 Fall 2015, Quiz Page 3 of 10 d. Starting from the moment of Timer1 s initialization, draw the waveforms of the TCNT1 register value and the pin PB2 value w.r.t. time. Please draw the waveform strictly according to the timing scale shown on X-axis, otherwise no credit will be given. TOP BOTTOM 1 2 3 4 5 6 7 8 9 Time (s) 5V 0 V 1 2 3 4 5 6 7 8 9 Time (s) e. In each full cycle of Timer1: For how much time (in seconds) is PB2 low? Be as accurate as possible in your calculations. For how much time (in seconds) is PB2 high? Be as accurate as possible in your calculations.

ECE 3411 Fall 2015, Quiz Page 4 of 10 2. [40 points]: Given that the clock frequency (clk I/O ) of ATmega328P is 16MHz, implement the finite state machine (FSM) shown in Figure 1. The state transitions are made whenever a button connected to INT0 pin (i.e. PD2) is pushed and a Falling Edge is detected at INT0. Each state produces an output signal at PB2, and the output specifications of the states are as follows: State A: PB2 stays at logic LOW level. State B: A non-inverting 1kHz PWM signal with 30% duty cycle is generated at PB2. State C: A non-inverting 2kHz PWM signal with 70% duty cycle is generated at PB2. FallingEdge == NO State_A FallingEdge == YES State_B FallingEdge == NO FallingEdge == YES State_C FallingEdge == YES FallingEdge == NO Figure 1: State Transition Diagram of the FSM Figure 2: ATmega328P Hardware Configuration. Assuming that the push button does not need debouncing, complete the following code segments.

ECE 3411 Fall 2015, Quiz Page 5 of 10 The following code snippet provides the necessary includes, declarations, definitions and a basic layout. /*********** ECE3411 Quiz 5, Task 2 ************/ #define F_CPU 16000000UL #include <avr/io.h> #include <inttypes.h> #include <avr/interrupt.h> // For State Machine #define State_A 1 #define State_B 2 #define State_C 3 volatile uint8_t System_State; // For PWM volatile uint16_t time_period; volatile uint16_t duty_cycle; // Define any other variables here //----------------------------------------------------------------------- /* Triggers at Falling Edge on PD2 */ ISR(INT0_vect) // Calls state transition function make_state_transition(); } //----------------------------------------------------------------------- // Timer 1 Compare Match A ISR (TCNT1 = OCR1A) ISR (TIMER1_COMPA_vect) OCR1A = time_period; // Update PWM time period OCR1B = duty_cycle; // Update PWM duty cycle } //----------------------------------------------------------------------- /* Main Function */ int main(void) initialize_all(); sei(); while(1); // Initialize everything // Enable Global Interrupts // Nothing to do. } /* End of main() */

ECE 3411 Fall 2015, Quiz Page 6 of 10 A. Initialization: (20 points) Complete the function initialize all(void) as instructed below: /* Initialization function */ void initialize_all(void) // Initializing the state variable System_State = State_A; /* Configure PB2 here */ /* Configure INT0 here */ /* Configure Timer 1 here */ /* Any other initializations here if needed */ } /* End of initialize_all() */

ECE 3411 Fall 2015, Quiz Page 7 of 10 B. State Transition Function Implementation: (20 points) Write the function make state transition() to implement the FSM. /* State transition function called by INT0 ISR */ void make_state_transition() } /* end of make_state_transition() */

ECE 3411 Fall 2015, Quiz Page 8 of 10 3. [20 points]: Given that clock frequency (clk I/O ) of ATmega328P is 8MHz. Assume the following about the code snippet given below: Each one of instruction 1, instruction 2,..., instruction 52 takes 4 CPU cycles. Evaluating while(1) statement takes zero CPU cycles. Evaluating if(!(adcsra & (1<<ADSC)) ) statement and executing its body take zero CPU cycles. /*********** ECE3411 Quiz 5, Task 3 ************/ #define F_CPU 8000000UL #include <avr/io.h> /* Main Function */ int main(void) /* Configuring ADC Control and Status Register A */ ADCSRA = 0x86; while(1) instruction_1; instruction_2; instruction_3;...... instruction_52; if(!(adcsra & (1<<ADSC)) ) ADCSRA = (1<<ADSC); } } /* End of while(1) Loop */ } /* End of main() */ // Start A to D Conversion Answer the following questions about the code snippet.

ECE 3411 Fall 2015, Quiz Page 9 of 10 a. Given that it takes 13 ADC cycles, how much time (in microseconds) does it take to complete one ADC conversion? b. What prevents the condition if(!(adcsra & (1<<ADSC)) ) from being satisfied? c. How much time (in microseconds) does it take to complete one iteration of while(1) loop? d. What is the percentage of while(1) loop iterations for which the body of if(!(adcsra & (1<<ADSC)) ) condition is executed?

ECE 3411 Fall 2015, Quiz Page 10 of 10 End of Quiz Please double check that you wrote your name on the front of the quiz.