2014-09-04 08:28 PM
I'm trying to set up interrupt on falling/raising edge on output PWM line. This line drives LEDs (through TI LED driver chip). The reason why I need this is that the TI chip would report issues on a different pin but this pin is synchronized with PWM line - one comms bit per PWM signal.
I've tried to configure update interrupt but the handler never gets triggered. Any ideas why?Here's my code#define LED_GPIO_PORT GPIOA#define LED_GPIO_RCC RCC_APB2Periph_GPIOA#define LED_GPIO_PWM_PIN GPIO_Pin_11#define PWM_FREQUENCY_Hz 3000#define PWM_MAX_DUTY_CYCLE 40 // 40%#define LED_TIMER TIM1#define LED_TIMER_RCC RCC_APB2Periph_TIM1void LEDInit( void ){ .... GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; TIM_OCInitTypeDef TIM_OCInitStructure; // turn on clocks RCC_APB2PeriphClockCmd( LED_GPIO_RCC | LED_TIMER_RCC, ENABLE ); NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* TIM IT enable */ TIM_ITConfig( LED_TIMER, TIM_IT_Update, ENABLE ); TIM_Cmd( LED_TIMER, ENABLE ); GPIO_InitStructure.GPIO_Pin = LED_GPIO_PWM_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init( LED_GPIO_PORT2, &GPIO_InitStructure ); TIM_TimeBaseStructure.TIM_Period = (SystemCoreClock/2) / PWM_FREQUENCY_Hz - 1; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit( LED_TIMER, &TIM_TimeBaseStructure ); TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_Pulse = period - dutyLength; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC4Init( TIM1, &TIM_OCInitStructure ); TIM_OC4PreloadConfig( LED_TIMER, TIM_OCPreload_Enable ); TIM_CtrlPWMOutputs( LED_TIMER, ENABLE );}void TIM1_UP_IRQHandler(void){ if (TIM_GetITStatus( LED_TIMER, TIM_IT_Update ) != RESET) { // do something here TIM_ClearITPendingBit( LED_TIMER, TIM_IT_Update ); }}2014-09-05 12:33 AM
And does the PWM pin pulse?
JW2014-09-09 03:19 AM
Yes, the LEDs are working fine, I can see the PWM on the scope as well...
2014-09-09 05:22 AM
Are you using C++ (.cpp)?
I perhaps would have ordered things differently, and assigned all the fields in TIM/GPIO structures.2014-09-09 01:15 PM
No, just C (using old CrossStudio). Is the order important? I'll try to fill all the fields.
Thanks2014-09-09 06:23 PM
I'm going to guess this is an STM32F1 device.
How are you determining the interrupt is not occurring? Could you perhaps toggle a GPIO or something? The other thing to look at would be your startup_stm32f1xx_xx.s file and make sure you have the interrupt vector described there. The C, whilst incomplete, looks like it should probably work.