cancel
Showing results for 
Search instead for 
Did you mean: 

Timer interrupt discontinuity issue using stm32f103c8t6

Shahid
Associate II

Hi 

I am trying to generate interrupt every 100uSec using Timer-2 using stm32f103c8t6 blue pill. I have simply set the system clock to 72 MHz pre scaled the timer two by 72 time using 72-1 and setting counter period to 100. I have also enabled TIM2 Global Interrupt in NVIC global interrupt setting. I started this timer in main function by using following command

a.PNG

Also, I used the interrupt routine using following code where I am toggling Pin A5 on each interrupt to test the interrupt generation.

b.PNG

 

The interrupt was generated correctly as shown in the following image

1.jpeg

 

However, when I increased the time scale of oscilloscope, I found the interrupt generation is discontinuous after every 10 msec as shown below

2.jpeg

I further increased the time scale and found significant halt in interrupt generation as shown below

 

3.jpeg

I am not sure what is making this interrupt generation to be discontinuous. Actually, I want to generate sine wave

reference for PWM generation. I observed above mentioned anomalies when I generated the sine wave

and the sine wave was disturbed at these discontinuous points. For this code at the moment, I am not using any

other peripheral of the controller or not performing any other task except this interrupt generation and toggling the pin in this interrupt call back.

Can anybody please help to resolve this issue so that I may get continuous interrupt throughout the time.

5 REPLIES 5
AScha.3
Chief III

Hi,

maybe any other interrupt doing something ? (HAL timer...delay..etc.)

So are any other INT enabled/active? (or DMA, other callbacks?)

How you set the priorities of all,  esp. this INT ?

If you feel a post has answered your question, please click "Accept as Solution".

Dear

Nothing else is active in this code, I was also assuming that may be any other interrupt source may be resulting in this situation. Therefore, I started a new project where I just initialized this timer interrupt and GPIO PIN A5 to observe the interrupt. Nothing else is active.

I just enabled the global interrupt and did not set any interrupt priority as I am not using any other interrupt source.

c.PNG

The TIM itself can automatically toggle one of it's CHx pins

If you want to modulate a PWM signal you could use DMA the content for a CCRx out of a table. The table could be circular

Running in a debugger, or monitoring variables externally, may result in time critical errors due to bus/mcu stalling to deal with external requests.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you very much for your kind response. If I create a circular table for sine wave values, I will need to fetch each value at a regular interval like 100uSec in this case. Can you please guide how I can use DMA to fetch sine wave values at this regular interval. Consistency of time interval is very important as the sine wave carrier will be operating a PWM inverter and any fluctuation in this carrier may result in serious consequences while operating inverter under loaded conditions.  

Best Regards

Anyway...

look at the NVIC setting, to see, whats set to active and priority :

AScha3_0-1718224458834.png

+

Check with scope the INT timing , but without active debug (just hard reset and run).

If you feel a post has answered your question, please click "Accept as Solution".