Fixed-point and integer math lesson plan
Fractions without a float unit, on an Uno and a knob: what floats really cost, Q formats, scaling, overflow guards, tables and fast trig. Ends with a fixed-point filter you tune and measure.
Objectives and materials
By the end, students can
- Time what a float costs, then keep fractions in integers on purpose.
- Scale a knob to millivolts, and guard every sum against overflow.
- Work it out once and look it up: gamma curves and a quarter-wave sine.
- A fixed-point filter on a noisy knob, measured and tuned.
Materials for the whole unit
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Resistor
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Floats and Q numbers
Time what a float costs, then keep fractions in integers on purpose.
| Lesson | Time | What students do |
|---|---|---|
| Why floats costThe Uno has no floating-point hardware. Time int, long and float multiplies with micros(), take off the loop overhead, and find where a float runs out of bits. | 40 min |
|
| Q formatsFractions stored in plain integers: Q8.8 in an int16_t, printing one with integers only, multiply then shift, divide with the shift first, and trading range for precision. | 45 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Resistor
Check for understanding
Each student finishes "Q formats" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Negative numbers too".
Real readings
Scale a knob to millivolts, and guard every sum against overflow.
| Lesson | Time | What students do |
|---|---|---|
| Scaling ADC readingsTurn a 0 to 1023 knob reading into millivolts four ways: a 16-bit sum that wraps, a long divide, a float, and a multiply and shift, timed against each other. | 40 min |
|
| Overflow guardsWhat an int16_t does past 32767, and three guards: saturating adds, __builtin_add_overflow and checking before a multiply, on a knob-driven rocket speed. | 40 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Resistor
Check for understanding
Each student finishes "Overflow guards" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A redline of your own".
Tables and trig
Work it out once and look it up: gamma curves and a quarter-wave sine.
| Lesson | Time | What students do |
|---|---|---|
| Lookup tablesGamma-correct an LED from a 33-entry table kept in flash with PROGMEM, time it against pow(), then interpolate between entries with integers only. | 40 min |
|
| Fast trigSine and cosine from a 65-entry quarter-wave table in Q1.14, with binary angles that wrap on their own, timed against sin() and flown as a satellite orbit. | 45 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Resistor
Check for understanding
Each student finishes "Fast trig" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A higher orbit".
Project
A fixed-point filter on a noisy knob, measured and tuned.
| Lesson | Time | What students do |
|---|---|---|
| Project: a fixed-point filterSmooth a noisy knob with an exponential moving average three ways, in float, in plain integers and in Q8, then measure the stall, the cost and the settle time, and tune it. | 45 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Resistor
Check for understanding
Each student finishes "Project: a fixed-point filter" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.