2021-05-04 10:18 AM
I am having this problem with a variety of signals but let's take for example a 10 kHz signal. I am using the repetition counter to count 9500 times (950 ms) and then be off for 50 ms before turning back on. During the repetition counter part my signal works great but then my signal goes to 3.3V for the 50 ms I want it to be off. Is there a setting somewhere to ensure my signal is at 0 during this off time? For timing reasons, I do not want to stop and start my signal.
2021-05-04 01:00 PM
There are several ways to achieve this, including in PWM mode setting CCRx to 0 or maximum depending on the particular PWM mode and output polarity; using some of the Forced output compare mode; or simply switching the given pin to GPIO Output for the required time.
JW
2021-05-04 01:35 PM
How do you set CCR for a given timer? I know that ARR is Counter Period, PSC is Prescaler, and RCR is Repetition Counter but I am not sure how to control CCR.
Thanks,
Sam
2021-05-04 01:54 PM
If you just want to invert the polarity of what you're currently getting, just change the channel polarity.
To modify CCR for timer 1 channel 2:
TIM1->CCR2 = 0;
2021-05-04 02:11 PM
So can I do something like:
if (TIM1->RCR1=9499)
{
TIM1->CCR2 = 0;
}
So it sets the signal to 0 when it hits the limit of the repetition counter?
Thanks
2021-05-04 03:10 PM
Where in the code would I input this? I tried to put it in the Timer configuration and it shut the whole signal off but then when I put it after the start code below, nothing happened
if (HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
nothi
2021-05-05 12:02 AM
Methods I suggested are intended to be used runtime, when the pulsetrain stops, e.g. employing interrupts.
If you want to stay with Cube, do what TDK suggested above and invert the output polarity.
JW
2021-05-05 07:54 AM
If you want to stick with HAL methods, I would start both timers, then set the master counter's CNT register to the appropriate value right after they are started.
2021-05-05 09:44 AM
if (HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_Base_Start_IT(&htim15) != HAL_OK)
{
Error_Handler();
}
while (TIM15->CNT == 9500)
{
TIM1->CCR1 = 0;
TIM1->CCR2 = 0;
}
Would this kind of thing make sense? And then would I need to set CCRx to not be 0 at 10,000?
2021-05-06 02:22 PM
I've tried a couple variations of the above code and none have gotten the signals to flip. Is there anything I may be missing?