# LED driver Simple driver for small LED stripes. ## The motivation We have a lot of small LED stripes with OEM LED drivers. It's a bit cumbersome to turn them all one by one, since you have to cycle through a lot of blinking modes until you get to the stable one. Original idea was to use USB power source, Zigbee USB power switch and [IKEA light switch](https://www.ikea.com/cz/cs/p/styrbar-dalkove-ovladani-chytre-bila-30488363/) and to use single resistor to lower the voltage appropriately. The voltage for these LED stripes is around 3V to 3.5V and the current is around 100mA, so the power loss on the resistor would be less than 0.2W. This worked for the battery-operated stripes, but it turns out the USB powered ones have alternating LED polarity. Odd LEDs are in one direction, even LEDs in the opposite direction. So with the resistor approach we would only get half of the LEDs. So I decided to create a simple driver for these LEDs. ## Requirements * powered from USB * output with alternating polarity and PWM * output voltage - variable LDO? From 5V (minus losses) to 0V * controllable via UART (USB virtual COM port) * current sensing (MCU can be used to regulate current) * **as simple and cheap as possible** We will not use any LED driver IC. We will either simply use constant voltage, or use MCU to do PWM regulation to control the current. ## Design ## Notes ### Build In fw folder run: ``` cmake -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-arm-none-eabi.cmake -S ./ -B Debug -DCMAKE_BUILD_TYPE=Debug arm-none-eabi-objcopy -S -O binary led_driver.elf led_driver.bin st-flash write led_driver.bin 0x8000000 ``` ### Debug ``` st-util # this stays running gdb led_driver.elf # in gdb then: target extended-remote localhost:4242 load ``` ### Design notes - bez zateze (bez zapnutych tranzistoru u H mustku) je samovybijeni cca 0.7 V za 50 ms (v prvni chvili, z 5V na 4.3V) - coz odpovida cca tomu ze tam je zatez (2k || 2k) ohm = 1k ohm, takze casova konstanta RC je 0.3 s, takze na 80% (4V) by se to melo dostat za 0.2 RC = 0.2 * 0.3 s = 0.06 s = 60 ms, coz zhruba sedi - viz [zaznam se Saleae](./data/vybijeni_C_50_ms_strida.sal) - coz zhruba sedi s vypoctem: - $Q_{partial} = Q * dV / V_0 = V_0 * C * dV / V_0 = C * dV = 330e-6 * 0.7 F = 0.00023 F$ - I je zhruba 5 mA (5V, 1k zhruba hodnota delice (viz nahore)) - Q_{partial} / I = 0.046 s = 46 ms, coz zhruba sedi tem 50 ms ktere jsem nameril - TODO zvysit rezistory napetoveho delice, 1k je malo