All courses › Embedded Systems and Instrumentation
Embedded Systems and Instrumentation: free practice, theory and problems
Computers and microcontrollers store and compute with everything as binary numbers (0s and 1s). To read and write code efficiently, engineers also use hexadecimal numbers as a compact shorthand for binary, and they need to know how negative numbers are represented in a fixed number of bits. Digital logic – gates such as AND, OR, NOT and XOR – are the building blocks all of these operations are ultimately built from, both in hardware and in expressions in C code.
Contents
1. Number systems and digital logic
What is it about?
Computers and microcontrollers store and compute with everything as binary numbers (0s and 1s). To read and write code efficiently, engineers also use hexadecimal numbers as a compact shorthand for binary, and they need to know how negative numbers are represented in a fixed number of bits. Digital logic – gates such as AND, OR, NOT and XOR – are the building blocks all of these operations are ultimately built from, both in hardware and in expressions in C code.
Concepts and formulas
- Positional number systems: a digit at position (from 0, counted from the right) has weight , where is the base ( binary, hexadecimal, decimal).
- Hexadecimal: digits 0–9, A–F (A=10 … F=15). Two hex digits make exactly one byte (8 bits).
- -bit unsigned integer: range to .
- -bit signed integer (two's complement): range to . The top bit is 1 for negative numbers. A negative number is represented as the unsigned number .
- Bitwise operators in C:
&(AND),|(OR),^(XOR),~(NOT/complement),<</>>(shift). Shifting left by is the same as multiplying by . - Logic gates: AND gives 1 only when both inputs are 1. OR gives 1 when at least one input is 1. XOR gives 1 when the inputs differ. NOT inverts a single input. NAND/NOR are AND/OR followed by NOT.
- ADC resolution: an -bit ADC with reference voltage has a step size .
How to solve the problems
- Converting between bases: multiply each digit by the base's power and sum (to decimal), or repeatedly subtract the largest possible power (from decimal).
- Two's complement, negative number to bit pattern: compute and write it as an unsigned binary/hex number.
- Two's complement, bit pattern to number: if the top bit is 1, subtract from the unsigned value.
- Bitwise operators: write out each number in binary and work bit by bit.
- Logic gates: build a truth table if unsure, or remember the rule for each gate.
Example
What is written as 8-bit two's complement, in hexadecimal?
- Unsigned bit pattern: .
- in hexadecimal: .
Answer: 0xFB.
Common mistakes
- Forgetting that the top bit determines the sign in two's complement, and that you must subtract from (not just flip the sign of the bit).
- Confusing bitwise AND (
&) with logical AND (&&), or bitwise OR (|) with logical OR (||) – the bitwise operators work bit by bit on the whole number. - Thinking an 8-bit unsigned value can reach 256 – the largest value is .
- Computing ADC resolution with instead of – the standard is a step size of .
Concepts in this part
2. Microcontrollers
What is it about?
A microcontroller is a small computer on a single chip: a processor, memory and input/output pins (GPIO) combined, built to control and read the environment in real time. It connects to sensors and actuators through digital and analog interfaces, keeps track of time with timers, and reacts quickly to events with interrupts. Understanding clock speed, communication protocols and memory types is necessary both to write working code and to judge whether it finishes its job in time.
Concepts and formulas
- GPIO pin: a general-purpose input/output pin configured in software as an input (reads a voltage) or an output (drives a voltage high/low).
- Pull-up/pull-down resistor: gives an input a defined level when nothing else is driving it (e.g. an open switch).
- PWM: a digital signal that switches between high and low with a given duty cycle (the fraction of the period the signal is high). Average voltage: .
- Clock speed and instruction time: an instruction that takes clock cycles on a clock takes time .
- Timer with prescaler and count value : period between overflows .
- UART: asynchronous serial communication (no shared clock), with a baud rate and a fixed number of bits per transmitted word (e.g. 1 start + 8 data + 1 stop = 10 bits).
- SPI: synchronous, with a shared clock (SCK), a separate chip select (CS) per device, data lines MOSI/MISO. No start/stop bits, so throughput bytes/s.
- I²C: synchronous, two lines (SDA, SCL) with open-drain outputs and pull-up resistors – devices can only pull the line low, never drive it actively high, so pull-ups are needed to bring the line back high.
- Interrupt: the CPU jumps to an interrupt service routine (ISR) when an event occurs, instead of continuously checking (polling).
- Memory: RAM is volatile (loses its content without power, used for variables), flash/EEPROM is non-volatile (keeps its content, used for program code/stored data).
How to solve the problems
- Identify what quantity you need: voltage/duty cycle, a time interval, or a byte/bit rate.
- For PWM: use , or find from the pulse length divided by the period.
- For timing: find the time per clock cycle () and multiply by the number of cycles or instructions.
- For communication: count the bits per transmitted unit (UART has start/stop bits, SPI and I²C normally do not) and divide the clock frequency by that number.
- Check whether the answer is realistic: microseconds for single instructions, milliseconds for typical timer periods.
Example
A program with 200 instructions, each taking 4 clock cycles, runs on a microcontroller with a clock speed of 8 MHz. How long does the program take?
- Total number of cycles: .
- Time per cycle: µs.
- Total time: µs.
Answer: 100 µs.
Common mistakes
- Counting start and stop bits for SPI/I²C, which do not have them (only UART does).
- Forgetting to add 1 to the count value for a timer ( cycles, since the counter starts at 0).
- Mixing MHz and Hz, or µs and ms, in the same calculation.
- Thinking a pull-up resistor is needed on every digital output – it is only needed where nothing actively drives the line (open switches, I²C lines).
Concepts in this part
3. Measurement
What is it about?
Instrumentation is about turning a physical quantity (temperature, force, light, motion) into a reliable digital number a microcontroller can use. Along the way you must choose the right sensor, amplify/condition the signal, sample it at the right frequency and filter out noise and aliasing – and you need to know how much you can trust the result (accuracy, precision, resolution).
Concepts and formulas
- Sensitivity: the change in a sensor's output per unit change in the measured quantity, e.g. mV/°C.
- Accuracy vs. precision: accuracy is how close the measurements are to the true value (systematic error), precision is how tightly the measurements are clustered (spread/noise).
- Nyquist criterion: the sampling frequency must be more than twice the highest frequency component in the signal, , otherwise aliasing occurs.
- Aliasing: a signal with frequency appears after sampling as a lower frequency for some integer (whichever is closest to 0).
- Anti-aliasing filter: a low-pass filter placed before the ADC that attenuates frequencies above before sampling. The attenuation at a frequency for a single RC stage is dB.
- Wheatstone bridge: four resistors in a bridge configuration turn a small resistance change (e.g. from a strain gauge) into a measurable differential voltage.
- Strain gauge: , where is the gauge factor and is the strain.
- RTD (e.g. PT100): the resistance increases approximately linearly with temperature, , with Ω and Ω/°C for PT100.
- Thermocouple: produces a small voltage from the Seebeck effect, proportional to the temperature difference between two junctions.
- Quantization error: for an -bit ADC with reference , the maximum error is LSB .
How to solve the problems
- Work out which concept the problem is about: sampling/aliasing, sensor/bridge, or ADC resolution.
- Sampling: check whether . If not, find the alias frequency by folding around .
- Anti-aliasing filter: plug and into the dB formula, or find for a desired attenuation.
- RTD: plug the temperature into .
- Strain gauge/bridge: use directly, or compute the bridge's differential voltage from .
Example
A PT100 sensor has Ω and Ω/°C. What resistance does it have at 80 °C?
- Plug into the formula: .
- Ω.
Answer: 130.8 Ω.
Common mistakes
- Using instead of (at exactly the Nyquist frequency the signal is still ambiguous).
- Forgetting the anti-aliasing filter and thinking alias frequencies can be removed afterward – they cannot, the information is lost once sampling has happened.
- Confusing accuracy (small systematic error) with precision (small spread) – a sensor can be precise without being accurate.
- Using instead of in the quantization formula (the standard is a step size of ).
Concepts in this part
Example problems with solutions
Here are some of the problems in embedded Systems and Instrumentation. In the app, calculation problems get new numbers every time, so you can practise until it sticks – and take a graded practice exam before the real one.
Number systems and digital logic: What is 0x1F in decimal?
Answer: 31
.
Microcontrollers: A 5 V PWM signal has a 25 % duty cycle. What is the average voltage?
Answer: 1.25 V
V.
Measurement: The Nyquist criterion says the sampling frequency must be …
Answer: more than twice the highest frequency in the signal
Otherwise you get aliasing.
Number systems and digital logic: What is the binary number 1010 in decimal?
Answer: 10
.
Matches these university courses
The content covers the syllabus found in engineering degrees, for example:
- ELFT2500 (OsloMet)
- FYS103 (NMBU)