Exam 3 Topics
Errata
Spring 21 Watchdog Timer question - SLEEP() should reset the WDT time [1], meaning the timeout occurs 500 ms later, and bumping back subsequent events. This only affects the 3-4s interval answer, which should be "X" and not "C"
If you find errors in the past exams or in this review guide, please email me at prl83@msstate.edu. It will be worth a small bonus to your lab grade.
Exam 3
The following table examines the last fifteen Exam 3s, dating back to Summer 2018:
Notes
"Prog" are programming problems that are Exam 3 / Practicum caliber. They've only appeared on summer exams. "I2C Prog" are I2C programming problems. This is a topic usually covered between Exam 3 and the final exam. Neither topic has been on an Exam 3 since 2020. Check with your instructor to be certain.
"Co/CoProg" are coroutine questions and programming problems. They will not appear on yourExam 3 unless your instructor covered them in class.
If we remove the unlikely topics, our table now looks like this:
UART
Identify the bit
Since there are 13-14 parts to this subquestion, each worth a point, it is worth the bulk of the points in the UART section, and is the reason why UART is the highest-weighted topic on Exam 3:
Every question since Spring 19 has been either A) 8 data bits, no parity, 1 stop bit (like above), or B) 7 data bits, 1 parity bit, 1 stop bit. (The 2018 questions were "7 data bits, odd parity, 1 stop bit", which for the sake of these questions is the same as the 7-1-1 ones.) Both versions of the question are easy, so it really doesn't matter which one you get, but here is a table showing Spring and Fall exams only:
Disclaimer: Past performance does not guarantee future results.
Additionally, a lot of the same waveforms are recycled; however, it's not worth the time to try to memorize or predict them. Instead, here are the simple rules that you need to solve these questions. Put them in your cheatsheet:
All the beginning 1 bits are idle (I).
The first 0 bit is start (S).
Then comes the data. The first data bit is D0, then D1, D2, etc. On the exam just write the number, so 0, 1, 2...
Careful - if there are 8 data bits, the last data bit will be D7! If there are 7 data bits, the last data bit will be D6!
If there is parity, that's the next bit (P).
Then the stop bit (T), which should be a 1.
Finally, all the rest of the 1 bits are idle (I). If there were another low bit at the end, it would be the start bit of the next byte.
Here is an illustration of that for the above question from Spring 24:
Here's one of the 7-1-1 types from Fall 23:
The first two bits are high, so they're Idle.
Bit 3 is Start because it's the first low one.
Bit 4 is data bit 0, bit 5 is data bit 1 (and so on)...
...Bit 10 is data bit 6.
We do have Parity, so that's bit 11. It is the bit right after the data, and can be high or low, but we'll discuss that later.
Bit 12 is the sTop bit. (Do not get confused because you think stop starts with an 's'.)*
Bit 13, and if there are any more bits (the only time there were 14 was in Fall 2021), are all Idle (as long as they are high).
*Joke - Q: How do you top a car? A: Tep on the brake, tupid!)
Hex value
In the waveform above, what is the hex value of the data transmitted? This question, or a variant of it, is asked almost every time.
You read the bits backwards so it's D6-D5-D4-D3-D2-D1-D0. In this case that's 0101110.
You do not count the parity bit. (The above solution diagram is misleading.)
Even though the question says "hex value", you can give the answer in binary, just remember to prefix with "0b": 0b0101110 is correct. (Conversely, some semesters they say they want the answer in binary, but you can give in hex. You can even give it in decimal, though I don't know why you'd want to: it's 56. If you don't believe me, try it on the sample exams.) If you do convert it to hex, remember to tack a zero on the left, so you would have 0010_1110, or 0x2E. (Nothing is case sensitive either, so 0X2e is also fine.)
Parity
Odd parity means that the total number of 1s in the data and parity bit combined has to be odd. Even parity means that the total number of 1s in the data and parity bit combined has to be even.
Count the 1s in the data only. Remember whether there are an even or odd number of 1s...
Odd parity:
If there's an even number of 1s in the data, we need another one to make the total odd - parity bit is 1.
If there's an odd number of 1s in the data, everything is fine - parity bit is 0.
Even parity
If there's an even number of 1s in the data - parity bit is 0.
If there's an odd number of 1s in the data, we need another one to make the total even - parity bit is 1.
Using this, we can work backwards and determine whether the parity is odd or even. In the above data there are four 1s. Four is an even number. The parity bit is high, for a total of five 1s, Five is an odd number, so that means the parity is odd. If the question were phrased differently, and told you that the parity was supposed to be even, then asked if the data was transmitted correctly, the answer would be no.
Baud rate
Baud is bits per second.
Include all the bits: stop, parity (if applicable), and start, even if they are not specifically mentioned.
Spring 24: What is the minimum possible time required to send 20 bytes over a UART operating at 115,200 baud using 8 data bits, 1 parity bit, and 1 stop bit? Give your answer in ms, accurate to at least 3 significant digits.
8 data + 1 parity + 1 stop + 1 start bit they didn't mention = 11 bits per byte
20 bytes * 11 bits/byte = 220 bits we need to send.
We can send 115,200 bits/second, so 220/115,200 = 0.001909722222... seconds.
We have to give the answer in ms, so bump the decimal point over 3 notches: 1.9097222 ms
It wants at least 3 significant digits, so 1.91 (1.910, 1.9097, and 1.90972 are also acceptable)*
* As is 1.90972 followed by holding down the '2' key indefinitely. So is 1.9149999999999999, though 1.91499999999999999 is not. The lowest acceptable answer seems to be 1.90499999999999992. Now go back to studying.
Digital inputs and outputs
Put this table in your cheatsheet:
"od" is open drain and "pu" is pullup. Sometimes instead of "od = 1", the problem will say "open-drain is enabled" or something like that
"pin" is sometimes "_LATB14" or similar
"random" = Z, X, can't be determined, etc.
"volts" is sometimes written _RB13 and you may have to give 1 and 0 (Spring 24), or "A for 0 V or B for 3.3 V" (Fall 23)
The question may be asked in different ways, including in the form of a program, but with the exception of Summer 18, they can all be solved simply with the above table.
These questions are often accompanied by a diagram and a snippet of code like this:
Whatever the table says, if the button is pressed, it grounds the pins, making the voltage 0 !
Summer 18
Although it's been a long time since the Digital I/O questions took this form, nevertheless I would be on the safe side and copy the correct code snippet and the following factoids onto your cheatsheet:
// configure an LED on pin RA2
#define CONFIG_LED1() (CONFIG_RA2_AS_DIG_OUTPUT())
An LED is an output.
"Open-drain configurations are typically used for outputs, not inputs."
// configure a pushbutton on pin RA2
void config_pb1(void) {
CONFIG_RA2_AS_DIG_INPUT();
ENABLE_RA2_PULLUP();
DELAY_MS(1);
}
A pushbutton is an input
"Pushbuttons require a pullup to operate correctly."
Watchdog timer
This type of question appears on almost every Exam 3. You're given the following instructions:
A PIC33 (or PIC24) programmed with the following code is powered on at 0 seconds. What is printed on the screen, and at what times? Assume the watchdog timer is programmed to expire in ___ seconds. See Fig. 1 for information on the WDTO bit. When power is first applied, assume _SWDTEN = 0.
(Fig. 1 is a link that just jumps you to the Power-on reset diagram, but it is unnecessary to solve these questions.) Then there's a C program, which for your reference while clicking back to study old exams:
same question: Fall 23, Spring 23, Fall 22, Summer 20
same question: Fall 21, Fall 18
no WDT: Summer 19, Summer 18
These questions are quite hard for several reasons:
There is no material in the ebook about the watchdog timer.
In the lecture slides, the important rules about the watchdog timer (i.e. the ones that help you solve these questions) are obscured by extraneous material that is not tested. Other rules are not given and can only be discovered by doing sample exams.
It is very easy to make a careless mistake. Watchdog timer is like the Timing questions from Exam 1 on steroids.
We've got you covered here for #1 and #2, but for #3, you're on your own. Besides plenty of practice, I would recommend making a tidy list on scrap paper to keep track of when everything happens, and then going back and doing this question from scratch a second time after you've finished the rest of the exam. As for #1 and #2, the good news is the list of rules that you need to learn put in your cheatsheet is actually fairly short:
A WDT timeout during normal operation e.g. DELAY_MS(), will reset the PIC and go back to the beginning of the program. _WDT0, the watchdog timer flag, will be set.
A WDT timeout during SLEEP() will resume operation on the next line. _WDT0 will be cleared.
_WDT0 is also cleared at power on (so it starts cleared in these questions).
The _SWDTEN bit can be used to enable/disable the WDT.
If _SWDTEN=1, this enables the WDT (and starts counting from zero).
If _SWDTEN=0, this disables the WDT. This makes DELAY_MS() delay the full interval, and will make SLEEP() indefinite.*
CLRWDT() clears _WDT0 and resets the timer.
MS_DELAY is cumulative, so if the WDT is set to expire in 1 second and you delay 500 ms, print a character, and delay another 700 ms, the WDT will trigger and reset the PIC 500 ms into the second delay.
SLEEP() is not supposed to be cumulative - the datasheet says the WDT is reset upon entering sleep [1]. However on Spring 21, it was cumulative. (Other exams in a similar situation executed CLRWDT() command before entering sleep.)
The letters are not case-sensitive, so you can type abcde or ABCDE or aBcDe, just don't put spaces or commas between them.
[1] Errata
* It is very unlikely that this would happen in an early interval, so if you find yourself writing "X" in the last six blanks, you've probably done something wrong.
Interrupts
These are also hard questions. Again, there are only a handful of rules to remember/write down and they're better documented in the lecture notes and ebook, but you have to keep track of all them at once, along with the table of pushbutton presses and releases. One lapse in concentration and goodbye points.
A PIC24 interrupt occurs when all of following conditions are satisfied simultaneously:
The interrupt flag (named _xxIF) is set.
The interrupt priority (named _xxIP) is > 0.
The interrupt enable (named _xxIE) is set.
An INT interrupt will be only be triggered either by rising OR falling edge as specified (CN interrupts are always triggered on BOTH):
INTxEP bit = 1 —> INTx will be triggered by falling edge (press)
INTxEP bit = 0 —> INTx will be triggered by rising edge (release)
Two other important things to remember for these questions:
If two interrupts occur, do them both, higher priority first.
If an interrupt flag is set and the priority is 0, or it is disabled, but then the priority changes or the interrupt is enabled, the interrupt occurs.
Timers
Timer Configuration
The first parts of these questions are all the same - and very easy. You look at this part of the datasheet:
Then you type 0b in the answer box (it doesn't matter what the question asks for - always answer in binary so you don't mistakes) and fill it out based on the specifications in the question. For example, from Spring 24:
What value for T2CON configures timer 2 to run, continue operation in idle mode, disable gated time accumulation, use a 1:8 prescale, operate as a 16-bit timer, and use the internal clock as its clock source? All undefined or unspecified bits must be chosen as 0.
TON - TSIDL - - - - - - TGATE TCKPS[1:0] T32 - TCS -
1 0 0 0 0 0 0 0 0 0 01 0 0 0 0
So 0b1000000000010000
Just remember;
if they don't mention bits in the question, they're 0.
Count your bits to make sure you have 16.
Bit 15 is on the left.
If you use spaces to divide the bits into groups of four to make them easier to count, make sure you delete the spaces or your answer will not be accepted.
Remember 0b !
Timer Period
The second part of these questions is almost as easy. You probably already have this formula in your cheatsheet from the lecture notes:
This is for Timer2. For Timer3, we use PR3, but the formulas are otherwise the same.
All but two of the exams use the bottom version of the formula and ask you to solve for PR2, but since you're given frequency instead of clock period, and timeout period is referred to as "interrupts every _____", a more useful version is:
PR2 = (interrupts_every x freq / prescaler) - 1
The Fall 19 exam asks for "the period of interrupts" aka timeout period, so on that question you would use the top version and do:
period_of_interrupts = prescaler x (PR2 + 1) / freq
Spring 22 asks:
Assuming a 1:256 prescale for timer 2 running on the internal clock of Fcy = 40 MHz, how much time is 200 timer ticks? Give your answer is ms.
For this question, use the formula:
timer tick = (1 / freq) x prescaler
So we get:
timer tick = (1 / 40M) x 256
timer tick= 0.0000064 s
200 timer ticks = 0.00128 s = 1.28 ms
For all these questions, remember:
Prescaler is not a fraction, it's 1, 8, 64, or 256.
Answer in milliseconds if that's what the directions say.
40 MHz = 40,000,000
Power-on reset
These questions are similar to the Watchdog timer and Interrupts ones in that you have to answer with what is printed in various time periods, and need to be careful not to make a foolish mistake. However, despite not being covered in the lecture notes or ebook, they are easier because they tend to be very similar from semester to semester, and you're given a datasheet with virtually all the information you need. Here's a more useful version of that datasheet with the rows that have actually been applicable to past exam questions:
*A brownout reset has never occurred in any past exam.
**You could set all these flags in the code, for example _POR=1. However this has never been done on any past exam.
The only thing you have to know:
All of these resets make you jump back to the top of the program.
This should be intuitive, but it doesn't specifically say it in the datasheet, so there it is.
Waveout interrupts
These questions have only appeared twice, on Summer 20 and Spring 21. At first glance, they appear cruel hard, combining Interrupts and Timers; but they eschew the trickery of the former and are just straightforward calculations of the timeout period.
Use this version of the formula:
timeout = prescaler * (PR2 + 1) / freq
All the calculations conveniently come out to whole milliseconds, and there's no button pushing or PIC resetting to throw you off. Give them a try if you're done with your other studying. The only real way to screw them up is to forget, as the question says, that "All times are measured from when the program began running, not from the last toggle."
Good Luck and God Bless!