How it works
A thin beam of white light enters an outlined glass prism and leaves as a six-band rainbow (red, orange, yellow,
green, blue, violet), drawn on a 640x480 VGA display (25.175 MHz pixel clock) in the style of the classic prism
album cover. The rainbow is driven live by a PDM MEMS microphone in two ways:
- Waveform: the image is generated by racing the beam, with no frame buffer and no sample memory. Each
scanline takes 31.8 us, so every row of the screen is a moment in time. Just before a row is drawn, the latest
audio sample shifts that row of the rainbow sideways, which makes the slanted bands ripple up and down with the
actual waveform. The shift is multiplied by the distance from the prism (a serial shift-and-add multiply during
horizontal blanking), so the bands stay anchored at the prism and swing most at the far end.
- Loudness: a peak envelope (instant attack, about 130 ms decay) sets the brightness of all the light (the
incoming beam, the glow inside the prism and the rainbow) once per frame. The light is drawn on a loudness-dependent
share of a 4x4 ordered dot pattern, giving 16 brightness steps. In silence the light dims to a faint glow.
Audio path:
- The microphone clock is the pixel clock divided by 16 (1.57 MHz), taken straight from the horizontal counter.
- One scanline is exactly 800 clocks = 50 PDM bits. A 2nd-order sinc (triangle) decimator produces one sample per
scanline: the bits of each row are summed with rising weights (n) and falling weights (49 - n), and the rising
sum of the previous row plus the falling sum of the current row gives a triangle window over two rows. This has
the same response as a 2nd-order CIC filter with R = 50 but needs only three 11-bit accumulators.
- A slow up/down counter tracks and removes the microphone's DC offset.
- A selectable gain shift and saturation reduce the sample to 8 bits.
How to test
Connect a VGA monitor through the Tiny VGA PMOD on the output pins, and a PDM microphone (for example the
Adafruit PDM MEMS Microphone Breakout, product 4346) to the bidirectional PMOD as listed below. Reset the design.
In silence the rainbow is a dim, still fan. Speak, whistle or play music near the microphone: the light
brightens with the loudness and the bands ripple with the waveform.
Inputs:
| Pin |
Function |
| ui[0] |
DAT sample point. 0 (default) samples at the end of CLK high, which suits mics with SEL tied low. If the display shows only noise, set it to 1. |
| ui[2:1] |
Gain: 0 = normal, 1 = x4 (quiet room), 2 = x1/2, 3 = x1/4 (loud music) |
External hardware
- Tiny VGA PMOD on the output pins (uo)
- PDM MEMS microphone, e.g. Adafruit 4346, wired to the top row of the
bidirectional PMOD: uio[0] = CLK, uio[1] = DAT, uio[2] = SEL (driven low), plus GND and 3V3