2019-11-12 04:12 AM
Hi,
I'm using STM32F767, Im trying to generate N-pulse waveform Generation but i couldn't achieve it.
My TIMER configurations are
static void MX_TIM2_Init(void)
{
/* USER CODE BEGIN TIM2_Init 0 */
/* USER CODE END TIM2_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2;
htim2.Init.Prescaler = 54;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 1000;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
htim2.Init.RepetitionCounter = 5-1;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OC_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OnePulse_Init(&htim2, TIM_OPMODE_SINGLE) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_RETRIGERRABLE_OPM1;
sConfigOC.Pulse = 500;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
__HAL_TIM_ENABLE_OCxPRELOAD(&htim2, TIM_CHANNEL_1);
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
HAL_TIM_MspPostInit(&htim2);
}
My APB1 clock is 54MHz. Please help me solve this
Thanks,
Vimal
2019-11-12 04:25 AM
Have you read AN4776 ?
Is the respective pin set properly for AF for the given TIM in GPIO?
Can you output "normal" PWM?
I don't Cube.
JW
2019-11-12 08:05 PM
I have read AN4776 document, I'm trying all configurations mentioned in that application.
Yes, I can generate the normal PWM signal.
i do not want trigger my one pulse mode using another timer. i want to trigger my one pulse every 5 seconds. What configurations do i need to make??
Thanks,
Vimal
2019-11-12 10:41 PM
> I want to trigger my one pulse every 5 seconds
If I understand it correctly, you don't want an external event to trigger a pulse, but you want the timer to produce one pulse once in 5 seconds, automatically?
Then set it up for normal to have a period 5 seconds and a normal PWM with relatively short pulse.
If this is not what you intended, describe exactly what do you want to achieve, perhaps attaching a drawing/sketch of the expected waveform.
JW
2019-11-12 11:43 PM
Some of the 32 bit TIM should permit a period of 5 seconds whilst still having a brief pulse width.
Also be aware that period and prescaler are set as N-1 values, ie 999 would divide by 1000
2019-11-18 12:53 AM
Hi,
Sorry for the late reply.
I understood the problem, I wanted to generate 50 Pulses using one Pulse mode. As advanced timer pins are occupied for other purposes, i have to use other general purpose timers to generate 50 Pulses (frequency 1Khz and 50% Duty cycle). How do i generate repetitive pulse using one pulse mode??
Thanks
Vimal