2024-03-12 01:57 PM
Hello,
I'm using a F401 blackpill board for a school project.
Currently I'm trying to generate a pulse with adjustable length to open a MOSFET circuit.
I managed the pulse by using an Output Compare channel and setting the CCR to 1, so the pulse would be the length of the ARR.
Where I run into a problem is when I try using more than one Output Compare channel from one timer to do the same operation. The pulse fires once and then all the channels go to HIGH output.
To trigger the timer channel I use this function:
void pulse(uint16_t pulsetime, TIM_HandleTypeDef *htim, uint8_t channel)
{
htim->Instance->ARR = pulsetime;
HAL_TIM_OC_Start_IT(htim, channel);
}
Then in the DelayElapsedCallback I stop the timer channel with HAL_TIM_OC_Stop_IT().
As long as I only ever start one of the timer channels it works fine, however as soon as another channel is started in this manner, all channels stop working.
Can anyone help me figure out why using multiple channels won't work?
Solved! Go to Solution.
2024-03-12 04:26 PM
Timers have a single counter. The channels are not independent.
If all you need is 1 channel active at a time, this scheme can work, or if you need multiple channels with the same period but different duty cycles, this can work. But if you need them independent, you need to use multiple timers.
2024-03-12 04:26 PM
Timers have a single counter. The channels are not independent.
If all you need is 1 channel active at a time, this scheme can work, or if you need multiple channels with the same period but different duty cycles, this can work. But if you need them independent, you need to use multiple timers.
2024-03-13 06:22 AM
Right, so activating 1 channel at a time would work but switching which of the channels is active won't work?
I'll move on to using multiple timers for this project, but I'm just curious as to where the fault lies in my original plan.
Could the problem lie in the HAL-library perhaps?
Thank you for the response btw.
2024-03-13 07:00 AM
You should be able to switch which channels are active. It's hard to know exactly what is going wrong without the full code, but it should be working in theory, if only one channel is ever active at a time. Unlikely to be a HAL bug, perhaps a misunderstanding of what it should be doing in a particular case. HAL source code is there in your project, you can step through to find out why something isn't occurring, or interpret by looking at the register values.