The finally knob works! Turn it and the lights follow it, smoothly, all the way from off to full. There is a video just below to demonstrate. Getting there cost me a day of blaming the wrong things, but that's why troubleshooting is so important, even if it does take forever.
What I thought was wrong
The symptoms were textbook. The raw analogue reading sat near the top of its range, never dipped below about 90%, and momentarily jumped to a different value on every sweep. That pattern has two well known causes and I worked through both of them.
The first is a potentiometer that is not actually acting as a divider. A pot needs all three legs connected, one outer to the supply, one outer to ground and the wiper feeding the input. Leave an end open and the maths quietly stops working, because an analogue input draws almost no current, and no current through a resistance means no voltage drop across it. The wiper then parks at whichever rail it can still see, wherever you point the shaft. I checked it with a meter. About 10 kΩ across the outer legs, no change as I turned the shaft, and a clean 0 to 10 kΩ sweep from wiper to one end. The pot was fine.
The second is over-smoothing. Filter the readings too hard and the dial lags noticeably behind your hand, which feels broken rather than smooth. I loosened the filter. No change.
At that point I had eliminated the pot, the wiring and the software, which should have told me something. Instead I went round again.
What was actually wrong
The board.
An analogue-to-digital converter does not measure voltage in the abstract. It measures a voltage as a fraction of a reference, and everything it reports is relative to that reference. If the reference is stable, a wiper sitting halfway up the track reads as halfway. If the reference is floating around, the same wiper position reads as whatever it feels like at that instant.
The dev board I had been using is one of the cheap clones. Externally it looks like the real thing and the digital pins all behave. What it never brought out was the analogue reference. No dedicated reference pin, none of the filtering that is supposed to sit behind it. So the converter was working from a reference that moved with whatever the rest of the board was doing, and reporting numbers that had no fixed meaning.
Every measurement I had taken to rule out the pot was correct. It just could not see the fault, because the fault was downstream of everything I was probing.
I swapped in a genuine Pico, changed nothing else, and the reading swept cleanly from zero to full scale first time.
So that's another valuable lesson learnt, sometimes the more expensive option is actually cheaper in the long run.
What it looks like now
The LED follows the knob across the whole travel. The dim end is smooth rather than stepping, which is the gamma correction earning its place: perceived brightness runs roughly as the 2.2 power of duty cycle, so a linear map makes the bottom half of the dial do almost nothing and then jump. With twelve bits and a correction curve, the bottom of the dial is where most of the visible change happens, and that is where a night cockpit spends its time.
The switching frequency is set at 30.5 kHz for a reason that only shows up on camera. A phone exposes each scanline for tens of microseconds, so anything much slower appears as rolling dark bands across the panel even though your eye sees a steady light. People film their pits, and a panel that looks fine in the room and terrible on video is a panel that gets bad press, and rightly so!
The next two jobs
1 - Put it back in front of DCS. Everything so far proves the hardware half. What it does not prove is that the round trip still works: the knob driving the cockpit dimmer, and the aircraft's own lighting value driving the PWM back out. That is the next session.
2 - Settle the series resistors. I have been running 100 Ω, and watching this test through a piece of acrylic, it is brighter than it needs to be. A backlit legend wants to be readable in a dark room, not to light the room. So I am leaning towards a larger330 Ω resistor instead.
That is worth more than it sounds. Raising the resistor value cuts the current through every LED, and there are 46 of them in my test panel, so it comes off the total three times over. Smaller supply, cooler switching hardware, more headroom everywhere downstream.
The bit worth remembering
I spent a day proving three components innocent, which is the right work in the wrong order. The lesson I am taking is that when everything downstream measures correctly and the reading is still wrong, stop measuring the circuit and start suspecting the reference, or indeed the entire microcontroller.
The cheap board cost about a fiver less than the real one, but it cost me nearly a whole day in troubleshooting!
0 comments