Emb Microcontroller Dsgn
Emb Microcontroller Dsgn ECE 4175
Popular in Course
Popular in ELECTRICAL AND COMPUTER ENGINEERING
This 0 page Class Notes was uploaded by Cassidy Effertz on Monday November 2, 2015. The Class Notes belongs to ECE 4175 at Georgia Institute of Technology - Main Campus taught by John Peatman in Fall. Since its upload, it has received 19 views. For similar materials see /class/233857/ece-4175-georgia-institute-of-technology-main-campus in ELECTRICAL AND COMPUTER ENGINEERING at Georgia Institute of Technology - Main Campus.
Reviews for Emb Microcontroller Dsgn
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 11/02/15
MEMO TO ECE 4175 students March 13 2009 FROM John Peatman SUBJECT Second quiz on Wednesday March 25quot Open book open notes Paul Abbott Ben Wallingford and Bren Whitfield will hold a review session in room C340 on the Tuesday after Spring Break from 430600 PM In addition to glancing over the review sheet for the first quiz review the quizzes and final exams from the last two semesters available from the piclab website Remember that the sequencing of topics in the course changes from semester to semester and that is the reason to look at the review sheet associated with each quiz and final exam Both the 900 class and the 1000 class will again be taking the same quiz If you take the quiz at 900 do not talk about the quiz or otherwise divulge information about the quiz as you leave If you are in the 1000 class do not press the 900 students with questions about the quiz Thanks I plan to begin each quiz at 3 minutes after the hour ie 903 and 1003 and end at 3 minutes before the hour ie 957 and 1057 unless someone comes to me no later than Monday March 23rd to raise an objection OK Bring a printed copy of the textbook either the Lulu print on demand copy or the free computer center printout Do not plan on being able to refer to the book on your notebook computer Be sure to bring your source les for all of the projects I will assume that you are familiar with the kinds of things that arise on each of the projects as well as Part A of the Design Project You will need to print out the source les for each of your team regardless of who has the folder that you turned in Read through the chapterssections of the book that we have discussed in class Review chapters 7 Alphanumeric Liquid Crystal Displays 13 Time Interval Measurements and 16 Output Time Interval Control from my earlier book for the sections we have discussed in class I do plan to ask you questions that have to do with the debugging that you have done or should have done in the lab You should be able to write C code to do the kinds of things for which you have had to write code on the projects I will not ask you to write assembly code or to understand the stuff of Appendix A2 or to understand the qwiklst file generated by the c18 wrapper For Project Six you used the stepper motor as a position controlling actuator stepping exactly 800 steps ie exactly four revolutions and stopping for three seconds before continuing While stopped you could change the step rate with the pot input Thus you could check the maximum step rate before steps are missed For Part A of the Design Project you populated the QampL Development Board and then checked that it could produce an output on the LCD You also checked the current draw on the 9V battery with a DeVPV program both while running the LCD and with the LCD disconnected You also executed a SleepTest program that shut down everything so that you could check the sleep current that should be well below 1pA looking for the quality of your soldering and your washup afterwards to remove conductive water soluble solder ux Review these two programs For Project Seven you added an RPG to the QampL Devel Ed and developed a test program that tested the RPG and displayed the results on the LCD For Project Eight you tested the LCD for bad pixels and for shorted or open pins by displaying checkerboard arrays of pixels as well as vertical and horizontal lines You used the RPG to generate a number between 1 and 6 to cycle through the choices using a switch statement OVER MEMO TO ECE 4175 students February 8 2008 FROM John Peatman SUBJECT First quiz on Wednesday February 13quot Open book open notes Cody Planteen Andrew Ray and Bren Whitfield will hold a review session in room C241 our classroom on Monday from 700900 PM Also review the first quiz from last semester available from the piclab website While the course is drastically different at least you may get an idea of the kinds of questions I ask Both the 900 class and the 1000 class will be taking the same quiz If you take the quiz at 900 do not talk about the quiz or otherwise divulge information about the quiz as you leave If you are in the 1000 class do not press the 900 students with questions about the quiz Thanks I plan to begin each quiz at 3 minutes after the hour ie 903 and 1003 and end at 3 minutes before the hour ie 957 and 1057 unless someone comes to me no later than Monday to raise an objection OK Be sure to bring your source les for all of the projects I will assume that you are familiar with the kinds of things that arise in all of the projects up through Project Five You will need to print out the source les for each of your team regardless of who has the folder that you turned in Also bring the qwiklst le for Project Four Review David Bauer s Hints on doing well in ECE 4175 posted on the piclab website Read through Chapters 1 2 3 4 5 6 7 Sections 91 to 96 and Appendix A2 I do plan to ask you questions that have to do with the debugging that you have done or should have done in the lab You should be able to write C code to do the kinds of things you have had to write code for on the projects I will not ask you to write assembly code However given the information in Appendix A2 you should be able to determine the execution time of a short segment of assembly code that the C compiler has generated into the qwiklst le For Project One you used the pushbutton in a rudimentary way taking action as long as the pushbutton was pressed Subsequently you took action in response to the leading edge of a pushbutton press All of our code examples use the brownout reset functionality of Figure 4 3 assuming that the chip powers up into our code to help ensure reliable startup When we use the chip Via QwikBug this dealing with the brownout reset really doesn t serve this function since QwikBug has already turned off the brownout reset We have used the Sleep state of the CPU waking up with either the watchdog timer s timeout or with Timer139s interrupt We have talked about the internal clock and how it can be controlled Refer to Figure 2 3 We also talked about the role of clock rate versus the average current draw to execute a xed number of instructions before returning to sleep for the remainder of the loop time We have also talked about the watchdog timer and its possible control with a Configuration option and the control we have actually used with a SWDTEN bit in the WDTCON register Refer to Figure 2 6 We have discussed the debouncing of a mechanical switch Refer to Figure 2 7 You should understand the rationale for the device connections of Figure 3 2 for the parts we have used Know how to set a bit clear a bit toggle a bit and test a bit for both a bit in a SFR Special Function Register and a ag bit defmed in RAM e g LCDFLAG Understand when and how to recast a variable from a char to an int etc in a mathematical expression The 4321 chip uses its Serial Peripheral Interface to send ASCII coded characters to the starburst LCD You should understand the role of the 432139s RDS pin in this process as well as how the SPI works for these transfers With our simple message protocol we always send nine characters for an eight character display Why For Project Two you used each push of the pushbutton to double the step rate of the stepper For Project Three you used a rate multiplier scheme to increment the step rate from 1 ss up to 62 ss You also measured how long the CPU remains awake during each loop time doing useful work For Project Four you used high priority interrupts to produce 16 ms tick times and then used these interrupts to reuse the rate multiplier scheme of Project Three to produce step rates from 10 s s up to 620 ss in increments of 10 ss For Project Five you used the output of the pot to set the step rate no longer using the rate multiplier scheme Now you translated the pot value into a step rate display and a number of counts of Timer3 between interrupts and thereby the interval between steps TimerO necessarily requires us to use its buffer register TMROH if we want to read out the content of the timer or write to it What is the intent of the buffer register in general What is the effect of the buffer register if we stop the counter while we read from or write to the counter Consider the TXascii macro called from within the Measurec file What is the effect of waiting for the setting of the TRMT bit before exiting and going to sleep We have looked at a bunch of ways to convert a NUMBER of a given size into UNITS TENS HUNDREDS etc ASCII characters You should have a pretty good idea of what helps to minimize the cycle count of an algorithm to do this On the projects we have dealt with the LED the pushbutton the pot and its use with the ADC as both an 8 bit input and a 10 bit input device the LCD as well as individual output pins e g RBO None of these interactions should hold any mysteries for you Timerl and Timer3 offer an option not available for TimerO of buffering the upper byte of the counter Whereas the circuitry for TimerO forces the use of this buffering we chose not to use either one with Timerl or Timer3 What went into this choice given how we used Timerl and Timer3 When this buffering feature is used what is it good for If the chip is asleep when the watchdog timer times out the CPU just picks up with the execution of the next instruction after the Sleep macro If the chip is awake when the watchdog timer times out the CPU is reset and starts over from address OxOOOO Timerl and Timer3 generate interrupts whether or not the chip is asleep The CPU awakens vectors to the respective interrupt service routine executes it and then returns from the interrupt back to the next instruction in the code that was executing at the time of the interrupt reenabling the interrupt for that timer in the process 15 10 9 4 16 ECE 4175 QUIZ 21308 1 of2 High 115 SEVEN PROBLEMS Upper quarter 97 Open book open notes Median 79 Lower quarter 68 I added in a variable amount to the grades Low 59 ranging from 5 for grades above 90 to 15 for grades below 71 Assume that we have defined a flag variable called READY whose value is either non zero ie 1 or zero Show the C code below to test READY and repeatedly execute lta sequence ofinstructionsgt until READY is non zero Presumably the sequence of instructions will eventually set READY but you can assume that READY is initially zero while1READY or whileREADY 0 lta sequence of instructionsgt Assume you have just added a new function NewFunction to code that previously worked correctly Now you find that NewFunction causes the MCU to hang and never return to the main loop from which it was called Describe how you might use QwikBug to discern what is going wrong Set a breakpoint at NewFunctioni Single step through NewFunction to see where it hangs or loopsi Set a breakpoint on a line that only executes when it breaks out of the loop Then run to the breakpoint to see if it ever breaks out If not set up a watch variable for any variable that affects the exit from the loop Set a breakpoint within the loop and run to the breakpoint repeatedly to see what is happening to the watch variable from loop to loop The TXascii macro is used in the Measurec template program of Chapter 6 to send a byte from the MCU to the PC The Send function used there includes six successive executions ofthis TXascii macro Ifthe TXascii macro definition did not include the statement wh eUTXSTAbhsTRMT then what would the effect be upon what would be displayed in QwikBug s console window Explain youranswer The Key to this problem is Figure 64 which describes the role of TXREG TSR and the TRMT flagi When a byte is written to TXREG while TSR is empty the byte is immediately dropped into TSRT Subsequent bytes written to TXREG can overwrite each other until the transfer from TSR has been completed without messing with the content of TSR1 Of course shortly after the exit from the final Send occurs the CPU goes to sleep Killing the reception of any byte in the process of being sent For the Measureic program the first character sent is a carriage return code which produces no display1 Because of the delays caused by the computations the CPU remains awake for some multiple of the half millisecond interval needed to send a single character I checked and found that three displayable characters showed up in the Console window I tried another experiment sending the six digits 123456 but then remaining awake thereafter The 1 and the 6 showed up in the Console window The rate multiplier scheme used on Projects 3 and 4 produced an action ie making the stepper motor take a step at a rate determined by how often it was called and the value ofRATE when it is called Assume that the rate multiplier code is executed each time around a mainline loop that has been set up to take ten milliseconds using the Timer1 oscillator and that the RATE parameter can take on any value between 1 and 120 When the subtraction ofRATE from ACCUM produces a negative result add 120 to ACCUM and take action What is the maximum number oftimes the action is taken per second and what value of RATE produces this rate Maximum 100 second RATE What is the minimum number oftimes the action is taken per second and what value of RATE produces this rate Minimum 01833second RATE 95 10 15 ECE 4175 QUIZ 21308 2 of2 Consider the code below taken from the qwiklst file for a modified version ofthe T3c template program For high priority interrupts pragma code highvector0x08 void interruptathighvectorvoid 3 2 0008 EF24 GOTO HiPriISR asm GOTO HiPriISR endasm 000A F000 2 0048 CFDA MOVFF FSRZHPREINC1 void HiPriISR 004A FFE4 1 004C 52E6 MOVF POSTINC1F a a 39 a 1 0050 5007 MOVF STEPCNTLW TMR3L STEPCNT 1 0052 6EBZ MOVWF TMR3L 1 0054 5008 MOVF STEPCNTHW TMR3H STEPCNT256 1 0056 6EB3 MOVWF TMR3H 005A 92A1 BCF PIR21 PIRZbitsTMR3IF 0 005C 8283 BSF PORTD1 PORTDbitsRD1 1 005E 9283 BCF PORTD1 PORTDbitsRD1 0 0060 7081 BTG PORTB0 PORTBbitsRBO A 1 0062 52E5 MOVF POSTDEC1F 0064 CFE5 MOVFF POSTDEC1FSR2H 0066 FFDA 0068 0011 RETFIE FAST Consider the possible consequences of not stopping the counting of Timer3 and also of reloading rather than adding into TMR3H2TMR3L Assume that it takes a maximum ofthree cycles ofthe CPU after Timer3 rolls over and before the CPU has fetched the instruction at the high priority interrupt vector address 0x0008 and is ready to execute it Cross out the instruction above that stops the counting of Timer3 and the instruction that starts the counting of Timer3 again How many CPU clock cycles can occur after Timer3 rolls over and before the above code will have reloaded TMR3HTMR3L with the content of STEPCNTHSTEPCNTL In answering this to the left of each line above that is executed until TMR3HTMR3L has been reloaded write the number of cycles executed for that line Cycles 12 How many microseconds will pass after Timer3 rolls over until Timer3 is incremented again by the 32768 kszatch crystal Microseconds Given this will reloading Timer3 rather than stopping Timer3 and adding into it always work Explain your answer briefly Yes we are assured that Timer3 will not be reloading at the same time that it is counting The T2c template program of Chapter 5 uses the pushbutton to increment a number displayed on the LCD one increment per press ofthe pushbutton For this to work correctly the maximum contact bounce time ofthe pushbutton must satisfy what requirement Be specific t must be less than the loop time which is 16 ms for T2c Assume that in one of your projects you want to display the following message on the LCD display each time you detect a new condition has been fulfilled and before displaying the new data NEW DATA Show the code you would use to do this making use of the LoadLCDSTRING macro LoadLCDSTRING NEW DATA Display MEMO TO ECE 4175 students March 14 2008 FROM John Peatman SUBJECT Second quiz on Wednesday March 263911 Open book open notes Cody Planteen Andrew Ray and Bren Whitfield will hold a review session in room C241 our classroom on Monday from 700900 PM Also review the quizzes and final exam from last semester available from the piclab website Both the 900 class and the 1000 class will be taking the same quiz If you take the quiz at 900 do not talk about the quiz or otherwise divulge information about the quiz as you leave If you are in the 1000 class do not press the 900 students with questions about the quiz Thanks I plan to begin each quiz at 3 minutes after the hour ie 903 and 1003 and end at 3 minutes before the hour ie 957 and 1057 unless someone comes to me no later than Monday to raise an objection OK Be sure to bring your source files for all of the projects I will assume that you are familiar with the kinds of things that arise in all of the projects up through Project Ten You will need to print out the source files for each of your team regardless of who has the folder that you turned in Read through the remainder of the book except for Chapter 14 on EEPROM and Chapter 16 on the LCD and the appendices A1 A3 and A4 Be sure to bring the book in either Lulu or Techprinted form I will not ask you to write assembly code However given the information in Appendix A2 you should be able to determine the execution time ofa short segment of assembly code that the C compiler has generated into the qwik1st file You should also understand the functioning of short assembly code sequences I will avoid the cryptic stuff involving interna1 function calls like the math functions and the variables that are introduced by the compiler to deal with them For Project Six you decreased the INTOSC frequency from 4 MHz to 1 MHz while sending bytes to the PC What was this attempting to do and what was the result For Project Seven you used the RPG to scroll an eightcharacter window over the sixteenhexcharacter si1icon seria1number For Project Eight you used a ratesensitive RPG scheme to change the stepping rate of the stepper motor For Project Nine you compared different implementations ofa linear equation looking at the qwik1st file to discern how the c18 compiler is handling each implementation For Project Ten you calibrated the HLVD feature of the PIC chip You should go back and read the data sheet on this feature and understand what it is for and how it works Chapter 12 deals with interrupts You should understand how to deal with an interrupt source with either a high or a low priority interrupt and how the structuring ofthe interrupt service routine can affect the code generated by the C compiler The use of a critical region of code is a topic that should have been in Chapter 12 We discussed this last Monday in conjunction with the Timer1Check function where we wanted to take action within microseconds after an event occurred so we disab1ed interrupts to make sure that code was not postponed momentarily by an intervening interrupt Chapter 15 deals with Dallas Semiconductor s 1wire interface used by the silicon serial number part and also by Dallas Semi s iButtons We discussed the implementation of opendrain outputs from the MCU to communicate with these devices We also discussed how a multiplebyte protocol that is specific to a device like the DS2415 time chip can be used to read from it or write to it OVER Chapter 10 deals with two RPGs The detented unit on the QwikampLow board operates best with interrupt servicing The Bourns unit available to you for the design project makes good use of a polling routine You should understand this distinction and why each RPG is handled in its own way The latter part of Chapter 9 deals with a linearization process and how its careful implementation with integer arithmetic by the C compiler can drastically simplify its execution time Chapter 17 expands on the SP1 concepts introduced in Chapter 5 to deal with the LCD We discussed the choice of CKP and CKE to match the MCU to the needs of a device to which we want to send information We also discussed the choice of CKP CKE and SMP to read in data reliably from a device Note that some devices want to receive a clock edge before the first data bit is read while others expect that first bit to be read before the first clock edge And note the choice ofparameters for either case Some devices expect the MCU to carry on simultaneous input and output transfers using the MOSIMISO scheme discussed in conjunction with the modes of Figure 171 1 Chapter 8 explains how a bipolar stepper motor works with a multiplepole magnetized rotor and a multiplepole stator designed so that the appropriate energization of its two windings moves the poles CW or CCW a step at a time It also explains how currentsensing resistors are used to set the current in the windings rather that having the current set by the motor s supply voltage Chapter 1 1 introduces macros for starting and stopping a pulse so that a scope can be used to measure time intervals We have done the same thing on multiple occasions by just setting and clearing the output to a pin that can then be monitored by the scope We also used this scheme in conjunction with the scope s Autostore mode to check worstcase time intervals The latter part of Chapter 13 introduces the cyclecounting Start Stop and Send functions first used in the Measureic template program of Chapter 6 We haven t dealt with the first part of Chapter 13 wherein the INTOSC internal oscillator ofthe MCU is calibrated against the much more accurate 32768 Hz 50 ppm TMRl oscillator I won t address this calibration on the quiz We have discussed Chapter 16 taken from my previous book and the IZC bus Its use is discouraged with the QwikampLow board because the same MCU pins that control the 12C bus are already in use with the SP1 bus control ofthe LCD You should understand how it frames multiplebyte transfers and how it uses the first byte to address a specific chip A multiplebyte message is device specific requiring reference to that device s data sheet for information on how to send information to and receive information from the device 1 10 15 25 a ECE 4175 QUIZ 32608 1 of2 High 113 SIX PROBLEMS Upper quarter 87 Open book open notes Median 68 Lower quarter 58 I added 10 points to everyone s grade Low 35 Consider the following assembly code generated into a qwiklst file 014C 5039 MOVF RPGW 14E E103 BNZ L013 0150 0EOF MOVLW 0XOF 0152 6E39 MOVWF RPG 0154 D001 BRA L012 0156 0639 L013 DECF RPGF 0158 9084 L012 BCF PORTE0 Describe what this code sequence does to the RAM variable RPG If RPG is initially equal to zero it is reloaded with 0XOF ie Otherwise it is decremented 15 For Project Six you decreased the INTOSC frequency from 4 MHz to 1 MHz while sending five bytes tothePC If you had left INTOSC 4 MHz how long would it have taken to transmit the five bytes Each byte including its start and stop bits takes 1019200 seconds or 1000000019200 microseconds This computes to 521 microseconds or about 05 millisecond Five bytes thus take about 25 ms With INTOSC 1 MHz how long does it take to transmit the five bytes The same 25 Why does decreasing INTOSC from 4 MHz to 1 MHz while sending these five bytes to the PC decrease the average current draw on the coin cell Because in either case there is a 25 ms time chip draws a current determined by the clock rate Th mA for INTOSC 4 MHz and about 05 mA for INTOSC 1 MHz interval during which the at current is about 1 See Figure 24 We have discussed how a critical region of code must not be permitted to be interrupted That is while that section of code is being executed it must be allowed to proceed instruction by instruction with no intervening interrupt permitted to break the lock step ofthe instruction sequence For an application that makes use of no interrupt sources other than the single interrupt source INT2 the interrupt input from the RPG this can be achieved by inserting the following line of C code before the critical region of code Given that every interrupt has both a local enable control bit and a global enable control bit show the code that will locally disable this single interrupt source INTCON3bitsiINT21E 0 Show the line ofC code to locally reenable INT2 interrupts at the completion ofthe critical region of code INTCON3bitsINT21E 1 If an RPG is incremented during this time that INT2 interrupts are momentarily disabled will the CPU account for that increment ofthe RPG or is it lost forever The CPU will account for that increment of the RPG when INT2 reenabled For a different application that makes use of INT2 interrupts and also Timer3 overflow interrupts show the line that will globally disable all possible interrupts by clearing a single control bit INTCONbitsCIEH 0 Finally show the line of C code that globally reenables all interrupts at the completion ofthe critical region of code INTCONbitsCIEH 1 If a Timer3 overflow occurs during the time that all interrupts are globally disabled will the CPU account for this overflow of Timer3 or is it lost forever Using Figure 7 5 explain your answer The TMR3IF flag is set by the overflow Either the clearing of the local interrupt enable bit TMR3IE or the clearing of the global interrupt enable bit GIEH will block TMR3IF from reaching the CPU When GIEH is set again along with TMR3IE already being set the signal gets through to the CPU and produces the interrupt whose interrupt service routine will then account for the overflow interrupts are 20 10 6 20 a ECE 4175 QUIZ 32608 2 of 2 Serial interfaces that reach from the MCU to more than one peripheral device have two problems to be considered here 0 How does a specific device know that it is the one being addressed 0 How are the beginning and the ending of multiple byte messages marked For the serial peripheral interface how are these two problems handled The MCU designates the specific device that is to receive and act upon the multiplebyte message by making that device s chip enable pin active Usually the chip enable pin is active low so this means that the MCU pin that drives that chip enable pin has a zero written to The MCU precedes the sending of the multiplebyte message with the activation of the specific device s chip enable pin It terminates the message by deactivating that device s chip enable pin Furthermore because it is enabled the SSPIF flag will be set after each received byte For the IZC interface aka the SMBus how are these two problems handled The MCU indicates that a multiplebyte message is about to begin by transitioning the SDA and SCL lines through the 12C START condition That is the MCU first pulls the SDA line low and then the SCL line low from their initial state of both being high The end of the multiplebyte message is indicated when the MCU causes the SCL line to go high followed by the SDA line going high a change that is called the 12C STOP condition Each device on the 12C bus has its own unique sevenbit address Seven bits of the first byte of the multiplebyte message hold this sevenbit address The addressed device responds to the rest of the message All other devices on the bus ignore the rest of the message Consider a bipolar stepper motor whose rotor consists ofjust a single North pole and a single South pole The stator has two windings designated as A and B Full stepping is carried out by the following sequence of winding excitations where A and its complement represent current in one direction or the other through winding A A B A B A B What is the angle of rotation produced by each step How many steps per revolution does this sequence produce 4 Suppose that a transducer generates an output M ranging from O to 2047 The physical parameter N that is being transduced is related to M by the equation N 4321M342 Reexpress this relationship to avoid floating point math as well as division so as to minimize computation time while maintaining 1 part in 2048 resolution Multiply 4321M by XX where X is a power of 256 so that the division by X can be achieved by moving the numerator to the right by one byte position for 256 or two byte positions for 256x256 To maintain 1 part in 2048 resolution X 256x256 65536 is So N 6553665536 X 4321 X M 342 256 is not sufficient whereas X or N 283181M65536 342 Express the computation in C You can assume that M has been defined as a four byte long variable N 283181 Mgtgt16 342 If the C compiler implements this with bit shifts rather than byte moves use the following instead N 283181 M gtgt 8 gtgt 8 342 Michael Pribble and John Hamilton had this answer 8849 M gtgt to get the 1 part computation Many students used 2 11 in 2048 resolution However this doesn t minimize the MEMO TO ECE 4175 students April 25 2008 FROM John Peatman SUBJECT Final Exam Open book open notes If you are registered for ECE 4175A the 900 class your final exam will be held on Tuesday from 250540 If you are registered39for ECE 4175B the 1000 class your final exam will be held on Wednesday from 250540 Unless you have arranged with me to take the final exam for the other section I expect you to take the nal exam for the section for which you are registered In either case come to C241 our normal classroom As a part of the nal exam I plan to ask if you have completed the online CETL course evaluation Please do so Be sure to bring enough of the source les for all of the projects to be able to refer to all of the code you and your partner have developed Be prepared to write C18 code I can imagine asking you to code an algorithm Go over the review sheets for the rst and second quizzes The nal exam will cover the entire course You have a handout from my earlier book and we talked about the operation of a magnetic card reader We use an interrupt input to time the data bits and organize them into groups of ve ready to be translated into digits and a few eldde ning codes beginning with a and ending with a We have discussed a revised version of the MagCardc le dated 41408 to read and display the card You should understand how this works and think about how you would set a ag variable if the parity check failed for one of the vebit entities We have discussed the use of direct and multiplexed LCDs and the waveformsthat are used to turn on selected pixels You should understand what is going on and how the on and off RMS voltages that control each LCD pixel are calculated You have another handout from my earlier book Chapter 7 Alphanumeric LiquidCrystal Displays that discusses the use of a standard offthe shelf LCD module that uses 1 16 multiplexing It employs a Register Select pin that distinguishes between the reception of a cursor position control character and a displayable ASCIIcoded character at the time of the falling edge of the E clock pin We casually discussed an assembly language le 2321LCDasm or 2321Hitachiasm that initializes a 16x2 character LCD and then writes stuff out to each line The assembly code is for a fourbit nibble interface that requires the writing of two successive nibbles to form each byte In contrast consider the SP1 circuit being handed out today that uses a 74HC164 eightbit serialin parallelout shift register to present bytes not nibbles to the LCD Then consider what the C code would look like to send a string of characters to the display Also consider how to terminate such a function when the character read from the string is the null character 0x00 39 We considered a MAX1724 DCDC converter that would take the coin cell voltage of approx 3V and produce a regulated 33V output suitable for supplying the voltage to a 33V part that requires tight control of the voltage The example part that we used it with was a Tianma 16x2 LCD display whose 1 16 multiplexing required 33V and which displayed faded characters when powered directly om the coin cell Bren talked brie y about using a PWM pulsewidthmodulated output from a PIC chip to control an RC motor with a 50 Hz signal and a duty cycle between lms20ms 005 to 3ms20ms 015 We talked also brie y about the ability of the PIC chip to generate PWM outputs Bren pointed out that better control of the duty cycle can be obtained using the PIC chip s output compare feature together with interrupts to control the time of each edge of the PWM output I don t plan to ask you about this stuff since we did not go into it in suf cient detail That is I won t ask you about the applications of the PIC18F4321 data sheet for section 150 CaptureComparePWM CCP Modules nor the information in the handout from my last book Section 164 Fast jitterfree square wave output For the same lack of detailed consideration in class reason I won t ask you about the use of the PICl8LF432139s Timer2 addressed in the handout from my earlier book 163 Periodic Interrupt Generator 1 5 15 3 15 ECE 4175A Final 4 29 08 Page 1 of3 High 116 SEVEN PROBLEMS Upper quarter 95 Open book open notes Median 79 Lower quarter 68 Low 51 Ihave completed the CIOS course evaluation Ihave not completed the CIOS course evaluation The QwikLow board that we have used in previous semesters included a three digit seven segment numeric LCD that had to be updated every ten milliseconds The refreshing function might have employed the following macro to write the seven segment coding for each digit out to three serially connected 74HC595 shift registers via the Serial Peripheral Interface defihe Shiftout SSPIF 0 SSPBUF out whileSSPIF Consider the following code and assume that the SP1 has been set up to clock the SCK line at the maximum rate with a CPU clock rate of1 MHz ShiftOUTH SUM Load three 74HC595 shift registers ShiftOUTT SUM with sevensegment coding o ShiftOUTU SUM hundreds tehs and units digits PORTCbitsRCO 0 1 Toggle the 74HC595 latch clocks PORTCbitsiRCO 1 1 Above each instruction in the macro list your estimate ofthe number ofmicroseconds taken to execute that instruction Use one ofthe qwiklst files handed out with this final exam in class or obtained for one of the design projects to see how instructions equivalent to those above are executed 1 2 8 1 1 S U M 1 1 14 defihe Shiftout SSPIF 0 SSPBUF out whileSSPIF To the right of each ofthe five lines above list your estimate ofthe number of microseconds taken to execute that line If the MCU draws 1000 mA while executing instructions with a clock rate of1 MHz then determine the average current draw ofthe MCU contributed by this five line sequence when it is executed every ten milliseconds assuming that the MCU sleeps when it is done doing useful work each loop time Show all your work clearly I wake lOOOnA X 3XSUM210000 0113XSUM2nA SnA Consider the interrupt service routine listed below for dealing with the magnetic card reader with the MCU connections discussed in class MPHISR wtemupt gem Wtwe void hiPriISR INTCON3thSINT11F 0 Crear interrupt trag it 1PORTBthSRB3 Read in activeslow data so R83 0 represents bit 1 1 MAG BYTE 0b00100000 6th bit position Witt be shitted into 5th it znAG STATE This is the first 1 read from card 3 MAG CNT 40 Initiarize counter or no more than 40 bytes MAG STATE 1 Set trag to signar presence or data bytes MAG BYTE 0b00100000 Initia1 value MAG BITCNT 5 gt it MAG STATE Handle data bytes MAG BYTE gtgt 1 Shirt bits into position it VVMAG BITCNT 0 Act turther onry tor a compreted digit z MAG BITCNT 5 Reset tor next digit MAG BYTE 0x30 Convert to ASCII it MAG BYTE 3939 End sentinar n TE 7 Done With data Tgtltasci i MAG BYTE TXascii39r39 39 Carriage return tine teed TXaSCTl39n391 else if MAG STATE Z LRC character after end sentinat MAG STATE 0 e1se A data byte ir MAG CNT Send no more than 40 characters TXasciinAG BVTE 7 AG CNT Decrement sca1e or 40 counter next data byte MAG BYTE Reset byte for 90 95 ECE 4175A Final4 29 08 Page2of3 Mark with 1 A the place in the above code where you would insert a line of program code that will toggle the least significant bit of a char variable PARITYFLAG ifbit 3 of PORTB is read as a zero Show that line of program code here PARITYFLAG quot 0X01 Mark with 2 A the place in the above code where you would turn on a LED by setting bit 4 of PORTD leaving the other bits of PORTD unchanged if PARITYFLAG equals zero during the interrupt call when the fifth of each group of five bits occurs Show the code here if lPARITYFLAG PORTDbi ts i RD4 1 Mark with 3 A the place in the above code where you would turn off the LED by clearing bit 4 of PORTD leaving the other bits of PORTD unchanged when the swipe of a new card is begun as detected by the first time bit 3 of PORTB is read as a zero Show the code here PORTDbitsiRD4 A couple of groups in working on their design project had a part that expected bytes to be sent and received over the SP1 interface least significant bit first whereas the MCU s SPI module sends and receives bytes most significant bit first To handle this it is convenient to have a Reverse function that will reverse the bits ofa char global variable called 10 For this problem you are to write the code for the Reverse function using the following algorithm that employs another char global variable TEMP To carry out this reversal execute the following procedure seven times using a for loop Copy the least significant bit of 10 into the least significant bit of TEMP Shift 10 right one place Shift TEMP left one place When this has been carried out copy TEMP into 10 to complete the function void Reverse for i0 1lt7 I TEMP IO amp 0x01 10 gtgt 1 TEMP ltlt 1 i TEMP IO amp 0x01 10 TEMP Consider the attached page showing a 12 multiplexed LCD display that might be used to display a two digit 7 segment coded decimal number directly from a microcontroller The two 100 kg resistors used in the drive for each ofthe two COMi lines provide a way to drive the line to 3 V the MCU supply voltage 15 V or O V The backplane waveforms for COM1 and COM2 are shown in the middle ofthe page Below these two waveforms are shown the four frontplane waveforms to be applied to SEG1 The bottom waveform is intended to turn on both pixel 11 and pixel 12 the leftmost two pixels illustrated The other three turn one or the other or both ofthese same pixels off The LCD itself draws essentially no current What is the current draw on the coin cell due to the COM1 resistor circuit when its voltage is 15 V 3V012MQ 15 uA Can you drive COM1 to 3V with no current draw due to this drive at all Explain your answer es set RCO RC1 Can you drive COM1 to 0V with no current draw at all Explain your answer e s s e t RC 0 As the COM1 and COM2 waveforms are continuously driven with a 50 Hz frame frequency determine the average current draw on the coin cell due to the generation of these waveforms ignoring the MCU s current draw Show your work clearly COM1 current V2 X lSnA 75 nA COMZ current V2 X lSnA 75 nA COM1 COMZ current 15 nA What is the interval needed between interrupts so that the corresponding interrupt service routine can be used to generate these waveforms ms Showing all work determine the RMS voltage between the frontplane and the backplane for pixel 12 when both pixel 11 and pixel 12 are off RMS f 1152 02 1152 02 4 1106V 10 7 10 ECE 4175A Final 4 29 08 Page 3 of3 Repeat part e for pixel 12 when pixel 12 is off but pixel 11 is on f 1152 02 1152 02 4 1106V Repeat for pixel 12 when pixel 12 is on but pixel 11 is off f 1152 32 1152 32 4 237V Repeat for pixel 12 when pixel 12 is on and pixel 11 is also on f 1152 32 1152 32 4 237V If we have set up the loop time to occur every ten milliseconds then we can make an event take place at a rate ofN events per second where N is the content of an unsigned char variable in a manner similar to what we have done on some ofthe lab projects That is we might call an ActNow function 2 times per second ifN 2 or 35 times a second ifN 35 Defining any global variables you need write an Action function that is called from within the main loop that will call ActNow periodically at a rate ofN times per second Define signed char ACCUM 0 void Action 1 ACCUM N if ACCUM lt 0 ACCUM ACTNOW 100 Show a C coded implementation ofthe equation SCALEDVALUE TRANSDUCER234 that modifies this operation to a multiplication followed by a shift of 8 places twice so that the C compiler will replace the shifts by the moves of bytes The intent is to minimize the execution time ofthe scaling operation with multiplications and shifts executing faster than a division Assume that SCALEDVALUE and TRANSDUCER are unsigned int variables Define any extra variables that you need First note that 2quot 16 65536 and that 655362 34 28007 Define unsigned long TEMP TEMP TRANSDUCER TEMP 28007 TEMP gtgt 8 SCALEDVALUE TEMP 1 5 15 15 a 4 65 ECE 4175B Final 4 30 08 Page 1 of3 High 99 FOUR PROBLEMS Upper quarter 94 Open book open notes Median 83 Lower quarter 68 Low 51 Ihave completed the CIOS course evaluation Ihave not completed the CIOS course evaluation Two models of 16x2 character LCD displays are available with a serial interface Model A uses a 19200 baud UART interface similar to that used by the QwikampLow board for its connection to a PC Model B uses an SPI interface similar to that used by the QwikampLow board for its connection to the starburst LCD For this problem you are to consider how long it takes to update the LCD with a five character string consisting ofa cursor position control character followed by four displayable characters Ignore the time taken for anything other than the five serial transfers How long does it take the MCU on the QwikampLow board to send a five character string via its 19200 baud UART interface to Model A Explain your answer with a baud rate of 19200 each character takes 10 bit times where a bit time 100000019200 5208us50 a character takes 10 X 5208 5208ns or about 05 Five characters take 5 X 05ms 25 How long does it take the MCU on the QwikampLow board to send a five character string via its SPI interface to Model B Explain your answer With a CPU clock rate ofl MHz the SPI interface transfers each byte in about 10Js Five characters take 5 X lens Sons The magnetic card reader discussed in class includes an LRC longtitudinal redundancy check character for the data bytes read from the card For this problem assume that a char variable called LRC has been defined When a magnetic card is scanned and after the first active low 1 quot bit has been detected show the code to initialize LRC to zero and to turn off the LED on the QwikampLow board PORTDbi ts i RD4 0 Each time a group of five bits has been shifted into a char variable called MAGiBYTE the LRC variable is to be updated by exclusive ORing MAGiBYTE into it Show the code to do this L YTE After the end sentinal as been received and detected the next five bits that are shifted into MAGiBYTE are again to be exclusive ORed into LRC When this has been done the lower five bits of LRC should equal zero if no LRC error has been detected Show the code to make this check ofthe lower five bits of LRC and to turn on the LED on the QwikampLow board if there is an LRC error You may assume that the upper three bits ofLRC are zero if LRC PORTDbi ts i RD4 1 On the back of the review sheet for the final exam I included a circuit showing the SPI connection between a PIC microcontroller and an LCD character display that employs the standard Hitachi display controller interface For this problem you are to consider replacing this circuitry with nothing but another PIC microcontroller to serve as a display controller the LCD character display with its Hitachi display controller interface The only connections to these two parts from the QwikampLow board are an active low interrupt input INTO SCK input SDI input VDD power GND Upon powering up the PIC display controller initializes the LCD character display with an eight bit interface The pins required ofthe PIC display controller are the five listed above the eight data bits connecting it to the LCD an output to the LCD s RS pin an output to the LCD s E pin ECE 4175B Final4 3O 08 Page2of3 Continued The features required ofthe PIC display controller in addition to its SPI interface are internal clock interrupt input sleep mode The PIC16F69O is a 166 20 pin microcontroller that will serve this role However for this problem you will examine the code necessary assuming that the chip used is the PIC18LF4321 When an interrupt occurs via a falling edge on the RBOINTl pin the chip wakes up and gets ready to receive characters from the SPI interface As each of up to 18 characters is received it is put into a line buffer defined with the following global variable array LBUFFER and an index variable into it LBINDEX unsigned char LBUFFER18 Line buffer unsigned char LBINDEX A value between 0 and 17 Show the C coding for a function called ReadlntoBuffer that waits for each character to be received reads it into the next position of LBUFFER and then waits upon the reception ofthe next byte You can assume that upon entering ReadlntoBuffer the value of LBINDEX is zero You are to exit from ReadlntoBuffer after you have received and written the null terminator value of 0x00 into LBUFFER void ReadIntoBuffer CHAR SSPBUF Clear buffer PIRlbitsSSPIF 0 and flag bit initially DONE 0 while lDONE while lPIRlbitsSSPIF Wait for byte to be received PIRlbitsSSPIF 0 Clear flag LBUFFERLBINDEX SSPBUF and read byte into buffer if lSSPBUF DONE 1 Exit from while loop 1 1 Now write a WriteToLCD function that will write each ofthe characters in LBUFFER to the LCD stopping before writing the null terminator Assume that PORTD is connected to the LCD s 8 bit data input and that RB4 and RBS are connected to the LCD s RS and E pins respectively The first character to be sent from the buffer is to be treated as a cursor position code and written to the display with RS 0 The subsequent characters are to be treated as displayable ASCII coded characters and written to the display with RS 1 To write each character after the 8 bit data and the RS pin are in place drive E high and then low again After writing to the display use the Delay macro having the same definition as we have used all semester to insert a delay of 40 microseconds before writing the next character to the display void WriteToLCD PORTBbits RB4 0 Clear R5 for cursor position code LBINDEX 0 while LBUFFERLBINDEX Continue until null character PORTD LBUFFERLBINDEX PORTBbits RBS 1 Clock display PORTBbits RBS 0 PORTBbits RB4 1 Set R5 for subsequent displayable chars Delay4 Wait for 40us On the chance that data has not been sent to this PICLCD combination in the correct format you are to rewrite ReadlntoBuffer to handle the following cases 1 An omitted cursor positioning code can be detected as a value less than 0x80 If the first character received is less than 0x80 then write 0x80 to LBUFFER0 and write the received character to LBUFFER1 This will result in the display ofthe received characters beginning in the upper left hand corner ofthe display 2 If fewer than eighteen characters are received and no null terminator is received time out after one millisecond measured from the entry into the ReadlntoBuffer function using TimerO to monitor this time Before returning insert a null terminator at the end ofthe received characters so that WriteToLCD will function correctly with the characters that have been received