CE351 lec22 Wrap up the IR tutorial
Overview
Yiyan Li wraps up CE351’s infrared transmitter tutorial by tracing the AVR timer-driven state machine: Timer5 generates IR pulses, while Timer3 advances start, data, and stop-bit states and handles message termination. The lecture also reviews UART baud-rate and receive-interrupt setup, checksum and buffer behavior, and exam-style questions on the implementation.
Key takeaways
- Timer5 generates the IR carrier using its compare-output configuration, and with ICR5 = 420, OCR5B = 42 gives the 10% duty cycle described in the tutorial.
- The transmitter represents each byte with a start bit, eight masked data bits, and a stop bit; a Timer3-driven state machine advances through those parts.
- A null terminator provides a detectable boundary for checksum handling, while an explicit flag can help distinguish the final checksum byte from ordinary message characters.
- UBRR values above 255 must be split between UBRRH and UBRRL; shifting right eight bits selects the high byte, while assignment to UBRRL retains the low byte.
- UART receive interrupts process a complete framed byte, not each incoming bit: the interrupt occurs after the start bit, eight data bits, and stop bit arrive.
- An 8-bit unsigned checksum wraps modulo 256, and the transcript describes it as the sum of the ASCII values of the transmitted characters.
Chapters
- The IR decoder reports a low when the transmitter pulls the signal down, so the start bit turns the IR output on.
- Timer5 controls the IR carrier through TCCR5A and the compare-output configuration; OCR5B sets the compare value.
- With ICR5 set to 420, OCR5B is set to 42 for a 10% duty cycle.
- The idle state waits for the transmit-start condition, then resets the message index and advances to the start-bit state.
- A one-bit mask, initialized as 0b00000001, extracts individual bits from the current character.
- The current character is loaded from the message buffer using its index before the Timer3 state advances.
- The data state tests the current character with a bitwise AND against the mask to determine the bit being sent.
- A data bit of 1 turns the IR output off; a 0 turns it on using the Timer5 compare-output setup.
- After all eight bits have been shifted through the mask, the state changes to the stop-bit state.
- The stop bit pulls the IR output up, completing the start–8-data-bit–stop framing for each transmitted byte.
- After a normal character, the index advances and the next character begins with a new start bit.
- A null terminator identifies the transition to the checksum byte; after the checksum is sent, the state returns to idle.
- A flag can mark that the message terminator was reached and guide the final stop-bit logic; transmit-start must also be cleared when transmission finishes.
- The baud-rate equation uses the 16 MHz clock and includes the specified plus-one and minus-one terms; Li notes that the equation will be provided on the exam.
- UBRR is a 16-bit value stored across UBRRH and UBRRL, so the upper byte is obtained by shifting right eight bits.
- Assigning the value to the 8-bit UBRRL register keeps the low byte and discards the upper byte; a shift that is not assigned back does not change the original C variable.
- UCSRB enables UART receiving and its receive interrupt, while the frame configuration uses eight data bits.
- The receive interrupt fires after a full 10-bit frame (start bit, eight data bits, and stop bit) has arrived.
- The ISR copies the received byte from the UART buffer into the message list at the current index.
- The review identifies USART1_RX_vect as the receive-interrupt vector and uses the baud-rate equation to calculate UBRR for 2400 baud.
- A Timer3 interval for 2400 bits per second is calculated from the clock rate and desired bit rate.
- The transmit checksum sums character ASCII codes and is stored as an unsigned 8-bit value, so overflow wraps around modulo 256.
- Other review items cover the two address bytes, the Enter key’s carriage-return character, index incrementing, and the null and checksum bytes at the message end.
- The diagram moves from transmit-idle to TX-start when transmit-start becomes true; the message index is initialized in idle rather than reset for every character.
- TX-start pulls the output low and loads the current character, then TX-data applies the mask and shifts it through eight bits.
- When the mask is exhausted, the state enters TX-stop and either starts another byte or handles the null-terminator and checksum sequence.
- After the checksum, the machine returns to idle and clears the relevant transmit flags.
- Li says solutions to the remaining practice-exam problems will be posted on Canvas.
- The practice exam uses questions adapted from the designed exam but approaches the material from different angles.
- Although the exam is planned for 55 minutes, Li says the problem set may be shortened by about 20%; many items require short answers.
Transcript excerpt
0:03 And then the next state should be out of the idle state. So in the start bits start bits the start bit state should send a start bit first right. So the start bit will be um IR on or off start bit. So decoder is outputting a zero right because whenever it's TX is pulling it down it starts the transmission. So if you want to pull it down to zero, you to turn on or turn off the IR turn on because all the pulses are triggering a zero from the decoder. So you want to turn it on. So how to turn it on? How to turn it on? Remember? So this will be on the exam. Okay. Make sure that you you know how to
0:52 how to do the uh routine. turn on, turn off, all those kind of things. How to turn it on is in TCCR. Which timer is controlling IR um based on the code we have been doing here. Timer five. So timer three is for what? For the ball rate, right? So timer five is going to be T CCR 5A. So turn turn on you are doing this one shifted by com 51. So that's in the ISR you turn it on turn on I turn on the IR by doing this by turn on this bit. Okay but followed by
1:41 writing a top to it. So what's the no uh writing the compare match register? So it's OCR5 that B OC R5B. Okay. And that equals to a number, right? So that's that controls the what controls the compare match. Okay. So whenever it matches this one, it pulls it down to zero. Okay. For the IR. So this number should be what should be the 10 should be 10% 10% of the uh whatever in the ICR
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Yiyan Li.