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.

AM6442: How to change Clock Prescale of EPWM on AM64x/AM243x

Part Number: AM6442

Hi,

I'm going to output PWM smoothly from 1 Hz to 100k Hz. To do that, I need to change Clock Prescale (CLKDIV, HSPCLKDIV) because TBCNT is 16 bits. May I do the change during run-tikme?

  • Hello koichi hamada,

    I am looking at your queries. You may expect a reply within one day.

    Regards,

    S.Anil.

  • Hello koichi hamada,

    Please look at the image below. The VBUSP clock is defined at 250 MHz, and the same clock is going to many peripherals and PRU cores on the SOC level.

    So, if we change that frequency, it will affect the performance of the device. So, we should not touch that frequency.

    For your requirement, matching to 1 Hz is not possible, but you can achieve it at 1.1 Hz.

    I am attaching one excel sheet in which you can just play with the prescalar values and check whether the time period register is smoothly changing or not based on your input frequency.

    My suggestion is that you should divide your required frequency ranges into smaller groups, and for each group, you should use one prescalar value for smooth PWM outputs.

    For example, for smoot PWM output from 1.1 Hz to 100 Hz, you can configure one prescalar values, and for other range frequencies, you can choose different prescalar values based on an Excel sheet.

    PWM.xlsx

    Please let me know if this helps .

    Regards,

    S.Anil.

  • Hello Swargam,

    Thank you for the explanation.

    For example, please consider the case of pulse output with the following specifications.

    • FICLK=250MHz
    • (A) Use CLKDIV=128 and HSPCLKDIV=14 (TBCLK will be 139508Hz) to output from 2Hz to 100Hz.
    • (B) Use CLKDIV=4 and HSPCLKDIV=5 (TBCLK will be 12500000Hz) to output from 101Hz to 500Hz.

    How can I change CLKDIV and HSPCLKDIV to output the following pulses? 

    Can I change CLKDIV and HSPCLKDIV in interrupt process?

    Or should I temporarily stop the output? If so, would you please tell me the way to stop?

    Regards,

    Koichi

  • Hello Koichi,

    I am looking at your queries, and you may expect a reply by today.

    Regards,

    S.Anil.

  • Hello Koichi,

    Please follow the below steps.

    You can create a function for which you just pass an argument of frequency, like the below example.

     

    EX: void frequency_set(uint32_t frequency)

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    void frequency_set(uint32_t frequency)
    {
    if(frequency <=Range1)
    {
    stop PWM output;
    Set Prescalar values based on your requirement;
    Set the frequency;
    }
    else if (frequency <=Range2)
    {
    stop PWM output;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Please follow the above method so that your PWM output change should be very smooth, and this change can be done in a normal application like where you wanted to change frequency by just passing a function and does not required in IRQ .

    Regards,

    S.Anil

  • Hello Koichi,

    Please close thread  if this helps your query .

    Reagrds,

    S.Anil.

  • Hello Swargam,

    I'm not sure what "stop PWM output" is. My understanding is that even if AQCSFRC.CSFA and AQCSFRC.CSFB are 01h (Forces a continuous low), TBCNT will not stop and the PRD_eq interrupt will be generated.

    Would you please give me the example of how to stop PWM output?

    Regards,

    Koichi Hamada

  • Hello Koichi,

    My idea is that when you wanted to change the frequency from one to different ranges, You can stop PWM, which means that PWM drives low output until a new frequency update. So, by using the below register, we can drive the PWM output low for some time again. PWM output should resume after frequency update in Registers. Can you try this method and let me know if you face any issues?

    By using the below API, you can control functionality.

    void EPWM_aqSwTriggerContAction(uint32_t baseAddr,
                                    uint32_t pwmOutputCh,
                                    uint32_t swTrigAction,
                                    uint32_t activeRegReloadMode)

    Regards,

    S.Anil.

  • Hello Swargam,

    Thank you for the idea.

    Regards,

    Koichi