Podcast
Questions and Answers
In the 16F84A's interrupt structure, enabling the Global Interrupt Enable (GIE) bit in the INTCON register masks all interrupts, preventing any interrupt from being serviced.
In the 16F84A's interrupt structure, enabling the Global Interrupt Enable (GIE) bit in the INTCON register masks all interrupts, preventing any interrupt from being serviced.
True (A)
In the context of microcontroller interrupts, a 'maskable' interrupt is one that the CPU always responds to, regardless of the system's current state or priority.
In the context of microcontroller interrupts, a 'maskable' interrupt is one that the CPU always responds to, regardless of the system's current state or priority.
False (B)
When an interrupt is triggered, the microcontroller immediately stops the current instruction, executes the Interrupt Service Routine (ISR), and then resumes the interrupted instruction from the beginning.
When an interrupt is triggered, the microcontroller immediately stops the current instruction, executes the Interrupt Service Routine (ISR), and then resumes the interrupted instruction from the beginning.
False (B)
In the 16F84A interrupt structure, the EE write complete interrupt is triggered when the EEPROM write process is only initiated, but not when it is actually complete.
In the 16F84A interrupt structure, the EE write complete interrupt is triggered when the EEPROM write process is only initiated, but not when it is actually complete.
When using the sleep mode in a microcontroller, all operations, including the watchdog timer and oscillator, are halted to minimize power consumption.
When using the sleep mode in a microcontroller, all operations, including the watchdog timer and oscillator, are halted to minimize power consumption.
A microcontroller watchdog timer is primarily used for precise time measurement in mission-critical applications.
A microcontroller watchdog timer is primarily used for precise time measurement in mission-critical applications.
In microcontroller programming, 'polling' offers an immediate response to I/O service requests, ensuring no delay in handling external events.
In microcontroller programming, 'polling' offers an immediate response to I/O service requests, ensuring no delay in handling external events.
In the 16F84A, configuring INTEDG
bit to '1' in the OPTION_REG
will cause an interrupt on the falling edge of the RB0/INT pin.
In the 16F84A, configuring INTEDG
bit to '1' in the OPTION_REG
will cause an interrupt on the falling edge of the RB0/INT pin.
In interrupt-driven systems, saving the STATUS register is always unnecessary, as the interrupt service routine can directly manipulate the microcontroller's status without affecting the main program's state.
In interrupt-driven systems, saving the STATUS register is always unnecessary, as the interrupt service routine can directly manipulate the microcontroller's status without affecting the main program's state.
Interrupts are exclusively generated by internal timers and cannot be triggered by external events or I/O devices.
Interrupts are exclusively generated by internal timers and cannot be triggered by external events or I/O devices.
Flashcards
What is an Interrupt?
What is an Interrupt?
An event that halts the normal program flow and executes a special interrupt service routine (ISR).
Advantages of Interrupts
Advantages of Interrupts
Immediate response to service requests and normal execution continues until I/O service is needed.
Interrupt Sources
Interrupt Sources
Sources can be external (pins, devices) or internal (timers).
Timer Overflow Interrupt
Timer Overflow Interrupt
Signup and view all the flashcards
Watchdog Timer
Watchdog Timer
Signup and view all the flashcards
Sleep Mode
Sleep Mode
Signup and view all the flashcards
How to enter sleep mode?
How to enter sleep mode?
Signup and view all the flashcards
Timer Applications
Timer Applications
Signup and view all the flashcards
What are the Disadvantages of interrupts?
What are the Disadvantages of interrupts?
Signup and view all the flashcards
What is Port B on change interrupt?
What is Port B on change interrupt?
Signup and view all the flashcards
Study Notes
Working with Time: Interrupts, Counters, and Timers
- Microcontrollers need to deal with time for external events, measuring time, and generating time-based activity
- Microcontrollers use timers, counters, and interrupts for this
Interrupts
- Interrupts cause the microcontroller to halt its normal program flow
- Interrupts execute a separate program called the interrupt service routine (ISR)
- Interrupts are hardware-initiated subroutine calls typically generated by I/O devices
Interrupts vs. Polling
- Advantages of interrupts include immediate response to I/O service requests and continued normal execution until I/O service is required
- Disadvantages of interrupts include coding complexity, extra hardware needs, and the processor I/O device needing to generate an interrupt request
General Hardware Structure for Interrupts
- Interrupt sources can be external, internal, maskable, and non-maskable
- Maskable interrupts can be enabled/disabled by setting/clearing bits
- Non-maskable interrupts can not be disabled
- Each interrupt has a flag (a bit) that is set when an interrupt occurs
16F84A Interrupt Structure
- Sources of interrupts for the 16F84A are external interrupt only, timer overflow interrupt, port B on change interrupt, and EEPROM write complete interrupt
- INTCON register and option register are interrupt related bits
INTCON Register
- INTCON register address is located at 0Bh and 8Bh
- GIE: Global Interrupt Enable bit enables or disables all unmasked interrupts
- EEIE: EE Write Complete Interrupt Enable bit enables or disables EE Write Complete interrupts
- TOIE: TMRO Overflow Interrupt Enable bit enables or disables the TMRO interrupt
- INTE: RB0/INT External Interrupt Enable bit enables or disables the RB0/INT external interrupt
- RBIE: RB Port Change Interrupt Enable bit enables or disables the RB port change interrupt
- TOIF: TMRO Overflow Interrupt Flag bit indicates TMRO register overflow
- INTF: RB0/INT External Interrupt Flag bit indicates RB0/INT external interrupt occurred
- RBIF: RB Port Change Interrupt Flag bit indicates state change on RB7:RB4 pins
Option Register (81H)
- RBPU bit enables or disables PORTB pull-ups
- INTEDG bit selects interrupt trigger edge on RB0/INT pin. 1 = rising edge, 0 = falling edge
- T0CS bit selects TMRO clock source, 1 = RA4/TOCKI pin, 0 = internal instruction cycle clock (CLKOUT)
- TOSE bit selects TMRO source edge; 1 = high-to-low, 0 = low-to-high
- PSA bit assigns prescader to the WDT or the Timer0 module. 1 = the WDT. 0 = the Timer0 module
- PS2:PS0 bits set prescaler rate
Operation
- To use interrupts
- Start the interrupt service routine at 0x0004
- Clear the flag of the used interrupt in the INTCON register if it is not cleared on reset
- Enable the corresponding interrupt by setting its bit in INTCON register
- Enable global interrupts by setting the GIE bit
- End the interrupt subroutine with RETFIE instruction to resume program execution
Context Saving
- If the main program is to preserve the W register, save it temporarily at the beginning of the ISR then restore at the end of ISR
- If preserving a memory location like STATUS
- Save it temporarily in memory at the ISR beginning
- Restore the value at the end of ISR
Counters and Timers
- Digital counters can be built with flip-flops and can count up/down, reset, or load an initial value
- An overflow indicates when the most significant bit changes from 1 to 0
- Counters with a known clock frequency can be used as timers
Timer applications
- Measure the time between two events
- Measure the time between two pulses
- Measure a pulse duration
- Polling or interrupts can be used
Watchdog Timer
- A timer internal to the microcontroller and continually counts up
- Microcontroller resets if enabled and overflows
- Helps reset the microcontroller if a program fails or gets stuck
- The WDT timer is enabled/disabled by the WDTE bit in the configuration word
- It has its own internal RC oscillator with a nominal time-out period of 18 ms
- Extended through prescaler bits in the OPTION register up to 128x18 ms = 2.3 sec
- The WDT timer is cleared using the CLRWDT instruction
Sleep Mode
- An important way to save power and can be entered using the SLEEP instruction
- Halts microcontroller operation, switches off the oscillator
- WDT is cleared unless, if it remains enabled, it keeps running
- Ports retain setting and ports bits are set/cleared respectively
- To exit
- An interrupt occurs
- A WDT wake-up
- External reset the MCLR pin
Summary
- Microcontrollers deal with time using timers and interrupts
- Interrupts require attention only when they occur, saving computational power
- Most interrupts are configurable
- Hardware timers can be a counter or a timer and are useful for measuring time
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.