For the calculation of the battery runtime we have a precompiled library which does help you realize the function.
You can download the precompiled library here:
https://kk-t.com/wp-content/uploads/2025/04/libRuntime_2025_04_22.zip
You can find different libraries for different use cases:
ARMCLANG_M0_SOFT
This library is built for Arm Cortex M0 controller without a hardware FPU using the ARMCLANG Compiler V6.19 (There is no FPU available for M0 Cores anyway). The library is built against the following settings: -xc -std=c11 –target=arm-arm-none-eabi -mcpu=cortex-m0 -c
ARMCLANG_M3_SOFT
This library is built for arm cortex M3 controller without a hardware FPU using the ARMCLANG Compiler V6.19. The library is built against the following settings: -xc -std=c11 –target=arm-arm-none-eabi -mcpu=cortex-m3 -c
ARMCLANG_M4_SOFT
This library is built for Arm Cortex M3 controller without a hardware FPU using the ARMCLANG Compiler V6.19. The library is built against the following settings: -xc -std=c11 –target=arm-arm-none-eabi -mcpu=cortex-m4 -c
ARMCLANG_M4_HARD
This library is built for Arm Cortex M4 controller with a hardware FPU using the ARMCLANG Compiler V6.19. The library is built against the following settings: -xc -std=c11 –target=arm-arm-none-eabi -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -c
ARMGCC_M0+_SOFT
This library is built for Arm Cortex M0 controller without a hardware FPU using the ARMGCC Compiler (There is no FPU available for M0 Cores anyway). The library is built against the following settings: -mcpu=cortex-m0plus -std=c11 –specs=nano.specs -mfloat-abi=soft -mthumb
ARMGCC_M3_SOFT
This library is built for Arm Cortex M3 controller without a hardware FPU using the ARMGCC Compiler. The library is built against the following settings: -mcpu=cortex-m3 -std=c11 –specs=nano.specs -mfloat-abi=soft -mthumb
ARMGCC_M4_SOFT
This library is built for Arm Cortex M4 controller without a hardware FPU using the ARMGCC Compiler. The library is built against the following settings: -mcpu=cortex-m4 -std=c11 –specs=nano.specs -mfloat-abi=soft -mthumb
ARMGCC_M4_HARD
This library is built for Arm Cortex M4 controller with a hardware FPU using the ARMGCC Compiler. The library is built against the following settings: -mcpu=cortex-m4 -std=c11 –specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb
A full example on how to use the library can be downloaded here:
https://kk-t.com/wp-content/uploads/2025/04/Example_Runtime_2025_04_22.zip
Implementation
Use the example project to understand how everything is initialized and executed. The most important steps are:
- Initialize the library by calling InitRuntime.
- Set the required Runtime or maximum power draw (if you want to keep the maximum power draw to a certain value all the time) by calling SetRuntime.
- Recalculate the DMX Values by calling either DoRuntimeSelectionCalculation16Bit or DoRuntimeSelectionCalculation8Bit.
We will now explain it step by step:
- First add the library to your project ( .a or .lib file and libRuntime.h). This can be done for the different IDE’s like this:
2. Define the necessary information of the led and the battery:
#define LED_COUNT 1
#define DIE_COUNT 5
// The SUM of the power multiplied with ledCount should not be higher than 65535
static const uint16_t POWER_CONSUMPTION_DIE[DIE_COUNT] = {2400,3000,2600,2600, 5100}; // Red, Green, Blue, Lime, Amber in for example milliWatt
static const uint16_t BATTERYENERGYH = 16000; // Battery Energy in Hour for example milliWh
static const uint16_t TIMECONSTANT = 50; // Time Constant for averaging the pwm data
// Runtime Instance
static runtime_instance_t runtime;
3. Initialize the library
InitRuntime(&runtime, LED_COUNT, DIE_COUNT, (uint16_t*)POWER_CONSUMPTION_DIE, BATTERYENERGYH, TIMECONSTANT);
4. Set and change the Runtime and maximum power consumption by calling SetRuntime
SetRuntime(&runtime,BATTERYRUNTIME_20HOURS,0xFFFF);
5. Whenever pwm values are refreshed call the function DoRuntimeSelectionCalculation16Bit or DoRuntimeSelectionCalculation8Bit
uint16_t array[LED_COUNT][DIE_COUNT];
for(uint8_t led=0; led < LED_COUNT;led++)
{
array[led][0] = red;
array[led][1] = green;
array[led][2] = blue;
array[led][3] = lime;
array[led][4] = amber;
}
DoRuntimeSelectionCalculation16Bit(&runtime, array[0]);
// Use array for setting pwm values
That’s it.