低压检测(LVD)模块用于检测低电压和断电。当供电电池电压低于内部参考电压时,触发LVD中断。使用该中断可实现:在断电前将关键数据写入flash、转储日志、触发外部电路等功能。 Note: - 只有实际供电电压低于阈值时,才会触发中断。初始供电电压低于阈值时,不触发中断。
- LVD电路可在Active模式、低功耗(LP)模式、超低功耗(ULP)模式下正常运行。如果需要在深度睡眠下使用LVD,则需配置deep sleep wake-up source,定期从深度睡眠模式中唤醒设备,确保在Active/LPACTIVE模式下运行LVD电路。
- 系统初始化阶段有可能会收到错误的LVD中断。系统启动,完成LVD模块配置的20µs 后自动屏蔽该错误中断。
- 系统进入深度睡眠模式时,如果设置了下降沿触发,或上升沿触发,或两者兼而有之,可能也会收到错误的LVD中断。要解决这个问题,可以在进入深度睡眠模式前禁用该触发设置,退出深度睡眠模式后重新启用触发设置。
LVD驱动(PSoC™ 6 PDL API 参考指南章节之一)文档中提供了管理LVD模块的一系列API 。
下列为配置LVD模块的节选代码,适用于: - PSoC™ 6 设备。
- 电压阈值设为2.7v,当供电电池电压低于或高于阈值时,产生中断。
- /* LVD interrupt configuration */
- const cy_stc_sysint_t LVD_interrupt_cfg =
- {
- .intrsrc=srss_interrupt_IRQn,
- .intrPriority = LVD_INTERRUPT_PRIORITY
- };
- /*******************************************************************************
- * Function Name: LVD_Init
- ********************************************************************************
- * Summary:
- * This function initializes and enables the LVD block by:
- * 1. Setting the LVD threshold.
- * 2. Setting the LVD Interrupt Configuration
- * 3. Initializing and enabling the LVD interrupt
- *
- *******************************************************************************/
- void LVD_Init()
- {
- /* Disable LVD interrupts */
- Cy_LVD_ClearInterruptMask();
- /* Set the threshold value for monitoring the VDDD voltage */
- Cy_LVD_SetThreshold(CY_LVD_THRESHOLD_2_7_V);
- /* Set configuration for LVD interrupt */
- Cy_LVD_SetInterruptConfig(CY_LVD_INTR_BOTH);
- /* Enable the LVD Block */
- Cy_LVD_Enable();
- /* Provide delay to avoid false interrupt detection */
- Cy_SysLib_DelayUs(20U);
- /* Clear any false interrupt */
- Cy_LVD_ClearInterrupt();
- /* Initialize the LVD interrupt */
- (void)Cy_SysInt_Init(&LVD_interrupt_cfg, LVD_interrupt_handler);
- /* Enables LVD interrupts */
- Cy_LVD_SetInterruptMask();
- NVIC_EnableIRQ(LVD_interrupt_cfg.intrSrc);
- }
- /* Interrupt Handler */
- void LVD_interrupt_handler()
- {
- /*Do the necessary processing if the voltage drops below the set threshold */
- /* Clear the interrupt */
- Cy_LVD_ClearInterrupt();
- }
|