PWM frequency and output granularity
-
Dear experts,
We are trying to setup a PWM output on OUT9 BUFF (laser output) to drive an external system. We need good linearity for this output between 0 and 6000 ideally in steps of 1 above 10kHz.
The configuration code we currently use isM950 R0 C"laser" Q160 L6000
The firmware version is 3.4.1.
Upon testing the configuration above with M3 commands, we noticed that the PWM output is not behaving as we expected. What we measure with our oscilloscope is:
- From 0-64 we have 0%.
- Beyond 65 steps increase with roughly 0.16% for every 9 or 10.
So we have 3 issues:
- We can not achieve values below 65 (which we need in our system)
- The step size is too large (we need 1/6000 on the duty cycle)
- The frequency is too low (we need between 10k and 20k Hz)
Is there a configuration that would achieve this?
For the last issue according to the code it seems the maximum frequency of 150MHz is divided by 128, is this necessary? Might this be a limiting factor?
https://github.com/Duet3D/CoreN2G/blob/3.4-dev/src/SAM4S_4E_E70/AnalogOut.cpp#L284 -
-
@svp_vub you can select PWM frequencies from 2Hz to 65535Hz using the M950 Q parameter.
The available duty cycle resolution does vary with frequency. I can look at improving the PWM resolution at high PWM frequencies in the next RRF 3.5beta release.
As you are using OUT9 I presume the board is a Duet 3 MB6HC. Can you confirm this?
-
@svp_vub further to my previous message, I have just tested the Laser/VFD port on a MB6HC. Instead of configuring it as a laser, I configured it as GpOut because this is easier to test. I used this configuraton command:
M950 P0 C"laser" Q10000
This gives a 10kHz PWM output as expected. I then tested it using M42. The smallest output pulse I can get is about 65ns wide using this command:
M42 P0 S0.0004
Increasing the S parameter to 0.0010 doubles the pulse width to 130ns, and increasing it further to 0.0017 trebles it to 200ns.
This is more or less as expected, because we currently use a PWM clock of 15MHz for PWM frequencies above 228Hz. At 10kHz frequency the available resolution is 1 part in 1500 which does not meet your target of 1 part in 6000.
I will revise the code to improve the resolution.
-
@dc42 indeed we are using a Duet 3 MB6HC.
Thank you very much for the prompt reply, testing and making effort to improve the code!!@alankilian thanks for the suggestion and the quick reponse!