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?
From GitHub CoPilot:
The main differences between [cot_pwm_3.cpp] and [cot_pwm_4.cpp] are:
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.
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.
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.