2108 views|0 replies

565

Posts

0

Resources
The OP
 

[N32L43x Review] 9. Complementary PWM, Dead Zone Test [Copy link]

 

1. Introduction

N32L43X supports two advanced timers, TIM1 and TIM8. The advanced timer supports input capture, output comparison, PWM, dead zone, brake and other functions. This article mainly tests complementary PWM and dead zone.

2. PWM channel and complementary channel of TIM1

This article uses PA8 and PA7, where PA8 is the CH1 channel of TIM1 and PA7 is the complementary channel.

3. Dead time calculation

It can be seen that the calculation of dead time is based on the above formula. There are four cases to calculate the dead time. In this article, the system clock frequency is 108M, so it can be calculated that T DTS=1/108000000=9.26ns;

Case 1: DTGN[7:5]=0xx, then the value range of DTGN[6:0] is 0-127, then DT=(0~127)*9.26ns=(0ns~1176ns);

Case 2: DTGN[7:5]=10x, then the value range of DTGN[5:0] is 0-63, then DT=(64+DTGN[5:0])*2*9.26ns=(64+(0~63))*2*9.26ns=(1185ns~2352ns);

Case 3: DTGN[7:5]=110, then the value range of DTGN[4:0] is 0-31, then DT=(32+DTGN[4:0])*8*2.96ns=(32+(0-31))*8*9.26ns=(2370~4667);

Case 4: DTGN[7:5]=111, then the value range of DTGN[4:0] is 0-31, then DT=(32+DTGN[4:0])*16*2.96ns=(32+(0-31))*16*9.26ns=(4741~9334);

From the above calculation, we can see that when T DTS = 9.26ns, the maximum dead time is 9334ns = 9.3us.

This article sets the dead time to 9.3us for testing, and can infer that the value of DTGN[7:0] is 255, which is 0xff.

4. Code Implementation

void PwmInit(void)
{
	//CH1:PA8   CH1N:PA7
    /* GPIOA and GPIOB clock enable */
    RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA  | RCC_APB2_PERIPH_AFIO, ENABLE);
	
	/* TIM1 clock enable */
    RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1, ENABLE);
	
	GPIO_InitType GPIO_InitStructure;

    GPIO_InitStruct(&GPIO_InitStructure);
    /* GPIOA Configuration:TIM1 Channel1 as alternate function push-pull */
    GPIO_InitStructure.Pin        = GPIO_PIN_7 ;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Current = GPIO_DC_4mA;
    GPIO_InitStructure.GPIO_Alternate = GPIO_AF5_TIM1;
    GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
	
	GPIO_InitStructure.Pin        =   GPIO_PIN_8;
    GPIO_InitStructure.GPIO_Alternate = GPIO_AF2_TIM1;
    GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
	
    //108M
	TIM_TimeBaseInitType TIM1_TimeBaseStructure;

	TIM1_TimeBaseStructure.Period    = 99; //999
    TIM1_TimeBaseStructure.Prescaler = 107;
    TIM1_TimeBaseStructure.ClkDiv    = TIM_CLK_DIV1;
    TIM1_TimeBaseStructure.CntMode   = TIM_CNT_MODE_UP;

    TIM_InitTimeBase(TIM1, &TIM1_TimeBaseStructure);
	TIM_Enable(TIM1, ENABLE);

	OCInitType TIM_OCInitStructure;

	/* PWM1 Mode configuration: Channel1 */
    TIM_OCInitStructure.OcMode      = TIM_OCMODE_PWM2;
	TIM_OCInitStructure.Pulse       = 49;//499

    TIM_OCInitStructure.OutputState = TIM_OUTPUT_STATE_ENABLE;
	TIM_OCInitStructure.OcIdleState = TIM_OC_IDLE_STATE_RESET;
    TIM_OCInitStructure.OcPolarity  = TIM_OC_POLARITY_HIGH;
	
	TIM_OCInitStructure.OutputNState= TIM_OUTPUT_NSTATE_ENABLE;
	TIM_OCInitStructure.OcNIdleState= TIM_OCN_IDLE_STATE_SET;
	TIM_OCInitStructure.OcNPolarity = TIM_OCN_POLARITY_HIGH;

    TIM_InitOc1(TIM1, &TIM_OCInitStructure);

    TIM_ConfigOc1Preload(TIM1, TIM_OC_PRE_LOAD_ENABLE);
	TIM_EnableCtrlPwmOutputs(TIM1, ENABLE);


	TIM_BDTRInitType TIM_BDTRInitStruct;
	
	TIM_BDTRInitStruct.OssrState=TIM_OSSR_STATE_ENABLE;
	TIM_BDTRInitStruct.OssiState=TIM_OSSI_STATE_ENABLE;
	TIM_BDTRInitStruct.LockLevel=TIM_LOCK_LEVEL_OFF;
	TIM_BDTRInitStruct.DeadTime =0xff; //9us
	TIM_BDTRInitStruct.Break=TIM_BREAK_IN_DISABLE;
	TIM_BDTRInitStruct.BreakPolarity=TIM_BREAK_POLARITY_HIGH;
	TIM_BDTRInitStruct.AutomaticOutput=TIM_AUTO_OUTPUT_ENABLE;
	TIM_ConfigBkdt(TIM1, &TIM_BDTRInitStruct);
	
}

5. Observe the phenomenon with an oscilloscope


It can be seen that the PWM complementary output and dead time are the same as those set in the program.

This post is from Domestic Chip Exchange
Personal signaturestm32/LoRa物联网:304350312
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list