DOC PREVIEW
PSU EE 200 - final_s13

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 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 18 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 18 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 18 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 18 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 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

blanksolutionsEE 200 Final Exam 30 April 2013Last Name (Print):First Name (Print):ID number (Last 4 digits):Section:DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SOProblem Weight Score1 252 253 254 25Total 100INSTRUCTIONS1. You have 2 hours to complete thi s exam.2. This is a closed book exam. You may use one 8.5”× 11” note sheet.3. Calculators are allowed.4. Solve each part of the problem in the space fol lowing the question. If you need more space, continue your solutionon the reverse side labeli ng the page with the question number; for example, Problem 1.2 Continued. NOcredit will be given to soluti ons that do not meet this requirement.5. DO NOT REMOVE ANY PAGES FROM THIS EXAM. Loose papers w ill no t be accepted and agrade of ZERO will be assigned.6. The quality of your analysis and evaluation is as i mportant as your answers. Your reasoning must be preciseand clear; your complete English sentences should convey what you are do ing. To receive credit, you mustshow your work.1Problem 1: (25 Points)1. (13 points) Complete the function in Figure 1 to assign the peripherals pins of a dsPIC33EP64MC502 micro-controller as follows:• Assign pin 2 and pin 26 for digi tal input.• Assign pin 6 and pin 7 for digital output.For each line a code, include a short comment describing its purpose.void initialize_DIO _ports(void) {}Figure 1: Function for initializing DIO ports.22. (12 points) Consider the microcontroll er code in Figure 2 on page 4 that calls the C function in Figure 1.(a) (2 points) Determine the value of int x in the expressionint x = PORTAbits.R A0 + 2* PORTBbits.RB15 ;if pin 2 is connected to VSSand pin 26 is connected to VDD.(b) (4 points) If the value of int x is three, approximate the time, in units of seconds, it will take f or the innerwhile loop to complete execution each time it is called.(c) (6 points) If the voltage at the inputs pins 2 and 26 are fixed so tha t int x is two, what is the approximateperiod a nd duty cycle of the square-wave signal generated at pin 6?3int main(void) {int int_x;initialize_DIO_ports();while (1) {int_x = PORTAbits.RA0 + 2*PORTBbits.R B15;while (int_x > -1) {switch(int_x){case 0: PORTBbits.RB2 = 0; PORTBbits.RB3 = 0; break;case 1: PORTBbits.RB2 = 1; PORTBbits.RB3 = 0; break;case 2: PORTBbits.RB2 = 0; PORTBbits.RB3 = 1; break;case 3: PORTBbits.RB2 = 1; PORTBbits.RB3 = 1; break;} // end of swi tch st atementint_x = int_x - 1;__delay_ms(1000);} // end of inner while loop} // end of outer while loop} // end of main functionFigure 2: Microcontroller C-code.4Problem 2: (25 Points)Figure 3 on page on page 6 shows C-code for realizing a Moore finite state machine.1. (2 points) What are the input and and output signa ls to the finite state machine in terms of RAx and RBx.2. (3 points) How many states does this Moore machine use?3. (10 points) Write out the state table.4. (10 points) Sketch the state diagram.5typedef enum {S0, S1, S2, S3} S;S s = S1;int main(void) {int z;initialize_DIO_ports();while (1) {z = PORTAbi ts.RA0;switch (s) {case S0:switch (z) {case 0: s = S0; break;case 1: s = S1; break;}; break;case S1:switch (z) {case 0: s = S2; break;case 1: s = S3; break;}; break;case S2:switch (z) {case 0: s = S0; break;case 1: s = S1; break;}; break;case S3:switch (z) {case 0: s = S2; break;case 1: s = S3; break;}; break;}switch (s) {case S0: LATBbits.LATB0 = 0; break;case S1: LATBbits.LATB0 = 1; break;case S2: LATBbits.LATB0 = 0; break;case S3: LATBbits.LATB0 = 0; break;}__delay_ms(1000);}}Figure 3: Microcontroller C-code for implementing a Moore finite state machine.6Problem 3: (25 Points)In this problem you will modify the code in Problem 2 to include an asynchronous reset input connected to pin 26.When the logic level transitions from high to low on pin 26, the finite state machine must be immediately placed instate S1.1. (13 points) The function in Figure 4 initializes the interrupt controller so that a falling edge o n pin 26 generatesan interrupt using external interrupt 2 (INT2). Compl ete the C-code by filling in the dashed lines withappropriate numerical constants and comments.void initialize_Int errup t_Con troller(vo id){RPINR1bits.INT2R = _______; // _____ ______________________INTCON2bits.GIE = 1; // set global interrupt enableINTCON2bits.INT2EP = _______; // _ __________________________IFS1bits.INT2IF = 0; // clear interru pt flagIEC1bits.INT2IE = 1; // enable interr upt}Figure 4: Function for initializing INT2.2. (12 points) Complete the interrupt service routine (ISR) in Fig ure 5. The ISR must place the system in stateS1 and appropriately set the finite state machine output.void __attribute__( (__in terru pt__,auto_ psv)) _INT2Interrupt (void){}Figure 5: Interrupt service routi ne.7Problem 4: (25 Points)Figure 6 on page 9 shows code similar to that used in Laboratory #25 to implement an LED dimmer. In thisexperiment, a m echanical encoder generates quadrature signals QEA and QEB that are read by the microcontrollerto determine the percent duty cycle of a PWM output signal. Complete the code in Figure 6 by completing thefollowing tasks.1. (12 points) Determine the value of the register RPINR14 , in hexadecimal format, so that the quadrature inputssignals QEA and QEB can be connected to pins 6 and 7, respectively.RPINR14 = 0 ×2. (13 points) The original code is written so that a 360◦rotation of the mechanical encoder shaft sweeps theduty cycle from 0% to %100. Modify the co de so that a 720◦rotation o f the mechanical encoder shaft sweepsthe duty cycle from 0% to %100.(a) (3 points) Circle the two lines o f code in Figure 6 that must be modified.(b) (4 points) In two or three sentences, justify why the circled lines require modification.(c) (6 po ints) In the space below, write and comment the modified code lines.8int main(void) {/**** Setup PWM Module ****/PTCONbits.PTEN = 0; /* disable the PWM module */PTPER = 7370; /* period as a m ultiple of clock cycles, */IOCON1bits.PMOD = 1; /* PWM1 I/O pin pair is in redundant mode */IOCON1bits.PENH = 1; /* PWM module controls pin 25, PWM1H */IOCON1bits.POLH = 0; /* PWM1H is active high */PWMCON1bits.ITB = 0; /* PTPER register spec ifies period */PWMCON1bits.MDCS = 0; /* PDC1 register specifies duty cycle */PWMCON1bits.MTBS = 0; /* PWM uses primast er time base as the clock source*/PWMCON1bits.CAM = 0; /* Enable edge-aligned mode */FCLCON1bits.FLTMOD = 3; /* fault input disabled */PTCON2 = 0x0000; /* PWM input clock p rescaler: divide by 1 */PTCONbits.PTEN = 1; /* enable


View Full Document

PSU EE 200 - final_s13

Download final_s13
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 final_s13 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 final_s13 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?