AnsweredAssumed Answered

TIM INTERRUPT IRQ STM32F3DISCOVERY

Question asked by spiezia.andrea on Jan 4, 2016
Latest reply on Jan 5, 2016 by spiezia.andrea

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.}





 

001.#include "stm32f30x.h"
002.#include "main.h"
003.  
004.static volatile unsigned int CapCom_PULSE;
005.__IO uint32_t IncDuty = 0; //boolean, if true increment duty cycle. It has set in ISRQ with SetTrue() func. 
006.
007.  
008.  
009./************************************************/
010.   
011.void TIM_Interr_Config(void)
012.{
013.    NVIC_InitTypeDef NVIC_InitStructure;
014.  
015.  /* Enable the TIM3 gloabal Interrupt */
016.  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
017.  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
018.  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
019.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
020.  NVIC_Init(&NVIC_InitStructure);
021.  
022.
023.   
024.void RCC_Configuration(void)
025.{
026.  /* Enable GPIO clock */
027.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //
028.   
029.  /* Enable TIM3 clock */
030.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
031.}
 
034.void GPIO_Configuration(void)
035.{
036.  GPIO_InitTypeDef GPIO_InitStructure;
037. GPIO_DeInit(GPIOA);    
      GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_2); // TIM3_CH1
043.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_2); //   TIM3_CH2
044.      
045.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
046.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
047.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
048.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
049.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
050.  GPIO_Init(GPIOA, &GPIO_InitStructure);
051.}
052.   
053.  
054.void TIM_Configuration(void)
055.{
056.  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
057.  TIM_OCInitTypeDef TIM_OCInitStructure;
058.       
059.  TIM_TimeBaseStructure.TIM_Prescaler = 72 - 1; // 72 to 1 MHz
060.  TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // 1 MHz to 1    KHz
061.  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
062.  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
063.  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
064.   
065.  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
066.  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
067.  TIM_OCInitStructure.TIM_Pulse = 900; // 10% duty cycle
068.  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
069.   
070.  TIM_OC1Init(TIM3, &TIM_OCInitStructure);
071.  TIM_Cmd(TIM3, ENABLE);
072.}
073.   
074./*****************************************************/
075.   
076.int main(void)
077.{
078.    IncDuty = 0; //boolean. If true increment duty cycle. It has set to TRUE in TIM3_IRQHandler, read in while loop and reset 
079.    CapCom_PULSE = 500;
080.      
081.      
082.  RCC_Configuration();
083.  
084.  TIM_Interr_Config();
085.      
086.  GPIO_Configuration();
087.   
088.  TIM_Configuration();
089.   
090.   
091.    while(1){ 
092.  if (IncDuty){
093.        CapCom_PULSE--;
094.        TIM_SetCompare1(TIM3, CapCom_PULSE);
095.        IncDuty = 0;
096.        
097.  }
098.          
099.}
100.  
101.void SetTrue(){ 
102.    IncDuty = 1; 
103.}
 

Outcomes