cancel
Showing results for 
Search instead for 
Did you mean: 

Stat and stop toggle of output compare mode precisely

Seth1er
Associate II

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;

}

1 REPLY 1

500kHz toggle means 1MHz interrupt rate. That's a bad idea.

Try using timers in master-slave arrangement, slave in gated mode.

JW