cancel
Showing results for 
Search instead for 
Did you mean: 

problem at while loop

Lchal.1
Associate II

HI, i am using two timers in interrupt mode by setting 100khz frequency for each . one timer interrupt is for my power factor calculation and other one for current calculation. But the problem is when it comes to while loop. once my code enter into interrrupt functions works fine after coming out of the interrupt it is not entering while loop . and the logic inside the while loop is also not executing. can anyone help me with it please . why i am not able to enter and execute while loop.

Thank you

12 REPLIES 12
KnarfB
Principal III

The interrupts are quite frequent @100kHz. Maybe there is no time for the main loop left because one interupot is always pending? Lower the freq. for testing.

Even if i lower the frequency in one timer to 1khz and other timer as usual 100khz . still its not going to while loop and even it is affecting the other timer which i set to 100khz . can you help me what is the problem in my logic.

Thank you

We cannot see your code.

I suggest to add code lines that toggle a GPIOs at the entry and exit of the invovled interrupt routines, and watch them with a scope.

Supposedly, your interrupts overrun their time slot, at least occasionally. That should show on the scope.

Thank you

0693W000008GOVlQAO.jpg0693W000008GOVvQAO.jpg0693W000008GOVqQAO.jpg0693W000008GOVbQAO.jpg0693W000008GOVMQA4.jpgeven i checked in scope waveforms are generating for both timers. Actually my timer and while is working only once after it will be stopped. Again it is not repeating . i have attached my code below please help me what i have done wrong and what i need to add it.

Thank you

As it seems, you do floating point operations inside the interrupt handler, and LCD operations. Callbacks run in interrupt context.

That looks deadly.

The fp routines might cause no runtime problem on M4 MCUs, but have an impact on stack handling.

See e.g. here:https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/10-useful-tips-to-using-the-floating-point-unit-on-the-arm-cortex--m4-processor

I suppose your LCD operations will overrun the time budget by an order of magnitude.

Such things are not done in interrupt context.

Thank you

The code is working fine now. Thanks for helping me . But it is not running continuously instead after running few minutes it shows HardFault error like this. I have attached the photo below . Please help me what is the wrong in my code and how to solve it.

Thank you0693W000008GWTYQA4.jpg

The code is working fine now. Thanks for helping me . But it is not running continuously instead after running few minutes it shows HardFault error like this. I have attached the photo below . Please help me what is the wrong in my code and how to solve it.

Thank you0693W000008GX6zQAG.jpg