Over the past few days, we have been using STM32 to write the sensorless BLDC driver framework. Therefore, we must use the six-way complementary PWM produced by The CCR1/CCR2/CCR3 of TIM1 and use the CCR4 to generate an interrupt, used in the PWM-ON of the generation of interrupt for zero crossing detection, and phase current detection.
Over the past few days, I have been testing functions such as PWM, CCR4 interruption, ADC1 sampling trigger, and DMA. Now I know about them. First, record them and take a look at some of my settings, TIM1 settings:
TIM_TimeBaseStructure.TIM_Period = TIM_TimeBaseStructure.TIM_Prescaler = TIM_TimeBaseStructure.TIM_CounterMode = TIM_TimeBaseStructure.TIM_ClockDivision = TIM_TimeBaseStructure.TIM_RepetitionCounter = TIM_TimeBaseInit(TIM1, & TIM_BDTRInitStructure.TIM_OSSRState = TIM_BDTRInitStructure.TIM_OSSIState = TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_BDTRInitStructure.TIM_DeadTime = TIM_BDTRInitStructure.TIM_Break = TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_BDTRConfig(TIM1, & TIM_OCInitStructure.TIM_OCMode = TIM_OCInitStructure.TIM_OutputState = TIM_OCInitStructure.TIM_OutputNState = TIM_OCInitStructure.TIM_Pulse = TIM_OCInitStructure.TIM_OCPolarity = TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCInitStructure.TIM_OCIdleState = TIM_OCInitStructure.TIM_OCNIdleState = TIM_OC1Init(TIM1, & TIM_OCInitStructure.TIM_Pulse = TIM_OC2Init(TIM1, & TIM_OCInitStructure.TIM_Pulse = TIM_OC3Init(TIM1, & TIM_OCInitStructure.TIM_OutputState = TIM_OCInitStructure.TIM_Pulse = TIM_OCInitStructure.TIM_OCIdleState = TIM_OC4Init(TIM1, & TIM_CtrlPWMOutputs(TIM1, ENABLE);
Set ADC1. The rule Channel + DMA + software is used for triggering, and the injection channel + CCR4 event is used for triggering:
ADC_InitStructure.ADC_Mode = ADC_InitStructure.ADC_ScanConvMode = ADC_InitStructure.ADC_ContinuousConvMode = ADC_InitStructure.ADC_ExternalTrigConv = ADC_InitStructure.ADC_DataAlign = ADC_InitStructure.ADC_NbrOfChannel = ADC_Init(ADC1, & ADC_RegularChannelConfig(ADC1,ADC_Channel_0,,ADC_SampleTime_239Cycles5); ADC_RegularChannelConfig(ADC1,ADC_Channel_1,,ADC_SampleTime_239Cycles5); ADC_RegularChannelConfig(ADC1,ADC_Channel_2,,ADC_SampleTime_239Cycles5); ADC_RegularChannelConfig(ADC1,ADC_Channel_10 , ADC_RegularChannelConfig(ADC1,ADC_Channel_Vrefint, ADC_InjectedSequencerLengthConfig(ADC1, ADC_InjectedChannelConfig(ADC1,ADC_Channel_TempSensor,,ADC_SampleTime_7Cycles5); ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4); ADC_ITConfig(ADC1,ADC_IT_JEOC,ENABLE); ADC_Cmd(ADC1, ENABLE);
In addition, I added an interrupt of the end of the injection channel sampling to quickly handle phase current problems, such as throttling and overcurrent processing.
From the test, if the pulse of CCR4 is set to 0, the ADC1 injection sampling will not be triggered, and the ADC will not be interrupted. Only pluse is set to a valid value, the sampling of the adc injection channel will be triggered.