2014-04-30 09:17 AM
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
2014-05-01 02:49 AM
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.
2014-05-01 03:14 AM
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 :)2014-05-01 12:09 PM
Cross-Post:
Have you looked for examples in the ST libraries, and for the Discovery boards...?2014-05-01 02:43 PM
yes I looked, and I searched but I found nothing
2014-05-01 03:33 PM
Unfortunately the code is incomplete, it's hard to do much with what you've posted.
I will observe thatGPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_2);
Needs to beGPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_8);
// COMP1_OUT2014-05-03 01:14 AM
that was the problem ''GPIO_PinSource0, GPIO_AF_2''. now it works perfectly
thank you :)