When we added some new features to the Yocto-PWM-Tx three month ago, a customer reminded us that he had also made a suggestion for improvement, regarding the synchronization between the two output channels. So we have kept our word, and this has now been implemented as well. Let's see how this works...
Phase shift transitions
Until today, the two output channels present on the Yocto-PWM-Tx were running entirely independently: each one has only been taking care of its own frequency and duty cycle, but no synchronization was possible.
There are a few applications for which it is useful to control the phase shift between two generated signals. This may serve for instance to generate a quadrature signal, or to open two FET one after the other. The phase shift might even be used as an alternative to duty cycle to transmit an analog value over a PWM signal.
So we have added to the YPwmOutput class a method
which can be used to progressively shift the phase of the selected output in order to get the desired shift with regard to the other output. The phase shift is specified in milliseconds, with a resolution of one microsecond. When the phase shift should be made within one cycle, specify a duration of 0. Otherwise, you can have a linear phase transition occurring within the requested duration, in millisecond. Here is what you get:
phaseMove(0.5, 1500) on a 400Hz signal, and back
There are a few limitations with this new feature:
- You can only use it for frequencies under 31 KHz. There might be a way to implement it for higher frequencies, but that would make it significantly more complex and till now nobody asked for it...
- As phase transitions are based on a temporary fine adjustment of the signal period, some constraints of the signal generator apply. In particular, the 62.5ns resolution of the period implies that it is not always possible to produce the exact transition duration requested, in particular for high frequencies. In the worst case, the transition will be a bit faster than requested, but the resulting phase shift will match the requested value.
- Both channels must obviously run at the exact same frequency (or possibly a multiple of it), otherwise the phase shift will not be kept over time.
And since we have the camera and the scope in place, we will take the opportunity to also illustrate the other new features presented in the previous article about the Yocto-PWM-Tx, since at that time we only used simple schemas...
Duty cycle transition
dutyCycleMove(10, 1500) on a 400Hz signal, and back
frequencyMove(1000, 1500) on a 400Hz signal, and back