2015-01-27 04:27 AM
Hi all,
is it possible to run the Timer 1 in Capture Compare mode to detect the duty cycle of a PWM and the Timer 2 in Capture Compare mode to generate a PWM? Sadly in my project Timer 2 is not giving any output while i measure the duty cycle with Timer 1. CODE:/* Configure TIMER1 peripheral -----------------------------------------------*/
static void TIM1_Config(void) { /* Init TIMER 1 */ CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE); // configure TIM1 channel 1 to capture a PWM signal TIM1_PWMIConfig(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV1, ENABLE); // Select the TIM1 Input Trigger: TI1FP1 TIM1_SelectInputTrigger(TIM1_TS_TI1FP1); TIM1_SelectSlaveMode(TIM1_SLAVEMODE_RESET); // Enable CC1 interrupt request TIM1_ITConfig(TIM1_IT_CC2, 0x01); // Enable TIM1 TIM1_Cmd(ENABLE);enableInterrupts();
} static void TIM2_Config(uint16_t value) { //CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE); TIM2_TimeBaseInit(TIM2_PRESCALER_1, 16000); // Time base configuration TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,value, TIM2_OCPOLARITY_HIGH); TIM2_OC1PreloadConfig(ENABLE); // PWM1 Mode configuration: Channel1 TIM2_ARRPreloadConfig(ENABLE); TIM2_Cmd(ENABLE); // TIM2 enable counter }