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;

}

2 REPLIES 2

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

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

JW

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