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;
}
2024-07-03 04:19 AM - edited 2024-07-03 04: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