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.

Compiler/TMS320F28035: pwm1.PeriodMax = SYSTEM_FREQUENCY*1000000*T/2;

Part Number: TMS320F28035
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: TI C/C++ Compiler

C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v2.1\HVPM_Sensored

What does the formula for "marked red" mean? Why do we do this calculation?

// Initialize PWM module
pwm1.PeriodMax = SYSTEM_FREQUENCY*1000000*T/2; // Prescaler X1 (T1), ISR period = T x 1
pwm1.HalfPerMax=pwm1.PeriodMax/2;
pwm1.Deadband = 2.0*SYSTEM_FREQUENCY; // 120 counts -> 2.0 usec for TBCLK = SYSCLK/1
PWM_INIT_MACRO(1,2,3,pwm1)

// Initialize PWMDAC module
pwmdac1.PeriodMax=500; // @60Mhz, 1500->20kHz, 1000-> 30kHz, 500->60kHz
pwmdac1.HalfPerMax=pwmdac1.PeriodMax/2;
PWMDAC_INIT_MACRO(6,pwmdac1) // PWM 6A,6B
PWMDAC_INIT_MACRO(7,pwmdac1) // PWM 7A,7B

  • The code calculates the value of PWM period register based on the PWM frequency (T) and CPU frequency ( SYSTEM_FREQUENCY), and the count mode of PWM for motor drive is up/down mode, so it needs to be divided by 2.
    pwm1.PeriodMax = SYSTEM_FREQUENCY*1000000*T/2; // Prescaler X1 (T1), ISR period = T x 1

    PWMDAC is an option function for motor control, just used for debugging, to converts any s/w variables to an analog signal using PWM signals through the external low-pass filters. Below code will be used to set the period register value of PWM for PWMDAC function, the PWM frequency must be greater than the cut off frequency of LPF.
    pwmdac1.PeriodMax=500; // @60Mhz, 1500->20kHz, 1000-> 30kHz, 500->60kHz

    Please refer to PWM_INIT_MACRO() and PWMDAC_INIT_MACRO(), both calculated value will be set to related PWM period registers.

  • Hi 

    what does exactly "T" means in the code? why it is referred as sampling frequency instead of PWM frequency :

    float32 T = 0.001/ISR_FREQUENCY;    // Samping period (sec),  see parameter.h 

    and what is ISR_FREQUENCY ?

    // Define the ISR frequency (kHz)
    #define ISR_FREQUENCY 10

    regards

  • As the comments for the code, ISR_FREQUENCY is the frequency of interrupt subroutine, often, it equals to PWM frequency, and PWM frequency equals to sample frequency for ADC by default. T is the period with sec unit of ISR/PWM.
  • Hello dear Luo
    Thank you so much.
    I have got it.
    regards