Vary Frequency in PWM output instead of duty cycle.
Hi, I have an external peripheral where it would be useful to vary the pwm frequency instead of the duty cycle from 0-65535Hz. Is this possible with M42? Better yet, would it be possible to implement something similar to M106 so I could have a nice slider in DWC?
bearer last edited by bearer
M42 is stricktly for on/off, and it seems M42 two consequiteve M42 take about 1ms on a Duet2Wifi, so that'll limit you to about 500hz.
Haven't looked at how
M160M106 or M280 deals with changing the base frequency while outputting a signal, but I wouldn't be surprised if there were some artifacts.
What kind of response times and resolutions are you looking for; and are there no other control options?
baird1fa last edited by
what you are looking for is not PWM (pulse width modulation) you want FM (Frequency Modulation). I would suspect that the duet is not setup to use FM as it is not mentioned anywhere in the documentation. As Bearer said you can change the base frequency of the PWM and if you set the PWM to 50% and then changed the base frequency it might work to act like frequency modulation, but i doubt it. Give it a try, it can't hurt.
I do believe you can buy conversion hardware that will take a PWM signal and convert it to an FM signal.
This is actually for driving a Clearpath Servomotor in Torque command mode, where the most accurate way to control it is with frequency of a square wave. It will probably work if I just reconfigure the pin every time, but I was hoping there was a more convenient way to do it.
See https://www.youtube.com/watch?v=PsCY2qx6dK8 for an exxample.
bearer last edited by
video shows you can use both pwm duty cycle and frequency control?
but if you don't need frequent updates and the control doesn't react to any undesired frequency components as a result of changing the frequency then it might work with M106.
Yes, but the Duty Cycle control mode is much less accurate (from using some function generator testing.
It'll probably be adequate for what I need to do.
bearer last edited by
interesting, i suppose the duty cycle can only be adjusted in 255 steps (unless using a 0..1 notation with decimals gives finer resolution?).
you might find the limited duty cycle adjustment of M280 to be not suited for frequency control, but M106 will let you change both the frequency and the duty cycle. testing might be the best manor of determining the min/max frequency the duet can produce as well as the resolution and linearity.
Unfortunately, M106 doesn't support frequency change in RRF3 :(. Gotta use M950.