This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[InstaSPIN] change pwm frequency at runtime

Other Parts Discussed in Thread: MOTORWARE

Hello dear e2e-community,

We are designing a motor control system for a customer based on InstaSPIN / MotorWare. Our customer wants to be able to change the PWM frequency without having to compile the program, just by using the CAN interface we provide. Just the range from 10 to 20 kHz.

Is it possible to change the PWM frequency at runtime?

My first thought was to replace the #define from the user.h with a variable (with the exact same name), and when the variable gets changed, to start over with the whole initialization process. So all dependant parameters would be calculated anew. Would this work?

Or is there a better way to do this? Have you done this before? Is there perhaps some example code available?

Thank you very much and best regards,

Philipp

  • Philipp,

    you wish to change the PWM frequency in system but not WHILE running, correct?

    Yes, this is possible.  Essentially you just need to update gUserParams (from user.c) with any changes.

    and then reinitialize everything that uses these params

      // initialize the user parameters
      USER_setParams(&gUserParams);


      // set the hardware abstraction layer parameters
      HAL_setParams(halHandle,&gUserParams);

      // set the default controller parameters
      CTRL_setParams(ctrlHandle,&gUserParams);

    you should also be cognizant of the effect of changing the pwm frequency on

    - the effective control loop frequency and CPU loading (do you need to update the PWM_TICKS as well?)

    - the control loop gains, which use the control loop frequency in their calculation. considering running updateKpKiGains and look at the effect on your speed controller gains or having a set of fixed gains that you have tested to load with each PWM frequency change