Microcontroller Engineering Flashcards

to pass mate (132 cards)

1
Q

What is firmware?

A

code that is able to interact direct directly with hardware

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

embedded systems compared General purpose computers

A

very limited feature hardware
heavy hardware interaction
limited memory
low level communication
crash resistant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Main components of a microcontroller

A
  1. core
  2. memory
  3. GPIO ports
  4. on chip peripheral devices eg. ADCs, timers and communications
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are the two types of buses and what do they do?

A

Advanced high performance bus (AHB) - connects CPU to memory and other high performance devices.

Advanced peripheral bus (APB) - connects group of on chip peripheral devices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you connect APB and AHBs

A

bus bridges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How are instructions executed, and what is the benefit of the pipeline, over not pipelined

A

Fetch, decode and execute and benefit they are executed in parallel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Status registers?

A

contents can be read determine the status of the peripheral eg true, false, busy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Control registers?

A

commands can be written to control the operation of the peripherals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Data registers?

A

used as a temporary store for data being processed by a peripheral

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are three clocks present in microcontroller

A

High speed Internal, High speed external, and phase locked loop (PLL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What pins are exceptions to GPIO

A

Power and ground pins, and reset pins

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

IO pins are grouped together to form?

A

Ports

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Number of pins per port is related to, and

A

the word length of the microcontroller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What other type of I/O can pins be configured to be?

A

Alternate functions like ADCs and serial inputs, UARTS, I2C,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is the point pull up and pull down resistors and with reference to VDD AND VSS

A

they prevent the pins from going into a floating (Voltage not strictly defined) state, by either choosing VDD (power supply voltage) VSS (ground or reference voltage). this helps with noise and mitigation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what ways can microcontroller operate for inputs

A

push/pull/neither (if going in input)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What ways can microcontroller operate for outputs

A

open drain/push or pull (if going out output, and if not VDD present open drain)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

three pieces of information that the user must specify in order to configure a GPIO input at register level

A
  1. Mode (Input or output)
  2. Clock speed
  3. pull up or pull down resistor?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

three pieces of information that the user must specify in order to configure a GPIO input at register level

A
  1. Mode (Input or output)
  2. Clock speed
  3. pull /pull or open drain ?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is abstraction?

A

Abstraction is the act of hiding all the unnecessary details or code of a program, that we are not concerned with. Like mbed abstracts a lot of detail away

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

what are the benefits and drawbacks of embed or abstraction?

A

Benefits:
Simplified code development
Can separately error check
speeds up progress
Drawbacks:
can be bloated as takes up a lot of space
additional layers of library reduce performance
less control of on-chip resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Whats Object oriented programming

A

programming based on use of objects rather than a list of instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Form of C++ statements

A

Class object (parameters?)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

what can a class and object be thought of as?

A

template for which a specific object can be made, and an object is a specific instance of class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What are the different protection levels and explain them
Public - can be accessed from outside the class private - cannot be accessed from outside the class protected - cannot be accessed from outside the base and derived class
26
write a program to read from the output by creating an object and using read function
DigitalOut my_output(A5) int value = my_output.read()
27
what are data members in the class
They are the variables
28
what are the member function
functions used to manipulate the data members
29
what are constructors in classes
they are member functions have the same name as classes, to ensure data members are correctly initialised.
30
When can we overload constructors?
Name? Number of parameters? types of parameters?
31
what selectors and modifier functions
1. selectors read the the values for example float getLength(void) {return l;}, has read access to state of an object 2. modifiers set values void setLength(float length) {l = length;}, has read/write access to state of an object
32
What are const member functions?
They help keep the 'selector' member functions constant, unmodified even after it might have been changed on the modifier. eg float getWidth() const { return width; }
33
Whats this pointer? explain?
if the data member and the parameter, have the same name you can use the this pointer to point the parameter to the data member.
34
what is a static variable?
1. static variables are variables allocated once in a programs lifetime memory, meaning the variable is not reinitialised each time the function executes, unlike non static it deletes and reinitialises itself each time 2. eg static int counter = 0; 3. we can do this with constructors within a class 4. we can also do this for functions (they can only call static data members)
35
How would you implement static variables in a class?
public: static int no_rectangles; Rectangle(float length, float width) : l(length), w(width){ no_rectangles++; } Rectangle(float length) : l(length), w(length) {no_rectangles++; } then outside the class is Rectangle::no_rectangles = 0;
36
What is scope control and give an example of your understanding?
refers to the visibility of variables and other data members to different areas of the program. e.g data members are in the scope of the class, where they are declared.
37
what are the three considerations for analogue to digital conversion, and explain them briefly
1. Dynamic range - range of values an ADC can measure without being distorted, values outside this have become distorted and saturation has occurred. can use offset, but still has to fit innit 2. Resolution - mapping signals that are continuous in time to be discrete in time, it is a lossy process, the more bits we use the better. 3. Sampling rate - how often we get a sample of the signal.
38
why should we try to match our dynamic range to our ADC?
because if we don't large amount of digital values are unused and leads to higher quantisation error. (assuming we have the same number of bits available)
39
what does the sampling theory state, and whose rate is it
states that the minimum sampling frequency should be at least twice that of the highest frequency, Nyquist rate.
40
if we fail to adhere to the sampling theory, what do we do
We use an Aliasing filter, which removes the signals with the frequencies higher than 2 times out frequency. has a resistor then a capacitor pointing downwards
41
what are the stages of ADC, explain briefly
1. sample hold circuits (uses capacitor downwards then, an amplifier thingy) 2. digital ramp, SAA.
42
explain successive approximation algorithm
1. uses most significant bit 2. then 2^(how many bit range there are) 3. then compare to the sample hold signal 4. then the boxes have compare two below it
43
what does the ADC require to accurately represent digitised waveforms?
we need one or more reference voltages, maximum and minimum analog voltages our ADC can represent
44
How do we access the ADCs
The ADCs are a peripheral device so occupy memory space in the address space
45
At a high level what are the three stages to interacting with the ADC ?
Configuration - configure how want it to behave eg. 12 bit register Control - need to send commands to make it perform tasks like start conversion Accessing the result - need to access result using data registers
46
What registers are used by the ADC
status - check for when finished interrupts etc control - provides some control Data - returns data from peripheral device
47
whats the first step in configuring an ADC?
make sure the pin you wish to use in configured for analogue input as its alternate function
48
give me 5 important parameters of ADC
The clock frequencies The bit configuration for output The source of reference voltages The channel to be sampled wether the ADC has an interrupt
49
Explain the difference between polling vs interrupts?
Polling involves constantly checking to see if an event has occurred, while interrupts signals the CPU when an event occurs
50
Interrupt service routines, explain a little, how do they make stuff efficient.
1. triggered by an interrupt event(not function from main code) 2. must be configured in advance, so program knows what action to take 3. they are transient, they are executed, then conclude, and then program return to the main line code. this should make the ISR efficient, so CPU can devote maximum time to main line code
51
Give me sources of hardware interrupts
GPIO pins:theres rising edge, falling edge On chip peripheral devices: timers (fixed time elapse) ADCs (End of conversion) communication interface(bytes received)
52
Whats the mechanism for response to an interrupt
The main mechanism id to have a fixed address in our program code in the sense that, an interrupt occurs, stops main like code and then return is used to return it back to main line program code
53
What should we avoid putting in our interrupt ISR, and explain why
We should avoid putting loops(while and for), lengthy function calls and execute blocking functions(delay ). because ISRs should have minimum impact on the main line code
54
Whats an exception?
An event that occurs that stops the CPU from executing main line code
55
What are hardware interrupts?
can be generated at any time, and are asynchronous, with respect to execution of program code, they are received from outside. the CPU, don't have to occur as CPU instructions are executed eg rising edge on GPIO, timers, communication peripherals
56
What are software interrupts?
tend to occur in response to execution of the main line code and they are synchronous, can only occur when the program executes.
57
Whats a type of exception that can occur when running software
attempting to divide by 0
58
what does volatile do?
informs a compiler that a variable might change without its knowledge
59
what are maskable and non maskable interrupts? and give examples
maskable interrupts are interrupts that can be ignored and delayed.(eg rising edge from GPIO pins) and non maskable interrupts are interrupts that cannot be ignored or delayed eg reset button
60
what device handles interrupts on the STM32 controller?
Nested vector Interrupt controller
61
Briefly explain interrupt priority
The smaller the number, the higher the priority, negative ones cant be changed, they are fixed and represent core exception and positive ones can be determined by the programmer
62
Explain the terms (interrupt) Active pending Inactive pending and inactive
Active: interrupt is being executed, but has not finished yet pending: interrupt has been detected but is waiting to be execute Inactive: neither pending or active pending and active: currently processing an interrupt and the same source has generated another interrupt request
63
whats pre-empt
this is like interrupting or disturbing a current interrupt only ones of higher priority can do this
64
The interrupt source on the STM32 contains what information
interrupt Flags (1 bits) interrupt enable bit(1 bit) a priority( 4 bits)
65
What does the interrupt API respond to
interrupt API responds to rising or falling edges
66
what type of function executes when an interrupt is called, and give or write down how its coded?
a callback function, input.rise(&risingISR) the &modifier function button.rise(&pressedISR.
67
Maximum value of the counter is dictated by?
Number of bits that the counter has
68
Briefly explain how a timer is implemented by a microcontroller
1.Timers are constructed from counter 2. counting can be slowed down by delaying by multiples of the clock frequency 3. counter is set to roll over user defined value known as the auto reload register ( interrupts to trigger every time the counter overflows ) 4. so counting to a specific value with a known clock frequency allows measurement of time periods
69
What are the two variables that dictate the frequency of our timer?
1. frequency of the base clock that we use 2. value at which the counter generates an interrupt
70
whats the time for 30 bit counter given a frequency of 20 hz
1/(frequency) x 2^(30) = 53687091.3
71
Whats maximum count value (Cmax)
1. This is the maximum value at which our counter will generate an interrupt, and roll over and start counting from zero again Cmax =< 2^(N) -1 2. so this depends on the pre-scaled value (𝐹𝑃𝑆_𝐢𝐿𝐾 = 𝐹𝐢𝐿𝐾\PS (Hz) )of frequency and the value of time we want C max= (T/Tps)
72
what other features apart from counting can the counter/timer peripheral do and explain them?
Input capture: used to count external events Output capture: used to generate events at particular intervals. eg pulse width modulation
73
whats pulse width modulation?
digital signals used to approximate analogue signals by varying the duty cycles of the periodic signals
74
timers on the STM32 are grouped by?
Core system timers Advanced control timers General purpose timers
75
timers on the STM32 are either contained in the ------ or are ------ ( how are they connected?)
core or are on-chip peripheral devices, connected to the APB1 and APB2 buses
76
General purpose timers can be configured in what ways
1. To provide a time-base 2. Input capture 3. Output capture 4. Pwm signals
77
On the STM 32 what is Cmax referred to as
It is referred to as the ARR (Auto reload register)
78
whats the equation for timer on STM32
π‘“π‘‘π‘–π‘šπ‘’π‘Ÿ =π‘“π‘π‘™π‘˜/((𝑃𝑆𝐢 + 1 )(𝐴𝑅𝑅 + 1))
79
what are three three types of counters on the STM32
1. Up (Overflow event) 2. Down (underflow event) 3. Up/Down ( overflow and underflow event)
80
Mbed three support API and explain
1. timer (provides simple time measurements) 2. timeout ( Executes an ISR (Callback) when a specified time period is reached) 3.Ticker: (Executes an ISR (Callback) repeatedly when a specified time interval is reached)
81
What is inheritance?
1. Allows us to define a class in terms of another class. 2. The derived class inherits member functions and data members from the derives class. 3. Typically a derive class adds further member functions and data members to the base class
82
Derived classes have the capability to?
1. override behaviour of the base class 2. Inherit from more than one base class 3. Transitive inheritance, can inherit from a base class who has also inherited from another base class
83
write code or example of how this inheritance is executes, or just think if it mate
class Rectangle: public SimplePolygon rectangle - derived class Simple polygon - base class
84
Describe the access levels of inheritance
public - everything remains unchanged protected - visible only in base and derived classes private - visible only in base class
85
are constructors (or destructors) inherited by a base class?, so what does this mean for us
No, so it is necessary to re initialise both
86
whats polymorphism
means that code behaves differently depending on what context it is executed, it can either be in compile time or run time
87
give me an example of polymorphism that has to do with overloading and state what type
operator overloading : (4+5) and (4.00 + 5.00) constructor or function overloading : int sum(int a, int b) {return a + b;} int sum(int a, int b, int c) {return a + b + c;} float sum(float a, float b) {return a + b;} compile time polymorphism )
88
Another name for compile time polymorphism is
static binding
89
What is run-time polymorphisms and how is it implemented?
typically implemented through inheritance and function overriding so basically the same function in the derived class overwrites the function in the base class
90
What us run time polymorphism termed?
dynamic binding.
91
what happens if we create function pointers to the base class?
1. it does not overwrite anything, if we expected to because it is statically bounded, because basis is taken on the type of pointer and not the the content. example: 2. SimplePolygon *myPolygon SimplePolygon poly1(1,1); myPolygon = &poly1; printf("Area is: %f\n",myPolygon->getArea());
92
How can we fix the problem of pointers to the base class and function not being overwritten
add virtual in front of the function eg virtual float getArea() { printf("For a shape to have an area it must have a geometry!\n"); return 0.0;}
93
what is serial and parallel communications and when is it commonly used?
serial - transferred bit by bit and is commonly used when communication between devices parallel- transferred multiple bits in one go and used for data transfer within a device
94
Explain simplex full-duplex Half- duplex
Simplex - one device can only send and one (or more) devices can only receive eg. TV, broadcast Full-duplex - both devices can send and receive at the same time Half- duplex - both devices can send and receive but not at the same time eg UHF radio
95
How are data bits transmitted by serial communication, and explain how is this implemented using tx and rx
the bits are first broken down and transmitted one by one in sequence then, is reassembled. tx - PISO tx - SIPO
96
whats synchronous and asynchronous communication
synchronous - this is when a clock signal is transmitted Asynchronous - this is when a clock signal is not transmitted and they both agree on a common rate
97
whats the baud rate
When two devices agree on a common clock speed
98
how does our receiver know where the stop and start bits are? clue/ there are three indications
1. The signal is held high when idle. 2. start bit: the signal is pulled low for one bit period , then the byte is sent. 3. stop bit: the signal is pulled high for one or two bit periods.
99
Is clocking both tx and rx at the same data rate sufficient to ensure synchronisation? if not what can we do to ensure synchronisation
1. ideally sample the incoming data bits in the centre 2. which can be done with oversampling (to increase probability of centre) 3. typically 16x the baud rate is used
100
what are two common errors, explain them and how can we mitigate them?
1. Overrun errors: receiver can not cope with speed at which data is being received, mitigated by buffers (FIF0) - balances the rate at which if the producer is ove rproducinv 2. random bit errors; mitigated by using odd or even parity (adding an extra bit, to see if the amount of odd or even matches)
101
what is USART? how are they clocked? where is the baud rate from?
1.Universal/synchronous/asynchronous/receiver/transmitter 2. they are clocked by the bus they are connected to 3. the baud rate are generated within the peripheral devices
102
For Asynchronous communications what can we specify
the baud rate stop bits (1 or 2) even using parity? How many bits are in each frame? Over sampling frequency (16x?)
103
How would you implement a serial link?
Connect Tx to Rx and Gnd to Gnd
104
what interrupts does USART accept for Transmit? receive?
transmit: ready to be sent?, buffer empty, sent? receive: incoming data has been received?, and if the buffer is empty or full
105
when does lossy communications occur and is it tolerable?
1. Lossy communications occur when producer might be producing at faster rate than consumer can receive and leads to maybe a loss in communication at some point in time 2. its tolerable maybe in video transfer but not in all cases where an important file is to be transferred
106
what rate do we have to work out between the producer and consumer?, and are there any loop holes in this, that we can do instead, to increase maybe our flexibility?
1. we have to operate at whatever rate is the slowest 2. Actually we can introduce a buffer
107
whats a bufffer
A buffer produces temporary memory in which, the producer can store incoming data for the consumer
108
what does the buffer do
1. it allows for if the producer is bursty, which is they produce a lot at some point time and don't produce that much at some point. 2. It allows for the consumer to have a constant rate 3. obv provided we don't exceed the buffer capacity actual
109
Benefits of the buffer
1. Frees the system of requirement to process task immediately 2. development of complex systems which can perform multiple concurrent tasks
110
how does put and get work?, rough descriptions?
for buffer ( int buf[8] = {};) then the initialisations for in, out, count and size for putting stuff in the buffer: use get() void put (int i) { then go through index [i]++count} for getting stuff out the buffer: use get() void get (int i) {go through index --count}
111
Memory is set out in four different stages which are? and which are determined at compile time
1. Heap 2. Stack 3. Global/static variables 4. program code 2-4(compile time)
112
what happens when we create variables inside code blocks? Explain substantially clue step by step
1.When we do this, memory is allocated to the variables automatically when the code for the function block is entered and deletes when the function is terminated 2. the automatic variables are then places on top of a stack called run-time stack are are accessed by stack pointers (R2 and R1), R2 at the bottom in which instructions are executed first up to R1
113
how much memory do we require for these? and how would they be implemented on the stack memory? int myInt = 5; char myChar = 32; int anotherInt = 100; float myFloat = 1.2
Integers and floats (4 bytes) characters (1 byte) implementation: float myFloat = 1.2 (4 bytes) SP- R1 int anotherInt = 100; (4 bytes) char myChar = 32; (1 bytes) int myInt = 5; (4 bytes) SP- R2
114
whats happens if a subsequent function is called in a function
It goes on top of the stack frame carrying R2 and R1 with it
115
What is stack overflow?
Stack overflow is when program contains large number of nested functions in which we run out of space on the stack
116
whats dynamic allocation of memory
dynamic allocation of memory is when memory is not allocated at compile time but rather at run time eg ~(the heap)
117
How do we search the heap for free memory? specifically 200 bytes
char mydata[200]
118
how do I allocate memory at run time and how do i delete it
int *mypointer = new int (4 bytes) delete mypointer
119
How do I allocate memory at runtime for lets say 10 integers and how do i delete it
int *mypointer = new int [10] (40 bytes) delete mypointer[]
120
How do i allocate memory for a rectangle in a class and how do i delete it
int *myrectangle = new rectangle(1,1) delete myrectangle
121
whats the point of destructors?
1. they destroy memory allocated at run time because it doesn't delete automatically like run time stack they are given by ' ~' 2. reason we don't see it is because our compiler automaticall does this for us
122
What is software?
Computer code that is able to be executed
123
Differences between an embedded system and a general purpose computer?
Embedded system: 1. limited memory 2. heavy hardware interactions 3. crash resistant 4. no operating system 5. very limited hardware 6. Low level communication General purpose computer: 1. substantial memory 2. heavy software interactions 3. crash tolerable 4. operating system 5. high level communication like USB
124
whats the environment of an embedded system?
environment is any hardware or software that the system interacts with
125
what can we differentiate general purpose computers and embedded systems?
How interacts with device? and the environment
126
what can we characterise an embedded system by?
single functioned - usually running a single program repeatedly tightly constrained - constrained by hardware/power supply/ cost limitations real time/reactive - means that rapid response is usually needed
127
what are embedded
embedded systems are devices which can receive inputs, process them and generate outputs
128
what might embedded systems interface with
Other ICs, (other microcontrollers) sensors (inputs) actuators (outputs)
129
whats memory map?
provides address space for registers to be written to and can be accessed by pointers
130
advantages and disadvantages of having on chip peripherals
131
whats quantisation error?
132
how is interrupt executed