Question
TIM INTERRUPT IRQ STM32F3DISCOVERY
Posted on January 04, 2016 at 16:17
Hi all,
I'd like to have e PWM signal, starting with a duty cycle of 10% and incrementing up to 100%. I'm using next code, I see the waveform with 10%, but it never increase, it seems that it never enter in the TIM IRQ, and I don't understand why, can you help me? In file stm32f30x_it.c the IRQ is:
1.
void
TIM3_IRQHandler (
void
)
2.
{
3.
SetTrue();
4.
5.
}
#include ''stm32f30x.h''
#include ''main.h''
static
volatile
unsigned
int
CapCom_PULSE;
__IO uint32_t IncDuty = 0;
//boolean, if true increment duty cycle. It has set in ISRQ withSetTrue() func.
/************************************************/
void
TIM_Interr_Config(
void
)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM3 gloabal Interrupt */
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);
}
void
RCC_Configuration(
void
)
{
/* Enable GPIO clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
//
/* Enable TIM3 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
}
void
GPIO_Configuration(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_DeInit(GPIOA);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_2);
// TIM3_CH1
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_2);
// TIM3_CH2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void
TIM_Configuration(
void
)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_Prescaler = 72 - 1;
// 72 to 1 MHz
TIM_TimeBaseStructure.TIM_Period = 1000 - 1;
// 1 MHz to 1 KHz
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 900;
// 10% duty cycle
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_Cmd(TIM3, ENABLE);
}
/*****************************************************/
int
main(
void
)
{
IncDuty = 0;
//boolean. If true increment duty cycle. It has set to TRUE in TIM3_IRQHandler, read in while loop and reset
CapCom_PULSE = 500;
RCC_Configuration();
TIM_Interr_Config();
GPIO_Configuration();
TIM_Configuration();
while
(1){
if
(IncDuty){
CapCom_PULSE--;
TIM_SetCompare1(TIM3, CapCom_PULSE);
IncDuty = 0;
}
}
}
void
SetTrue(){
IncDuty = 1;
}
#st