Is it possible to obtain pulses with a duration of 100 nanoseconds and with a period from 1 Hz to 100 kHz using PWM? I tried PWM2 and with decreasing frequency, the accuracy of the duty cycle decreased.
var freq = 100_000;
var duty = 0.01;
var PWM2 = PwmController.FromName(SC20260.Timer.Pwm.Controller2.Id);
var PWM2_4 = PWM2.OpenChannel(SC20260.Timer.Pwm.Controller2.PA3);
PWM2.SetDesiredFrequency(freq);
PWM2_4.SetActiveDutyCyclePercentage(duty);
PWM2_4.Start();
The CCR register is used to adjust the duty cycle. For timers 2 and 5 it is 32 bit and for other timers it is 16 bit. Therefore, I used timer 2 and hoped for a high accuracy of the duty cycle. But the result is the same as for 16 bit timers. Where is the mistake? Or I’m wrong?
I am assuming you are using the CCR register to tune the duty cycle.
I get exactly 100ns dutycyle on 100 kHz.
And I couldn’t get exactly 100ns dutycyle on frequencies below 10 kHz.
With decreasing frequency, the accuracy of setting the duty cycle decreases!
On 100 Hz doesn’t work at all