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.

F29H859TU-Q1: the PWM ISSUE

Part Number: F29H859TU-Q1

Hi all,

Scenario:

1. Multiple PWM modules are used, where one master PWM acts as the synchronization source and outputs a sync signal.
2. Phase registers (PHSEN) are not used; they are all enabled but set to 0. Different PWM modules achieve different phases by utilizing CMPA and CMPB.
3. All PWMs operate at a 50% duty cycle and the same frequency, configured for a rising edge on CMPA and a falling edge on CMPB.
4. A separate software task periodically updates the period, CMPA, and CMPB for all PWM modules.
5. Global Load is linked to the counter = 0 event to ensure all updates occur simultaneously.
Current Solution:
  1. The software task calculates the new period, CMPA, and CMPB values, determines whether an extra rising or falling edge needs to be compensated (edge padding/compensation), and sets update_flag = 1.
  2. An interrupt is triggered when the counter of the synchronization master PWM equals 0 (CTR = 0). Inside this ISR, the firmware checks if update_flag == 1. If it is 1, the firmware applies the updates and executes the edge compensation. If no update is required, it clears any pending edge compensation.
  3. (Updating at CTR = 0 guarantees that all shadow registers are loaded into active registers only after all new values have been fully written, preventing a race condition where some registers are updated while others are not).
Proposed Solution:
  1. The software task calculates the period, CMPA, and CMPB for all modules. It then reads the current PWM counter value x to check if it falls within 0~50 (assuming a fixed period of 200).
  2. If x is too large, the task introduces a delay of 200-x to ensure the execution aligns with the beginning of a PWM cycle.
  3. Next, it writes all update values into the respective registers and enables
  4. If edge compensation is required, the task enables the CTR = 0 interrupt. Inside this ISR, the firmware clears the edge compensation operation. 
Check Question:
Will reading the current PWM counter x and evaluating whether it is between 0~50consume too many clock cycles? Could this cause the read value to deviate significantly from the actual hardware time, thereby missing the window to update at the start of the cycle and leading to a race condition where some registers are updated while others are not?
 
Regards,
Jenney
  • Hi all,

    Is there any comment?

    Regards,

    Jenney

  • Will reading the current PWM counter x and evaluating whether it is between 0~50consume too many clock cycles? Could this cause the read value to deviate significantly from the actual hardware time, thereby missing the window to update at the start of the cycle and leading to a race condition where some registers are updated while others are not?

    Just reading PWM counter and checking in if statement would not take too many cycles, maximum 2-3 CPU cycles. 

    You should profile the time completion of the ISR and ensure under different conditions the ISR execution never exceeds PWM cycle - buffer value.

    Thanks