Battery Runtime Library

为了计算 battery runtime,我们提供了一个 precompiled library,可帮助您实现该 function。

可以在这里下载 precompiled library:
https://kk-t.com/wp-content/uploads/2025/04/libRuntime_2025_04_22.zip

不同 use cases 对应不同 libraries:

ARMCLANG_M0_SOFT

该 library 使用 ARMCLANG Compiler V6.19,为没有 hardware FPU 的 Arm Cortex M0 controller 构建(M0 Cores 本身也没有 FPU)。Build settings: -xc -std=c11 -target=arm-arm-none-eabi -mcpu=cortex-m0 -c

ARMCLANG_M3_SOFT

该 library 使用 ARMCLANG Compiler V6.19,为没有 hardware FPU 的 Arm Cortex M3 controller 构建。Build settings: -xc -std=c11 -target=arm-arm-none-eabi -mcpu=cortex-m3 -c

ARMCLANG_M4_SOFT

该 library 使用 ARMCLANG Compiler V6.19,为没有 hardware FPU 的 Arm Cortex M4 controller 构建。Build settings: -xc -std=c11 -target=arm-arm-none-eabi -mcpu=cortex-m4 -c

ARMCLANG_M4_HARD

该 library 使用 ARMCLANG Compiler V6.19,为带 hardware FPU 的 Arm Cortex M4 controller 构建。Build settings: -xc -std=c11 -target=arm-arm-none-eabi -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -c

ARMGCC_M0+_SOFT

该 library 使用 ARMGCC Compiler,为没有 hardware FPU 的 Arm Cortex M0+ controller 构建(M0 Cores 本身也没有 FPU)。Build settings: -mcpu=cortex-m0plus -std=c11 -specs=nano.specs -mfloat-abi=soft -mthumb

ARMGCC_M3_SOFT

该 library 使用 ARMGCC Compiler,为没有 hardware FPU 的 Arm Cortex M3 controller 构建。Build settings: -mcpu=cortex-m3 -std=c11 -specs=nano.specs -mfloat-abi=soft -mthumb

ARMGCC_M4_SOFT

该 library 使用 ARMGCC Compiler,为没有 hardware FPU 的 Arm Cortex M4 controller 构建。Build settings: -mcpu=cortex-m4 -std=c11 -specs=nano.specs -mfloat-abi=soft -mthumb

ARMGCC_M4_HARD

该 library 使用 ARMGCC Compiler,为带 hardware FPU 的 Arm Cortex M4 controller 构建。Build settings: -mcpu=cortex-m4 -std=c11 -specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb

完整 example 可从这里下载:

https://kk-t.com/wp-content/uploads/2025/04/Example_Runtime_2025_04_22.zip

实现

使用 example project 理解初始化和执行流程。最重要 steps 如下:

  • 通过调用 InitRuntime 初始化 library。
  • 通过调用 SetRuntime 设置 required Runtime 或 maximum power draw(如果希望始终将 maximum power draw 保持在某个 value)。
  • 通过调用 DoRuntimeSelectionCalculation16BitDoRuntimeSelectionCalculation8Bit 重新计算 DMX Values。

下面按 step by step 说明:

  1. 首先将 library 添加到 project(.a 或 .lib file,以及 libRuntime.h)。不同 IDE 可参考:

2. 定义 LED 和 battery 的必要 information:

#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. 初始化 library

InitRuntime(&runtime, LED_COUNT, DIE_COUNT, (uint16_t*)POWER_CONSUMPTION_DIE, BATTERYENERGYH, TIMECONSTANT);

4. 通过调用 SetRuntime 设置和修改 Runtime 以及 maximum power consumption

SetRuntime(&runtime,BATTERYRUNTIME_20HOURS,0xFFFF);

5. 每次 pwm values refresh 时,调用 DoRuntimeSelectionCalculation16BitDoRuntimeSelectionCalculation8Bit

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

这样就完成了。

© KKT Künzler Technologies GbR.
Developed by KKT - Künzler Technologies GbR