The University of Texas at Arlington Lecture 21_Review CSE 5442/3442
Agenda Tuesday December 1st Hand back Homework 7,8 and 9. Go over questions and answers Exam 3 Review Note: There will be a take home problem that counts 10 points (addressing ABET requirement) On web page by Friday, 12/4 2
Exam 3 Coverage Exam 3, Thursday December 10, 2009 8:00 AM - 10:30 AM Exam Coverage: 1. Labs 5 and 6 2. Chapter 9 Timers 3. Chapter 10 Serial Port Programming 4. Chapter 11 Interrupts 5. Chapter 15 Using PIC18 Timers for CCP, PWM, and ECCP will not be on test 6. Chapter 16 Using the SPI 3
Exam 3 Information cont. Exam 3 will be similar in form as Exam 1 and 2 - close book, one 8.5 x 11 inch page with any information you would like to have placed on it. You may bring the instruction summary that I previously provided. 4
Assignment 7 Chapter 11 Problems 1.,3., 7., 9.,15.,16., 18., 21. 22., 33., 34., 37., 39., 42., 43., 47., 48., 51., 52. 76 1. Which technique, interrupt or polling, avoids tying down the microcontroller? interrupts 3. In the PICI8 what memory area is assigned to the interrupt t vector table? 0x0008 and 0x0018 4. True or false. The PICI8 programmer cannot change the memory address location assigned to the interrupt vector table. 5
Assignment 7, cont. 7. Do we have a memory address in the interrupt vector table assigned to the Timer0 interrupt? No all interrupts go to the same location (high or low) 9. To which register does the GIE bit belong? INTCON 6
Assignment 7, cont. 11. What is the state of the GIE bit upon power-on reset, and what does it mean? GIE is set to 0 so the interrupts are disabled on power up. 15. How many bytes of address space in the interrupt vector table are assigned to the highpriority interrupt? 16 bytes (8 words) 7
Interrupt Types CSE 3442/5442 Lecture 16 Dr. Roger Walker 8
Registers and Bit Names for Interrupt t Sources CSE 3442/5442 Lecture 16 Dr. Roger Walker 9
Simplified View of Interrupts (default for power-on reset) CSE 3442/5442 Lecture 16 Dr. Roger Walker 10
PIC18 External Hardware Interrupt t Pins CSE 3442/5442 Lecture 16 Dr. Roger Walker 11
Assignment 7, cont. 16. How many bytes of address space in the interrupt vector table are assigned to the low-priority interrupt? From 18 to what ever addresses not used by program. 18. True or false. The INTCON register is not a bit-addressable register. 21. True or false. Upon reset, all interrupts t are enabled by the PIC18. 12
Assignment 7, cont. 22. In the PIC18, how many bytes of ROM space are assigned to the reset. 8 Bytes 23. True or false. For each of Timer 0 and Timer 1, there is a unique address in the interrupt t vector table. 13
Assignment 7 Cont. 33. True or false. An address location is assigned to each of the external hardware interrupts t INT0, INTI, and INT2. 34. What address in the interrupt vector table is assigned to INT0, INTI and INT2? How about the pin numbers on PORTB? 0x0008 if high priority and 0x0018 if low priority, Pins 33, 34, and 35 are the INT0-2 interrupt lines. INT0 is always a high priority interrupt. (Note: If you said 0008 following a reset or power on and the words unless otherwise specified it would be counted correctly as this was in the book.) 14
Assignment 7, cont. 37. Show how to enable all three external hardware interrupts. BSF INTCON, INT0IE BSF INTCON3,INT1IE INT1IE BSF INTCON3,INT2IE 39. True or false. Upon reset, all the external hardware interrupts are negative edgetriggered. 42. The INTlIF bit belongs to the register. INTCON3 15
Assignment 7, cont. 43. True or false. The last two instructions of the ISR for INTI are: BCF INTCON3,INT1IF INT1IF RETFIE 47. True or false. INTO-INT2 are part of the PEIE group. 48. True or false. Upon power-on reset, all of INTO-INT2 are positive edge trigered. 16
Assignment 7, cont. 51. True or false. INT0-INT2INT2 must be configured as an input pin for a hardware interrupt to come in. 52. Which register holds the INTEDGx bits? INTCON2 register. 76. True or false. In PIC18 an interrupt inside an interrupt is not allowed. 17
Chapter 9 Timers SUMMARY The PIC18 can have up to four or more timers/counters, depending on the family member. When used as timers, they can generate time delays. When used as counters, they can serve as event counters. By using the external clock option, pulses are fed through h one of the PIC18 s pins and the mode is referred to as a counter mode. Generally, the timers are accessed as two 8-bit registers, TMRLx and TMRHx. They can be used as a 16-bit timer, or as an 8-bit bttimer. 18
Timer Summary cont. Each timer has its own TCON (Timer Control) register, to choose between various operational modes. Among the modes are the prescaler and timer/counter options. When the timer is used as a timer, the PICI8's crystal is used as the source of the frequency (Fosc/4); however, when it is used as a counter, it is a pulse outside of the PIC18 that increments the TMRxH, TMRxL registers. 19
Programming 1. Load T0CON Prescale & 8/16 bit options. 2. Load TMR0H followed by TMR0L 3. Start Timer 4. Loop (or ISR interrupt mode) when roll over flag set. 5. Stop timer and clear flag 6. Go back to step 2 20
Assignment 8 On pages 383-385 385, Chapter 9 in your text, work problems 1, 5., 8., 9., 14., 16., 21., 29.,45., 46., 47. 1. How many timers are in the PIC18F458? 4ti timers 5. Timer1 supports the highest prescaler value of 8. 21
Assignment 8 - cont. 8. True or false. TICON is a bit-addressable register. 9. Find the T1CON value for 16-bit mode, no prescaler, timer oscillator off, with the clock coming from the PICI8's crystal. 0x01 (assuming enabling w/ these parameters 14. True or false. Both Timer0 and Timer1 have their own timer interrupt flags. 22
T1CON (Timer 1 Control ) Register 1 2 3 23
Figure 8-2a. PIC18F458 Power-On Reset Circuitit Counter0 External CLk. In Pin Counter1 External CLk. In Pins 24
Timer1 Block Diagram 3 1 2 25
PIR1 (Interrupt Control Register 1) Contains the TMR1IF Flag 26
Assignment 8 - cont. 16. Assume that XTAL = 10 MHz. Find the TMR0H, TMR0L value needed to generate a time delay of 2 ms. Use 16-bit mode, no prescaler mode. 10MHz/4=25MHz 2.5 MHz, 1/25MHz=04μs 2.5 0.4 μs, 2 ms / 0.4 μs = 5000, 65536 5000 = 60536 = 0xEC78, TMR0H = 0xEC TMR0L = 0x78 27
Assignment 8 - cont. 21. Assuming that XTAL = 10 MHz, and we are generating a square wave on pin RB7, find the lowest square wave frequency that we can generate using Timer0 in 16-bit mode. 10 MHz / 4 = 2.5 MHz, 2.5 MHz / 256 = 9765.625 Hz, 1 / 9765.625625 Hz = 102.4 μs, 102.4 μs * 65536 = 6.7108864 s, 6.7108864 s * 2 = 13.4217728 s, 1 / 13.4217728 = 0.0745058 Hz So the lowest frequency is equal to 0.0745058 HZ. 28
Prob. 21 2^16 2^16 T 10 Mhz / 4 1/256 F = 1 / T (per ct) 29
Assignment 8 - cont. 29. To use a timer as an event counter we must set the T0CS bit in the T0CON register to (LOW, HIGH). ) We must set T0CS bit of T0CON to high 45. Indicate when the timer flag is raised for each of the following: (a) Timer2 - When TMR2 = PR2 (b) Timer3 - When TMR3H:TMR3L rolls over from FFFFH to 0000H 30
Assignment 8 - cont. 46. True or false. The PR2 register of Timer2 is an 8-bit register. 47. True or false. Both Timer2 and Timer3 are 16-bit timers. 31
Serial I/O Chapter 10 Terms Baud Rate (distingush from bits per second) RS232 main signals, RTS, CTS, DTR, DSR, SGd, TxD, RcD Framing Mark/space, DB9 vs DB25, UART, USART 32
Assignment 9 On pages 418-420 420, Chapter 10 in your text, work problems 4., 5., 7., 9., 13., 29., 31., 33.,36., 36 37 4. If there is no data transfer and the line is high, it is called (mark, space). 5. True or false. The stop bit can be 1, 2, or none at all. It can be 1 or 2 but we always need stop bit. 33
Assignment 9 - cont. 7. True or false. RS232 voltage specification is TTL compatible. 9. True or false. DB-25 and DB-9 are pin compatible for the first 9 pins. 13. If two PCs are connected through h the RS232 without the modem, both are configured as a (DTE, DCE) -to- (DTE, DCE) connection. 34
Assignment 9 - cont. 29. Which of the following baud rates are supported by the HyperTerminal program in PC? (a) 4,800 (b) 3,600 (c) 9,600 (d) 1,800 (e) 1,200 (f) 19,200 (a), (c), (e), (f) 35
Assignment 9 - cont. 31. Which bit of the TXSTA is used for baud rate speed? Bit D2 (BRGH) 33. TXREG is a(n) 8 -bit register. 36
Assignment 9 - cont. 36. For XTAL = 10 MHz, find the SPBRG value (in both decimal and hex) for each of the following baud rates. (a) 9,600 (b) 4,800 (c) 1,200 First we have 10 MHz/4 = 2.5 MHz and 2.5/16 = 156,250. Now each is calculated by using X = (156,250/ Desired Baud Rate) 1 formula.. (a) 156,250/9600-1 = 15 = F in hex (b) 156,250/4800-1 = 32 = 20 in hex (c) 156,250/1200-1 = 129 = 81 in hex 37
Assignment 9 - cont. 37. What is the baud rate if we use SPBRG = 15 to program the baud rate? Assume XTAL= 10 MHz. 9600(see page 398 example) SPBRG (Fosc/4/16)/(Desired Baud Rate) -1 Or solve for Baud Rate see table 10-4 38
Chapter 16 - SPI What is SPI page 604/605 SPI Bus Steps for writing to SPI device SPI - Serial Peripheral Interface short tutorial http://www.mct.net/faq/spi.html (only for information/will not be on exam) 39
Lab 6: Digital to Analog Objective: Converter (DAC) The purpose of this lab assignment is to work with the serial DAC chip (MAX 522). Use the QwikFlash board to generate a variable amplitude and frequency signal using the DAC chip. There will be a take home problem that t counts 10 points (addressing ABET requirement) On web page by Friday, 12/4 40
Using the SPI Chapter 16 For Lab 6 Use the SPI Module of PIC SPI Serial Peripheral Interfacing (SPI) protocol 41
SPI_D/A Interface 42