Skip to main content
Visitor II
December 25, 2023
Question

STM32F334C8T6,main program is stuck

  • December 25, 2023
  • 2 replies
  • 1296 views

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?

    This topic has been closed for replies.

    2 replies

    Super User
    December 25, 2023

    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 .

    Graduate
    December 25, 2023

    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.

    LXCCCCAuthor
    Visitor II
    December 26, 2023

    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?

    Super User
    December 26, 2023

    >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...}