Hi all
I’m trying to generate a timer based interrupt from Timer 3, with not much luck.
I release there is a library written for this, however I’m trying to do it without the abstraction as I need to run both the interrupt and PWM off the same timer (timer 3).
I have got PWM to work successfully off the timer so I thought it wouldn’t be a lot more work to get the interrupt up and running…
The following code I’ve stripped the PWM part from to focus just on the interrupt.
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
uint16_t period;
uint16_t pulse;
/* Compute the period value to generate a clock freq of 1KHz */
period = (uint16_t)(SystemCoreClock / 2000)-1; //SystemCoreClock = 120MHz
/* Compute the CCR1 value to generate a PWM signal with 50% duty cycle */
pulse = (uint16_t) ((period-1)/(100.0/(100-dutyCycle)));
/* ISR configuration */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
/* Timer Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = period;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
/* TIM3 Counter Enable */
TIM_Cmd(TIM3, ENABLE);
I’m using the following as my interrupt handler
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3,TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
//Interrupt code here
}
}
Anybody have any ideas?