cancel
Showing results for 
Search instead for 
Did you mean: 

TIM1 interrupts only with low level input

marcl
Associate II
Posted on December 10, 2008 at 11:04

TIM1 interrupts only with low level input

1 REPLY 1
marcl
Associate II
Posted on May 17, 2011 at 12:55

Hallo,

I have some problems implementing the TIM1 functions I want.

I have for input at the TIM1 a PWM square wave (period 40 ms) with 10% duty cycle, and I want to have for example 5 update event interrupts but only when the input PWM is LOW. When it's high,the interrupts must stop.

void TIM_Counter(void)

{

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_ICInitTypeDef TIM_ICInitStructure;

/* ------------

TIM1CLK = 28 MHz, Prescaler = 6, TIM1 counter clock = 4 MHz

------------ */

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = 65535;

TIM_TimeBaseStructure.TIM_Prescaler = 6;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

/* TIM1 Input Capture Configuration */

TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

TIM_ICInitStructure.TIM_ICFilter = 0;

TIM_ICInit(TIM1, &TIM_ICInitStructure);

/* TIM1 Input trigger configuration: External Trigger connected to TI1*/

TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1);

TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Gated);

/* TIM IT enable */

TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);

}

This funtions gets near my purpose but the problem is that with gated mode the counter doesn't reset at the next falling edge (so all the interrupts have different synchro with their period's falling edge) , and using reset mode instead of gated makes the counter running also when the PWM is HIGH (but the counter resets every time a falling edge occurs, as I want).

Anybody knows how to solve this?

Greetings.

[ This message was edited by: marcl on 10-12-2008 15:35 ]