Would anyone help figure out why the two C++ modules of multiphase PWM work differently?

Would anyone help figure out why the
cot_pwm_3.cpp (9.7 KB)
cot_pwm_4.cpp (9.8 KB)
COT_set _3.qsch (5.4 KB)
COT_set _4.qsch (5.4 KB)
two C++ modules of multiphase PWM work differently?[quote=“JJH, post:1, topic:21184, full:true”]
Would anyone help figure out why the
cot_pwm_3.cpp (9.7 KB)
cot_pwm_4.cpp (9.8 KB)
COT_set _3.qsch (5.4 KB)
COT_set _4.qsch (5.4 KB)
two C++ modules of multiphase PWM work differently?
[/quote]

set_frequency_limitation.cpp (1.9 KB)

Hi, JJH.

I don’t want to sound glib or condescending but there are only a few lines of code changes. What about the code is doing something that is unexpected? Perhaps you could simplify the code to demonstrate the issue more clearly?

–robert

From GitHub CoPilot:
The main differences between [cot_pwm_3.cpp] and [cot_pwm_4.cpp] are:

  1. Additional Variables in [cot_pwm_4.cpp]:
  • [cot_pwm_4.cpp] includes additional arrays [pwm_off_time] and [pwm_on_time] to store the times when each PWM turns off and on, respectively.
  • [cot_pwm_4.cpp] includes a [first_round_completed] boolean to track if the first round of PWM activations is done.
  1. Logic for PWM Activation:
  • In [cot_pwm_4.cpp], the logic for setting the PWM pins high includes additional checks for [mini_off_time] constraints after the first round of activations.
  • [cot_pwm_4.cpp] uses [pwm_off_time] to ensure that the minimum off time ([mini_off_time]) has passed before reactivating a PWM pin.
  1. Handling of PWM Turn Off:
  • [cot_pwm_4.cpp] updates [pwm_off_time] when a PWM pin is turned off, which is not present in [cot_pwm_3.cpp].

These changes in [cot_pwm_4.cpp] provide more detailed control over the timing of PWM signals, ensuring minimum on and off times are respected.