2022-02-26 04:43 PM
I have an SM32H723 NUCLEO-144 board. I successfully implemented COMP1. It works, but I have some bouncing at the rising and falling edges (100Hz signal). I found a COMP_OutputBlanking example for NUCLEO-H7A3ZI-Q (No blanking example for NUCLEO-H723ZG) I successfully added the “blanking�? code to my project but the result is terrible.
Here is my init code:
static void MX_COMP1_Init(void)
{
hcomp1.Instance = COMP1;
hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_VREFINT;
hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO2;
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH;
hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_TIM1_OC5;
hcomp1.Init.Mode = COMP_POWERMODE_HIGHSPEED;
hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING;
if (HAL_COMP_Init(&hcomp1) != HAL_OK)
{
Error_Handler();
}
}
static void MX_TIM1_Init(void)
{
TIM_OC_InitTypeDef TIMPWM_Config;
htim1.Instance = TIM1;
htim1.Init.Period = 50000;
htim1.Init.Prescaler = 0;
htim1.Init.ClockDivision = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.RepetitionCounter = 0;
HAL_TIM_PWM_Init(&htim1);
TIMPWM_Config.OCMode = TIM_OCMODE_PWM1;
TIMPWM_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
TIMPWM_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
TIMPWM_Config.Pulse = 2000;
TIMPWM_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
TIMPWM_Config.OCNPolarity = TIM_OCNPOLARITY_LOW;
TIMPWM_Config.OCFastMode = TIM_OCFAST_DISABLE;
if(HAL_TIM_PWM_ConfigChannel(&htim1, &TIMPWM_Config, TIM_CHANNEL_5) != HAL_OK)
{
Error_Handler();
}
if(HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_5) != HAL_OK)
{
Error_Handler();
}
}
The tech. ref. manual mentions the blanking window, but it does not declare how can I set the width of the window. Can anybody tell me what I am doing wrong? Frequency of the input signal is around 100Hz. I need 100-200us blanking window.
Thanks,
Louis
2022-02-28 03:27 AM
Hi
The built-in "blanking" is useless. In the "COMP_OutputBlanking" example's readme file, in the "Connection needed" chapter STM suggests to connect the comparator input "..to a signal generator, at the frequency of TIM1 period to have comparator input signal frequency matching blanking signal frequency and sync the generator from the TIM CHN2..." It does not happen in the real world. The input frequency will never match the TIM1 period. How did you plan to use it?
Currently the only way (I see) to blank the output of the comparator from the spikes if you have Timer (not the 1ms SYSTICK) and you enable the comparator interrupts for both edges during initialization. When the comparator interrupt is raised:
Note: if you need the blanked comparator output then you can toggle a GPIO pin from comparator interrupt (when it is not ignored)
Why does not the built-in "blanking" work this way?
Thanks,
Louis