STM32G0 Programmable Voltage Detector  - Page 1
Forum section: electronics / general

author: Red_Micro
author_rank: Regular Contributor
timestamp: February 25, 2022, 01:30:21 am
content: I'm checking the PVD example from STM32G0 repository in CubeMx and something looks backwards to me unless I'm misunderstanding it. I'm expecting the rising callback when the voltage is ABOVE the threshold not below like the code shows. Likewise, I'm expecting the falling callback when the voltage is BELOW threshold. But the code behaves the opposite, that is, the falling callback comes in when the voltage is above ~2.6V and rising callback when is below ~2.5V.Here is part of the code:Code:/* Configure the PVD Level to 3 and generate an interrupt on rising and fallingedges(PVD detection level set to 2.5V, refer to the electrical characteristicsof you device datasheet for more details) */sConfigPVD.PVDLevel = PWR_PVDLEVEL_3;sConfigPVD.Mode = PWR_PVD_MODE_IT_RISING_FALLING;Code:void HAL_PWREx_PVD_PVM_Rising_Callback(void){/* Turn Off LED1 as voltage is below threshold */BSP_LED_Off(LED1);/* Set uwToggleOn global variable to zero to disable toggle */uwToggleOn = 0u;}void HAL_PWREx_PVD_PVM_Falling_Callback(void){/* Turn On LED1 as voltage is above threshold */BSP_LED_On(LED1);/* Set uwToggleOn global variable to one to disable toggle */uwToggleOn = 1u;}

author: thm_w
author_rank: Super Contributor
timestamp: February 25, 2022, 10:49:10 pm
content: Code:void HAL_PWREx_PVD_IRQHandler(void){/* Check PWR exti Rising flag */if (__HAL_PWR_PVD_EXTI_GET_RISING_FLAG() != 0x0U){/* Clear PVD exti pending bit */__HAL_PWR_PVD_EXTI_CLEAR_RISING_FLAG();/* PWR PVD interrupt rising user callback */HAL_PWREx_PVD_Rising_Callback();}/* Check PWR exti fallling flag */if (__HAL_PWR_PVD_EXTI_GET_FALLING_FLAG() != 0x0U){/* Clear PVD exti pending bit */__HAL_PWR_PVD_EXTI_CLEAR_FALLING_FLAG();/* PWR PVD interrupt falling user callback */HAL_PWREx_PVD_Falling_Callback();}}#define __HAL_PWR_PVD_EXTI_GET_RISING_FLAG() (EXTI->RPR1 & PWR_EXTI_LINE_PVD)#define __HAL_PWR_PVD_EXTI_GET_FALLING_FLAG() (EXTI->FPR1 & PWR_EXTI_LINE_PVD)Are you slowly raising the voltage with a clean power supply?Maybe set some breakpoints in there? see if registers are what you expect.Where is the code where you are setting the levels?Quote

author: Red_Micro
author_rank: Regular Contributor
timestamp: March 04, 2022, 12:53:23 pm
content: Quote from: thm_w on February 25, 2022, 10:49:10 pmYes, I'm using a clean power supply. I've set the level 6:Code:/** PVD Configuration*/sConfigPVD.PVDLevel = PPWR_PVDLEVEL_6;sConfigPVD.Mode = PWR_PVD_MODE_IT_RISING_FALLING;HAL_PWREx_ConfigPVD(&sConfigPVD);/** Enable the PVD Output*/HAL_PWREx_EnablePVD();Basically the falling callback is being called during the rising edge (3.01V) and the rising callback during the falling edge (2.91V), not sure if it's how it should work.Code:void HAL_PWREx_PVD_PVM_Rising_Callback(void){/* Turn green LED as voltage is above threshold */}void HAL_PWREx_PVD_PVM_Falling_Callback(void){/* Turn red LED as voltage is above threshold */}

author: cv007
author_rank: Frequent Contributor
timestamp: March 04, 2022, 06:03:31 pm
content: I have an stm32g031 board, and am no expert but...Forget rising/falling naming in PVD, will just call it 'setpoint' here and just pretend its just one valuePVD output (PVDO) is what controls EXTI-PVDO low = Vdd above setpointPVDO high = Vdd below setpointwhen going from low voltage to high voltage (crossing setpoint from below)-PVDO high -> PVDO low = falling interrupt (not falling voltage)when going from high voltage to low voltage (crossing setpoint from above)-PVDO low -> PVDO high = rising interrupt (not rising voltage)So you have clashing names that mean opposite things. I would come up with a way to make this a 'one time think' (via functions) where you can then use pvd without having to do mental gymnastics each time.