ZHCAE13B May 2024 – April 2025 TPS2HCS10-Q1
电流检测代码示例展示了 HCS 系列智能保险丝高侧开关如何实现可扩展且极其灵活的电流检测。此代码示例会设置 1ms 的时间,以便定期唤醒高侧开关通道 1 的负载电流并对其进行采样。如果负载电流低于 500mA,则器件启用高侧开关的以下设置:
在每个事件上都会设置一个断点行,以允许用户中断并理解电流检测的行为。当在软件中进入低电流检测模式时,会设置状态变量 (inLowCurrent) 以指示当前状态,器件会继续定期对电流采样。如果电流电平使 ADC 读数饱和,则会退出低电流模式并使用正常调节或 KSNS 模式。以下代码中演示了相关代码的一个片段:
while(1)
{
__WFI();
/* Reading the load current value. Read the register twice
as the */
resCode = HCS_readRegister(TPS2HCSXX_ADC_RESULT_CH1_I_REG,
¤tValue);
resCode.byte |= HCS_readRegister(TPS2HCSXX_ADC_RESULT_CH1_I_REG,
¤tValue).byte;
/* For each transaction, the high-side switch returns an error
status code that reports common faults of the device. */
if(resCode.byte != 0)
{
handleError(resCode);
}
/* Masking out the relevant bits */
currentValue &= TPS2HCSXX_ADC_RESULT_CH1_I_ADC_RESULT_CH1_I_MASK;
/* Check to see if the threshold is below where to turn
on current sense scaling and change the KSNS ratio and enable
scaling by 8x. This allows for */
if((currentValue < LOW_CURRENT_SNS_THRESHOLD) &&
(inLowCurrent == false))
{
exportConfig.diagConfigCh1.value.bits.OL_ON_EN_CH1 = 1;
exportConfig.diagConfigCh1.value.bits.ISNS_SCALE_CH1 = 1;
inLowCurrent = true;
HCS_writeRegister(TPS2HCSXX_CH1_CONFIG_REG,
exportConfig.diagConfigCh1.value.word);
/* Adding place to set a breakpoint for the sake of demonstration */
asm ("nop");
}
else if((currentValue == LOW_CURRENT_SNS_SATURATION) &&
(inLowCurrent == true))
{
exportConfig.diagConfigCh1.value.bits.OL_ON_EN_CH1 = 0;
exportConfig.diagConfigCh1.value.bits.ISNS_SCALE_CH1 = 0;
HCS_writeRegister(TPS2HCSXX_CH1_CONFIG_REG,
exportConfig.diagConfigCh1.value.word);
/* Adding place to set a breakpoint for the sake of demonstration */
asm ("nop");
}
}
由于能够检测低电流并启用调节和 KSNS 模式,高侧检测能够调节电流检测分辨率,并满足需要高电流检测精度的应用的要求。