AnsweredAssumed Answered

Dead time generation STM32F030K6

Question asked by boeni.franz on Feb 15, 2014
Latest reply on Feb 17, 2014 by boeni.franz
This software is not working with STM32F030K6 , but this sofware works with STM32F030R8. Prototype 1 used the discovery board. No we made a PCB with
STM32F030K6. And the code is not working anymore. Makes reset. If I don't call this routine, then the softtware is working also on STM32F030K6. But then we don't have the brushless sensorless functionality.
Is any work arround possible. I have a 3 phase brushless motor. For the operation I need a very low cost non overlapping PWM unit.

The software use only TIM1. So I can not understand why the software is not working with the smaller member STM32F030K6. (TIM15/16/17 is not used in this sample)
)
**


  ******************************************************************************
  * @file    Spwm.c
  * @author  MCD Application Team
  * @version V1.0.0
  * @date    16.1.2014
  * @brief   Tim1 3 Phase PWM for block commutation sensorless
  ******************************************************************************
  *
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "pwm.h"
#include "stm32f0xx.h"
#include "stm32f0xx_tim.h"
//#include "stm32f0xx_gpio.h"
//#include "stm32f0xx_rcc.h"


/* Private variables ---------------------------------------------------------*/

//uint16_t Channel1Pulse = 0, Channel2Pulse = 0, Channel3Pulse = 0;


TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
uint16_t TimerPeriod = 0;
//uint16_t Channel1Pulse = 0, Channel2Pulse = 0, Channel3Pulse = 0;
/* Private function prototypes -----------------------------------------------*/



/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void Complementary_signals(void)
{
   
#define PWM_FREQ 100000
      TimerPeriod = (SystemCoreClock / PWM_FREQ);  //16kHz TimerPeriod = 3000

  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  /* Time Base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  /* Channel 1, 2 and 3 Configuration in PWM mode */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0;
  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(TIM1, &TIM_OCInitStructure);

  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OC2Init(TIM1, &TIM_OCInitStructure);

  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OC3Init(TIM1, &TIM_OCInitStructure);

  /* 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_Enable;
  TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
  TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;

  TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);

  /* TIM2 TRGO selection */
   TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); // ADC_ExternalTrigConv_T2_TRGO
  /* TIM1 counter enable */
  TIM_Cmd(TIM1, ENABLE);

  /* Main Output Enable */
  TIM_CtrlPWMOutputs(TIM1, ENABLE);

}

Franz

Outcomes