Hello: I have a keyboard that has both buttons to scan, and LED’s to light. No issues with the keyboard scan, that is working OK, There are 20 LED’s, but at most only 6 would be ON at any time. I’m presently using a timer at a rate of 15ms to avoid flicker, but as the number of LED’s ON approaches 6, the flicker is more apparent. Hoping to get some advice on what the best way to do this. My control loop is set to “PWM” the on time such that it doesn’t exceed the maximum power for the LED. In that loop, which is within the call of the timer task, I am using vTaskDelay(x) where x is the time it’s on before I switch of that LED in the double indexed for loop. Presently, that’s set to 5ms It seems that if I had 6 LED’s set to be ON, and the delay time ON of each is 5ms, and that total delay is 30ms, which is longer than the timer task rate of 15ms. Is this correct, and if so, how can that be? If this sin’t the best way to do it, can someone please provide an outline of a better method that would provide better light uniformity (ideally, less flicker) Thanks for your help !
If you cycle 6 LEDs on for 5ms each, that will take 30ms for the full cycle, which since LEDs don’t have persistance, may well show a flickering. You really need to be switching the LEDs on and off much faster. If I were to do something like this, (needing the control to be in software), I would find an auxilary hardware timer and configure it faster, like maybe a 1 ms period. I would then inside the ISR for that timer turn off the current LED, and select the next one in a 6 element array (And there should be a value you can put in that array to mean ‘NO LED’). This operation should be quick so appropriate for an ISR, and doing the work in the ISR saves a lot of time since you don’t need the scheduler to switch the task in and out. By always cycling through the six slots, the brightness won’t change based on the number of LEDs being lit. With a 6ms cycle period, you should not be able to see the flicker.
That’s a great suggestion, and makes perfect sense. I have a few timers on the STM32F4, so it won’t be trouble to find an unused one. Thanks!
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.