cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F051 Internal comparator configuration

Aiswarya1
Associate II

Hi,

I am trying to configure the internal cooperators in the STM32F051 micro-controller, but in the .ioc file I am able to configure only one Comparator. I require three comparators for my application. Is it possible to configure multiple comparators on the STM32F051 development board? If so, could someone please explain how to configure multiple comparators in the STM32F051 micro-controller?

7 REPLIES 7
waclawek.jan
Super User

> I require three comparators for my application.

waclawekjan_0-1765883691611.png

> I am able to configure only one Comparator

Maybe there's some conflict between second comparator and some other peripheral, which prevents CubeMX from enabling it. I don't use Cube/CubeMX.

If you don't need the 3 comparators at the same time, you may be able to switch between inputs to use one comparator for two or three inputs. Details need to be looked up in the RM. This is probably not something you can click in CubeMX.

JW

TDK
Super User

> STM32F051

What is the full chip number you are using? Letters after this...

 

Only one ST board that uses this chip and comparators 1 and 2 are easily configurable in CubeMX with it.

TDK_0-1765891540670.png

 

Attach your IOC file. Perhaps the pins are already being used by other peripherals.

If you feel a post has answered your question, please click "Accept as Solution".

PA1, PA2, and PA3 are the positive input pins of Comparator 1, and PA0, PA4, and PA5 are the negative input pins of Comparator 1. Can I configure these pins simultaneously and use Comparator 1 as a multiplexer?

can I configure comparator 1 as MUX?

 

I've had a look at the 'F0 and it does not have that flexibility.

waclawekjan_0-1765980544402.png

Only PA1 can be used as positive input to COMP1. You can multiplex between PA0, PA4 (you must not enable DAC) and PA5 as negative inputs to COMP1. (And yes, those pins can be all set to Analog at startup, and then selected by controlling the MUX in COMP_CSR.COMP1INSEL field).

Similarly, PA3 is the only positive input to COMP2.

So you don't have three pairs of pins which could be used even with multiplexing.

This is the lowest range of STM32; there are families with more comparators (e.g. 'F3).

JW

Thank you for your response.

I am trying to configure PA1 as the positive input and PA0, PA4, and PA5 as negative inputs. However, in STM32CubeMX, I am only able to configure one pin as the negative input. Why is this happening?

waclawek.jan
Super User

CubeMX - as any configurator and the associated libraries such as Cube/HAL - inevitably implements only "typical" settings - writing tools  and libraries which would cover all the possibilities these microcontrollers offer would take too much time and cost too much money. I don't use CubeMX, I program directly through registers, in that way I am free to set them up in any way they allow.

Generally, you should set all four pins as Analog in GPIO_MODER - I believe CubeMX may allow that for the remaining two pins - and then you select whichever negative input you need, in runtime.

JW