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:
- The software task calculates the new period,
CMPA, andCMPBvalues, determines whether an extra rising or falling edge needs to be compensated (edge padding/compensation), and setsupdate_flag = 1. - An interrupt is triggered when the counter of the synchronization master PWM equals 0 (
CTR = 0). Inside this ISR, the firmware checks ifupdate_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. - (Updating at
CTR = 0guarantees 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:
- The software task calculates the period,
CMPA, andCMPBfor 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). - 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.
- Next, it writes all update values into the respective registers and enables
- If edge compensation is required, the task enables the
CTR = 0interrupt. 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?
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