COMP_InitType COMP_Initial;
/*Set dac2,dac1. because dac1/PA4 is share pin line,so only PB0 puls 0/1, can find out puls*/
COMP_SetRefScl(16, true, 32, true);
/*Initial comp*/
COMP_StructInit(&COMP_Initial);
COMP_Initial.InpSel = COMP1_CTRL_INPSEL_PB10;
COMP_Initial.InmSel = COMP1_CTRL_INMSEL_PA5;
COMP_Initial.SampWindow = 18; //(0~31)
COMP_Initial.Thresh = 12; //Thresh should be greater than half of SampWindow and should be less than SampWindow at the same time.
COMP_Init(COMP1, &COMP_Initial);
COMP_Enable(COMP1, ENABLE);
EXTI_InitType EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line = EXTI_LINE21;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_InitPeripheral(&EXTI_InitStructure);
NVIC_InitType NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = COMP_1_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
EXTI_ClrITPendBit(EXTI_LINE21);
NVIC_ClearPendingIRQ(COMP_1_2_IRQn);
COMP_SetIntEn(ENABLE); |