2 Microcontrollers Flashcards
What is a microcontroller?
A microprocessor with RAM, Permanent memory, Digital I/O and other peripherals
What are the registers that control the ports of a microcontroller?
- DDRA, DDRB: Data direction
- PORTA, PORTB: Outputs / pull-up resistors
- PINA, PINB: Input
What is bouncing?
Bouncing is short signal fluctuations before a signal change.
Choose Interrupts or Polling for the following scenarios and explain your choice.
(1) The ”change input”-button on a monitor
1) Interrupts. Due to the rarity of this signal, Polling would waste a lot of CPUressources.
Choose Interrupts or Polling for the following scenarios and explain your choice.
(2) The wireless-reciever of a garage-opener
2) Depends. Again the scarcity of such signals would make Interrupts preferable,however since there might be a lot of signal-noise and erroneous garage-openingswould be a security concern Polling would be preferable in that regard.
Choose Interrupts or Polling for the following scenarios and explain your choice.
(3) The keyboard on a standard desktop
3) Polling. Interrupts could cause programm pausations in undesired moments.Additionally often we would also like to know if a key was pressed for x amount ofseconds which would not be measurable with Interrupts
Choose Interrupts or Polling for the following scenarios and explain your choice.
(4) The temperature-sensor of a weather-station
4) Polling. This allows for better planability of ressource usage. (I.e. how would onescale Interrupts to get high enough detail without having a lot of interrupts whentemperature changes quickly)
How is an ISR done?
► ISR is triggered by event
▪ Save return address (PC) to stack
▪ Clear global interrupt enable bit (I bit)
▪ Clear interrupt flag bit (usually)
▪ Jump to corresponding interrupt vector table entry (interrupt vector)
► Execute jump instruction at interrupt vector
► Save additional context (anything not automatically saved by hardware)
► Execute ISR body
► Restore context
► Leave ISR by assembly instruction RETI
▪ Return to PC popped from stack
▪ Set global interrupt enable bit (maybe delayed)
What is a counter?
Hardware unit that counts external events (Rising edges, falling edges, arbitrary edges)
What is a timer?
Special counter that counts clock cycles
How is the reading and writing of a 16 bit value made atomic?
Parallel reading and writing by Reading the Low-Byte and Writing the High-Byte first, then vice-versa. (However disabling ISR is neccessary)
What is a Watchdog?
A watchdog is a timer that counts from an initial value to zero. When zero is reached, the μC is restarted. In the main loop of the program, the watchdog counter is reset tothe initial value.This is useful to recover from unintended infinite loops: When themain loop is not executed for too long, the Microcontroller restarts.
Why might it be necessary to temporarily disable interrupts when reading 16 bitvalues?
Reading 16 bit values requires two cycles (on 8-bit platforms). Interrupts could occurbetween those two cycles and could corrupt the 16-bit value that is accessed by themain program.
What analog devices can be found on a ATmega16?
- 4 PWM channels
- an 8-channel-10-bit A/D converter (Successive ApproximationConverter)
- an Analog comparator
What is PWM and how does it work?
Pulse width modulation
- produces a rectangular signal
- with a configurable frequency and high time.
PWM is a
- hardware feature
- that usually can produce signals with a much higher frequency than would be possible by producing the signal in software.
PWM can be used to
- reduce the average voltage delivered on a PIN.
What are the disadvantages of the binary weighted resistor circuit?
Many different types resistors or many resistors are needed for BWRC (or many resistors of the same type in series, which is not preferable in practice).
–> This leads to either bad quality of the produced voltage level due to different deviations from the nominal value of the resistances, or to high costs if high-precision resistances are used.
Usual properties of digital I/O pins
▪ are grouped into ports of 8 pins (on 8-bit architecture).
▪ are bidirectional (i.e., can be used as input or output pins)
▪ can have alternate functions (i.e., can be used for purposes different than
digital I/O, e.g., as analog I/O pins)
What is the meaning of DDR?
Data Direction Register