cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 Comparator

rafik
Associate II
Posted on April 30, 2014 at 18:17

hello everyone

I am a beginner in STM32F3 and I found a problem with the comparator. I have no compilation error but its not working. If anyone can help me I would be grateful here is the code:

COMP_InitTypeDef compp;
GPIO_InitTypeDef GPIO_Inite;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_StructInit(&GPIO_Inite);
GPIO_Inite.GPIO_Pin = GPIO_Pin_1;
GPIO_Inite.GPIO_Mode = GPIO_Mode_AN;
GPIO_Inite.GPIO_Speed = GPIO_Speed_50MHz; /* GPIO speed - has nothing to do with the timer timing */
GPIO_Inite.GPIO_OType = GPIO_OType_PP; /* Push-pull */
GPIO_Inite.GPIO_PuPd = GPIO_PuPd_NOPULL; /* Setup pull-down resistors */
GPIO_Init(GPIOA, &GPIO_Inite);
GPIO_StructInit(&GPIO_Inite);
GPIO_Inite.GPIO_Pin = GPIO_Pin_0;
GPIO_Inite.GPIO_Mode = GPIO_Mode_AF;
GPIO_Inite.GPIO_Speed = GPIO_Speed_50MHz; /* GPIO speed - has nothing to do with the timer timing */
GPIO_Inite.GPIO_OType = GPIO_OType_PP; /* Push-pull */
GPIO_Inite.GPIO_PuPd = GPIO_PuPd_NOPULL;; /* Setup pull-down resistors */
GPIO_Init(GPIOA, &GPIO_Inite);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_2);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
COMP_DeInit(COMP_Selection_COMP1);
compp.COMP_InvertingInput=COMP_InvertingInput_DAC1 ;
compp.COMP_NonInvertingInput=COMP_NonInvertingInput_IO1 ;
compp.COMP_Output=COMP_Output_None ;
compp.COMP_BlankingSrce=COMP_BlankingSrce_None ;
compp.COMP_OutputPol=COMP_OutputPol_Inverted;
compp.COMP_Hysteresis=COMP_Hysteresis_High;
compp.COMP_Mode=COMP_Mode_HighSpeed;
COMP_Init(COMP_Selection_COMP1,&compp);
COMP_Cmd(COMP_Selection_COMP1, ENABLE);

thank you in advance :) #cross-post
6 REPLIES 6
chen
Associate II
Posted on May 01, 2014 at 11:49

Hi

I do not know if this is the root cause of you problem : ''

compp.COMP_InvertingInput=COMP_InvertingInput_DAC1 ;

'' The comparator is suppose to work on ADCs not DACs. The code probably resolves down to a number anyway.
rafik
Associate II
Posted on May 01, 2014 at 12:14

hi 

I found it in the library stm32f30x_comp.h, and even in the manual you can see that the comparator has the ability to work with the DAC. I just tried and its not working well. 

thank you :)
Posted on May 01, 2014 at 21:09

Cross-Post: 

http://www.keil.com/forum/57543

Have you looked for examples in the ST libraries, and for the Discovery boards...?
rafik
Associate II
Posted on May 01, 2014 at 23:43

yes I looked, and I searched but I found nothing

Posted on May 02, 2014 at 00:33

Unfortunately the code is incomplete, it's hard to do much with what you've posted.

I will observe that

GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_2);

Needs to be

GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_8);

// COMP1_OUT

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rafik
Associate II
Posted on May 03, 2014 at 10:14

that was the problem ''GPIO_PinSource0, GPIO_AF_2''. now it works perfectly 

thank you :)