cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030R8 TIM17 PWM COMPLEMENT

metin
Associate II
Posted on April 04, 2014 at 13:47

Dear friends,

We can not produce N Polarity for TIM17 Complement PWM in STM32F030R8.

But P Polarity channel (other one) is OK.

I need your helps.

 // TIM17 clock enable

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE);

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE);

  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_9 ;  

  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(GPIOB, &GPIO_InitStructure);

 GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_2);

 GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_2);

   PrescalerValue_ = (uint16_t) (SystemCoreClock / 4000000) - 1;   // Deger buyuk, prescaler gerekli.

   TIM_TimeBaseStructur.TIM_Period = 40000;        // 100Hz

  TIM_TimeBaseStructur.TIM_Prescaler = PrescalerValue_;

  TIM_TimeBaseStructur.TIM_ClockDivision = 0;

  TIM_TimeBaseStructur.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM17, &TIM_TimeBaseStructur);

  TIM_OCInitStructur.TIM_OCMode = TIM_OCMode_PWM2;

  TIM_OCInitStructur.TIM_OutputState = TIM_OutputState_Enable;

 TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;

  TIM_OCInitStructur.TIM_Pulse = 20000;          

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;

  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;

  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;

  TIM_OC1Init(TIM17, &TIM_OCInitStructur);

 

 // Automatic Output enable, Break, dead time and lock configuration

  TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;

  TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;

  TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;

  TIM_BDTRInitStructure.TIM_DeadTime = 20;

  TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;

  TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;

  TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;

  TIM_BDTRConfig(TIM17, &TIM_BDTRInitStructure);

 

 TIM_CCPreloadControl(TIM17, ENABLE);

  TIM_ARRPreloadConfig(TIM17, ENABLE);

 TIM_Cmd(TIM17, ENABLE);       //TIM17 enable counter

 TIM_CtrlPWMOutputs(TIM17, ENABLE); //Enable the TIM Main Output / TIMx->BDTR |= TIM_BDTR_MOE; 

0 REPLIES 0