cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F334C8T6,main program is stuck

LXCCCC
Associate

I wrote an interrupt service function HRTIM1_TIMA_IRQHandler() for PID tuning at a frequency of 200kHZ. Is this frequency selection reasonable, after I enabled this IRQHandler, the main program in main.c no longer works, what is the reason?

4 REPLIES 4
AScha.3
Chief II

Maybe there is just no CPU time left, if you jump to interrupt every 5us and do something in the interrupt, that needs the 5us time or even more. So try at a lower frequency or be aware of the time, you need to do things in interrupt and the time limit you have.

And set optimizer to fast or -O2 .

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

The common reason may be not clearing the timer interrupt flag - check this first.

While 200 kHz interrupts may sometimes be reasonable, PID handling at this frequency seems not so reasonable to me. It's hard to believe that: 1. it's needed. 2. there is enough time for PID implementation (5 us).

The most you can do in the ISR at 200 KHz is like 40 lines of C code.

I need HRTIM to generate PWM to control the switching of MOSFETs, and the switching frequency needs to reach 200kHz. Therefore, the period of HRTIM can only be 200kHz. I initially planned to implement single-cycle PID control, but now it seems less feasible. Can I set the triggering frequency of HRTIM1_TIMA_IRQHandler() in CubeMX while keeping the period of HRTIM unchanged?

>Can I set the triggering frequency of HRTIM1_TIMA_IRQHandler

no.

But you can use a simple counter and do the PID at lets say 1/10 timer rate:

in INT:

loop++;

if (loop>9)

{  loop=0; ....calculate...}

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