Currently I am trying to automate a coil winding machine using stepper motors. I wrote a Python code to send frequencies to the stepper motors. But for some reason, the frequencies produced by raspberry were not steady, their fluctuations were quite uncontrollable. So I ended up buying 2 XY-PWM Frequency Generators to give out frequency to the steppers, and they worked perfectly. Their wave-forms were rock steady , very stable.
Now, my question is, how am I able to control these 2 frequency generators or talk to them using Raspberry Pi via the UART protocol, and what Python script should I use for this communication between the Pi and the frequency generator to occur?? Please suggest…..Thank you..
How can Rpi4B python UART talk to XY PWM Signal Generators?
I have been using the following “XY-LPWM” sig gen for a couple of years. This is the only cheap, hobbyist grade square wave signal generator I know that has both manual and software / UART control.
The manual control interface is very user friendly. You press frequency up button, frequency goes, up. Similarly for frequency down button and duty cycle up and down buttons.
I used a scope to check the waveform and found it steady, at least for low frequency range from 1kHz to 10kHz. Actually other analog sig gen like NE555 astable, or Rpi master clock divided software PWM signal, can not be compared with the very precise dedicated mcu processed signal. As the signal is actually generated by a MCU (Nuvoton H78E003), so UART control should be easy, though I have not tried it. I googled and found a couple of Arduino UART programming example controlling this XY-LPWM sig gen. It should be easy to convert the Arduino UART program to Rpi.
Actually I bought the sig gen from TaoBao, which is always cheaper than AliExpress or Amazon. AliExpress and Amazon usually include the reseller’s brand name. But this Taiwan based model is OEM, there is no distributor name, except the model number “XY-LPWM”.
So you google with search keywords “XY-LPWM” + “AliExpress” + “Amazon” + “PWM” + “signal Generator”, you should find it.
PS – The two MCUs used are from Holtek (HT1621B), and Nuvoton (H78E003A120). You may like to check out their new sig gen and other updated products (Refs 2, 3).
Appendix A – XY-LPWM sig gen pair calibration record
UART communication and parameter settings
1. UART parameter setting: TTL 9600, N, 8, 1
2. Set PWM frequency:
‘F101′ :Set frequency is 101Hz.’ 101′ can by replace by 001~999;
‘F1.05′ :Set frequency is 1.05KHz.’ 1.05′ can by replace by 1.00~9.99;
‘F10.5′ :Set frequency is 10.5KHz.’ 10.5′ can by replace by 10.0~99.9;
‘F1.0.5′ :Set frequency is 105KHz.’ 1.0.5′ can by replace by 1.0.0~1.5.0;
3. Set PWM duty cycle:
‘DXXX’: Set duty cycle is XXX. ‘ XXX’ can be 000-100.
Example: ‘D051’ means PWN duty cycle is be set as 51%.
4. Read set parameter:
Send ‘read’ and then get parameter.
5. Return value:
Returns ‘DOWN’: Set success.
Returns ‘FALL’: Set fail.
Appendix C- XY-KPWM Sig Gen Spec and UART user guide
- UART support
- Frequency range (Normal mode): 1Hz ~ 150KHz;
- Frequency range (precise mode): 1Hz ~ 15 KHz;
- Frequency accuracy: 2%;
- Accuracy of the duty cycle: 1% in Normal mode;
- Accuracy of the duty cycle: 0.1% in accurate mode;
- Service cycle range: 0.00% -100%;
- Output current: approximately 5-30mA;
- output amplitude: identical to the input voltage;
XY-KPWM UART User Guide
End of answer