Stat and stop toggle of output compare mode precisely
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-07-02 11:58 PM
Hi all,
for a projet I need to create a signal at 500khz, and every 60 µs I want to stop the toggle (or not)
I generate the signal with the output compare of tim2 (on stm32L073)
then,
in
TIM2_IRQHandler(void)
I try to count the number of call, then stop the toggle. but the in fact, I have more than 5 period.
the command to stop and start the toggle is correct, but the bit duration not. where can I count the exact number of the toggling of tim2 output compare please?
bit_duration = bit_duration +1;
if (bit_duration == 5) // 5 is an exemple to test.
{
TIM2 -> CCMR1 &= ~TIM_CCMR1_OC1M; //set to 0 = keep level
TIM2 -> CCMR1 |= (3 << TIM_CCMR1_OC1M_Pos); // restart the toogle
bit_duration = 0;
}
- Labels:
-
STM32L0 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-07-03 4:19 AM - edited 2024-07-03 4:21 AM
500kHz toggle means 1MHz interrupt rate. That's a bad idea.
Try using timers in master-slave arrangement, slave in gated mode.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-07-03 7:34 AM
thanks to your reply.
I read the document to give, that's why I use the output compare mode of the timer to generate de 1MHz interrupt and toggle.
I will try to use an other timer interrupt base on the tim2 1MHZ interrupt but I need to read more about that I never do this.
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-07-04 1:20 AM
No, I mean, don't use interrupts at all.
Run one timer so that it overflows at 1MHz rate, set one of its outputs to toggle, that will generate you the 500kHz waveform.
Use that timer as slave, i.e. you set its slave-mode controller (in TIMx_SMCR) to Gated mode, and select an another , master timer as TRGI source.
In that master timer, set it to overflow at 100kHz rate, set one of its channels to generate PWM, and select that channel (in TIMx_CR2) to be source of TRGO, which goes towards the slave timer.
That will result in modulated 500kHz waveform; by changing the master timer's channel (which generates the TRGO signal) you can change the modulation.
JW
