DOC PREVIEW
PSU EE 200 - Lab_16_EE200_s14

This preview shows page 1-2-3-4-5-32-33-34-35-64-65-66-67-68 out of 68 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 68 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ColorGrayscaleEE 200 Spring 2014Lab 16.EE 200Design ToolsLaboratory 16Professor Jeffrey SchianoDepartment of Electrical Engineering1EE 200 Spring 2014Lab 16.Laboratory 16 Topics• Hardware Realization using a Microcontroller– Implementing finite state machines • Realizing Asynchronous Resets using Polling• Realizing Asynchronous Resets using Interrupts– Peripheral Pin Select feature2EE 200 Spring 2014Lab 16.Realization of a FSM in C• Use nested switch statements within a while–loop– Directly analogous to LabVIEW which uses nested case structures within a while-loop structure• Outer-level switches on the current state• Inner-level switches on the input3EE 200 Spring 2014Lab 16.Lab 4 Parity Detector• A string of bits has even (odd) parity if the number of 1’s in the string is even (odd)4INPUTOUTPUTCLOCKEE 200 Spring 2014Lab 16.Lab 4 Parity Detector Design FSM50S/01S/11100State DiagramPresentStateInputNextStateOutput0011010101100011EE 200 Spring 2014Lab 16.Exercise 1• Complete the C code in the Exercise_1.X directory• A tactile switch connected to pin 2, RA0, generates the input• Place a 1 in the bit stream by depressing the button which drives RA0 to a logic low state• Place the parity detector output on pin 3, RA1• Improve the readability of the code by using an enumerated type to represent the system state• Read the input and update the state every second using the __delay_ms() function6EE 200 Spring 2014Lab 16.Exercise 1 dsPIC33 Connections7330RA012345678910111213142827262524232221201918171615dsPIC33EP64MC502-I/SP27 kΩDDV = 3.3VRA1PARITY LED Even Off Odd OnPress to add a 1 to the bit streamEE 200 Spring 2014Lab 16.Exercise 1 Code8• Use the XOR operator to invert the input logicEE 200 Spring 2014Lab 16.Exercise 1 Verification9• Compile and deploy the program to the microcontroller• Holding the button down should cause the LED to alternately flash on for one second, and then off for one secondEE 200 Spring 2014Lab 16.Realizing an Asynchronous Reset• Suppose the FSM requires an asynchronous reset input• Without waiting for the next clock cycle, as soon as the reset line is asserted, the FSM must be placed in a specified reset state• Using discrete-logic or the CPLD, an asynchronous reset is typically implemented using either the reset orset inputs of the flip-flops• How do we implement an asynchronous reset in C?10EE 200 Spring 2014Lab 16.Implementing Asynchronous Resets for a FSM Realized in C• Method I: Polling– While waiting for the next clock tick, continuously poll (read) the reset line and take appropriate action when it is set• Method II: Hardware Interrupt (preferred approach)– An interrupt is a signal that commands the microcontroller to immediately execute a sequence of code known as the interrupt service routine (ISR)– The ISR immediately changes the state and output11EE 200 Spring 2014Lab 16.Exercise 2• Complete the code in the directory Exercise_2.X so that it realizes an asynchronous reset using polling• The reset is triggered when RB15 (pin 26) is set to logic low when the reset button is pressed• When the reset is asserted, return the FSM to state S0 and set the output to 0• Poll the reset line every ten milliseconds• Update the state every second using the __delay_ms() function12EE 200 Spring 2014Lab 16.Exercise 2 dsPIC33 Connections13RA012345678910111213142827262524232221201918171615dsPIC33EP64MC502-I/SP27 kΩDDV = 3.3VRA1PARITY LED Even Off Odd Onpress to add a 1 to the bit streamRB1527 kΩ330press to resetEE 200 Spring 2014Lab 16.Exercise 2: Modifications to Exercise 1 Code14EE 200 Spring 2014Lab 16.Exercise 2 Verification15• Compile and deploy the code to the microcontroller• Momentarily hold the input button down so that the system enters and remains within state S1 (LED on, odd parity)• Press the Reset button and verify the system resets to State S0 by noting that the LED turns offEE 200 Spring 2014Lab 16.Disadvantages of Polling• Inefficient use of microcontroller processing time– Polling requires frequent checking of an input to see whether its state has changed• Delayed response and missed events– The microcontroller is unaware of a change in the input until polling occurs– If the input toggles between polling instants, the program will miss the change16EE 200 Spring 2014Lab 16.Interrupts• An interrupt allows the flow of program execution to be modified by an external event asynchronously• When an interrupt request (IRQ) occurs program execution jumps directly to the code that services the interrupt• The code executed when an interrupt occurs is called an interrupt service routine (ISR) or interrupt handler17EE 200 Spring 2014Lab 16.Program Execution• Without Interrupts• With Interrupts18Main ProgramtimetimeMainMain MainISR ISRIRQ IRQEE 200 Spring 2014Lab 16.Advantages of Interrupts• Allows fast response (low latency) of a program to external events• Simplifies programming when interfacing to external devices with strict timing requirements• Allows systems to operate in real-time19EE 200 Spring 2014Lab 16.dsPIC33 Interrupts: Introduction • Up to eight processor exceptions and software traps• Up to three external interrupt pin sources (INT0-INT2)• Interrupt Vector Table (IVT) with up to 254 vectors• Seven user-selectable priority levels20EE 200 Spring 2014Lab 16.dsPIC33 Interrupt Vector Table21• From Figure 7.1 in the dsPIC33 data sheetEE 200 Spring 2014Lab 16.dsPIC33 Interrupt Vector Details22• From Table 7.1 in the dsPIC33 data sheet• The exercise for Lab 19 uses external interrupt 1EE 200 Spring 2014Lab 16.dsPIC33 External Interrupt Sources• INT0 is only available on pin 16• INT1 and INT2 are mappable to any RPn or RPIx pin using the peripheral pin select input registers RPINR0 and RPINR1, respectively23AN0/OA2OUT/RA0AN1/C2IN1+/RA1MCLRPGED3/VREF-/AN2/C2IN1-/SS1/ /CTED2RPI32/RB0PGEC3/VREF+/AN3/OA1OUT/ /CTED1RPI33/RB1PGEC1/AN4/C1IN RPI31+/ 4/RB2PGED1/AN5/C1I RP35N1-/ /RB3VSSOSC1/CLKI/RA2OSC2/CLKO/RA3RP3FLT32/ 6/RB4RP2CVREF20/ /T1CK0/RA4VDDPGED2/ASDA2 RP37//RB5AVDDAVSS/PWM1L/T5CK/RPI47 RB15/PWM1H/T3CK/RPI46 RB14/PWM2L/CTPLS/RPI45 RB13/PWM2H/RPI44 RB12TDI/ /PWM3L/RP43 RB11TDO/ /PWM3H/RP42 RB10VCAPVSSTMS/ASDA1/SD RP4I1/ 1/RB9TCK/CVREF10/ASCL1/SDO1/ /T4CKRP40/RB8SCK1/ /INT0RP39/RB7PGEC2/ASCL2 RP38//RB612345678910111213142827262524232221201918171615dsPIC33EP64MC502-I/SPEE 200 Spring


View Full Document

PSU EE 200 - Lab_16_EE200_s14

Download Lab_16_EE200_s14
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab_16_EE200_s14 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab_16_EE200_s14 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?