cancel
Showing results for 
Search instead for 
Did you mean: 

I want to make Comparator's output inversely.

DU2
Associate II

Hello, I am using STM32 L031K6 & its low power Comparator, which is running in stop mode.

What I want to Comparator is:

when pin PA3's input voltage is bigger than reference Voltage, then Comparator give interrupt to the system. so after wake up from its Stop mode, System make buzzer sound. after that, entering sleep again.

Luckily I can make Comparator run in stop mode, so Comparator is always comparing PA3 and Vref/4 (referenceVoltage/4) .

In my intension, I wish my Comparator give interrupt when PA3 voltage >Vref, but my Comparator is always making interrupt when PA3<Vref

how can I make my Comparator work as My intension?

thank you for read.

*********************************************************************

here is my config code:

 hcomp2.Instance = COMP2;

  hcomp2.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1;

   

  hcomp2.Init.InvertingInput = COMP_INPUT_MINUS_1_4VREFINT;

  hcomp2.Init.LPTIMConnection = COMP_LPTIMCONNECTION_IN1_ENABLED; //PA7

  hcomp2.Init.OutputPol = COMP_OUTPUTPOL_INVERTED;

 //I tried OUTPUTPOL_NONINVERTED , but result was same

  hcomp2.Init.Mode = COMP_POWERMODE_ULTRALOWPOWER;  

  hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE;

  hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING;

 if (HAL_COMP_Init(&hcomp2) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN COMP2_Init 2 */

 /* USER CODE END COMP2_Init 2 */

  

  if(HAL_COMP_Start_IT(&hcomp2) != HAL_OK){

   

  while(1){

  }

1 REPLY 1

> //I tried OUTPUTPOL_NONINVERTED , but result was same

It should make a difference.

Read out and check/compare/post content of COMPx_CSR register for both settings.

Output the COMP's output to a pin and observe its behaviour.

Also, if you use EXTI for wakeup, you can change the polarity there.

Note, that when input voltage is close to the threshold, there may be spurious oscillations up and down, resulting in both edges to be seen by the hardware. If this is what causes you problems, you should introduce some sort of hysteresis (the 'L0 does not have internal circuitry for that, so you should then do it externally).

JW