2023-10-03 11:51 PM
In complementary PWM out put my dead time increases or decreases when i am varying the Auto reload register value. is there a solution like 45% of duty cycle with one out put inverted and second output non inverted.
This is my HAL_INITS along with Timer Hal Start and Method to change the frequency and duty.
static void MX_TIM1_Init(void)
{
/* USER CODE BEGIN TIM1_Init 0 */
/* USER CODE END TIM1_Init 0 */
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
/* USER CODE BEGIN TIM1_Init 1 */
/* USER CODE END TIM1_Init 1 */
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_DOWN;
htim1.Init.Period = 400;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 110;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM1_Init 2 */
/* USER CODE END TIM1_Init 2 */
HAL_TIM_MspPostInit(&htim1);
}
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
void pwmData(uint32_t dat){
__HAL_TIM_SET_AUTORELOAD(&htim1,dat);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1,dat/2);
}
the change in frequency is ADC dependent.
2023-10-04 01:09 AM - edited 2023-10-04 01:10 AM
> In complementary PWM out put my dead time increases or decreases when i am varying the Auto reload register value.
How do you observe that? Show screenshot/photo exhibiting this change.
JW
PS.
htim1.Init.CounterMode = TIM_COUNTERMODE_DOWN;
Why?
2023-10-04 01:17 AM
Also, changing ARR and CCRx in runtime while having
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
and also possibly CCRx preload disable, may lead to surprising results.
JW
2023-11-02 12:43 AM
sorry for being late to this reply,
htim1.Init.CounterMode = TIM_COUNTERMODE_DOWN;
any other configuration is not working thats why i used this.
2023-11-02 12:46 AM
it will be such an appreciable if you could give me an example code to test and compare with that, so i can better understand the facts. I am totally new to stm32 and 32bit MCU as well.
2023-11-02 01:27 AM
I don't use Cube, but you should be able to find examples under the Projects directory of your Cube library installation. CubeMX should be able to generate you examples too.
JW
2023-11-03 01:48 AM
hello Mr waclawek.jan
first of all kindly see my attached file with this comment i hope it will help you to get the exact problem i wanted to explain you. I am Using a 22K pot for varraying the arr register value and you will be able to see here my duty changes too with change in frequency.
I don't use Cube, but you should be able to find examples under the Projects directory of your Cube library installation. CubeMX should be able to generate you examples too. and i didn't get what exactly you want me to try. If you don't use MXCUBE the you can give me you own firmware which will demonstrate me how i can meet my desire.
Thank you.