1

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..

4
  • 1
    I can't see any Pi relevance. It appears to be a general programming question.
    – joan
    Commented Oct 20, 2019 at 15:50
  • @Nicholas Francis, Your coil winding machine application is interesting, reminding me of once upon a time, me using geared DC motor winding inductor coils with a optical detector to count the number of turns. BTW, earlier I made a quick reply which sig gen to try and I thought I have answered every thing, though I thought your sig gen + uart control does not seem perfect. Actually I am playing with PWM stuff and perhaps I can counter suggest something for brainstorming.
    – tlfong01
    Commented Oct 21, 2019 at 12:39
  • @Nicholas Francis, This XY-LPWM toy is dirt cheap but very "professional", therefore super popular among poor hobbyists like me. If you google "XY-LPWM", you will be surprised to see the number of searched results returned. You can also easily find Arduino programs with UART control. Happen python programming and cheers.
    – tlfong01
    Commented Oct 21, 2019 at 12:51
  • @Nicholas Francis, So I have tested my XY-LPWM sig gen serial control OK, using Win10 RealTerm USB/serial to send commands and receive responses to/from XY-LPWM. Please let me know if there are other things I need to explain. I will wait for you to catch up, before moving to python programming. Cheers!
    – tlfong01
    Commented Oct 22, 2019 at 5:35

2 Answers 2

3

Question

How can Rpi4B python UART talk to XY PWM Signal Generators?


Answer

Contents

(1) Introducing XY-LPWM, UART support version of XY-PWM

(2) Using Win10 RealTerm terminal emulator to serial/UART talk to XY-LPWM

(3) Using Rpi python program to serial/UART talk to XY-LPWM


(2) Using Win10 RealTerm terminal emulator to serial/UART talk to XY-LPWM

I am now using Win10 RealTerm terminal emulator to talk to XY-LPWM. The serial parameter setting is the following:

9600, N81 (9,600 baud, No parity, 8 data bits, 1 stop bit)

(a) I first did the RealTerm loop back, shorting TxD to RxD, and make sure any characters typed at the keyboard or send by RealTerm will be looped back / echoed at the RealTerm screen.

realterm wiring

(b) Then I connected Win10 RealTerm USB to serial adapter/cable to the XY-LPWM sig gen as show below:

--------------------------
Win10 USB Serial   XY-LPWM
--------------------------

TxD                 RxD

RxD                 TxD

Gnd                 Gnd

---------------------------

Then I send commands

(1) "F010 to To set frequency 101Hz,

(2) "read" to read back "F010", "D050" confirming everything OK.

The two commands and response are displayed below:

xy-pwm commands

/ to continue, ...


(1) Introducing XY-LPWM, UART support version of XY-PWM

The OP's sig gen is XY-PWM, which does not support Serial/UART communication/control. There are other versions of XY-PWM which support Serial communication, Examples are (1) XY-LPWM (Ref 1), (2) XY-KWPM (Ref 6).

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).


xy-lpwm


References

(1) XY-LPWM 1Hz-150KHz Signal Generator PWM Module

(2) Holtek Semiconductor

(3) Nuvoton Technology

(4) HT1621 RAM Mapping 324 LCD Controller for I/O MCU Datasheet

(5) Nuvoton H76E003 mcu datasheet

(6) AliExpress (UART support) XY-KPWM Signal generator 1 channel 1Hz-150KHz PWM pulse frequency duty cycle module adjustable LCD display - US$3.6

(7) XY-LPWM Sig Gen English Manual


Appendices

Appendix A - XY-LPWM sig gen pair calibration record

sig gen test 1

sig gen test 2

Appendix B - XY-LPWM sig gen user guide with serial communication instructions

sig gen uart

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

AliExpress (UART support) XY-KPWM Signal generator 1 channel 1Hz-150KHz PWM pulse frequency duty cycle module adjustable LCD display - US$3.6

Features:

  1. UART support
  2. Frequency range (Normal mode): 1Hz ~ 150KHz;
  3. Frequency range (precise mode): 1Hz ~ 15 KHz;
  4. Frequency accuracy: 2%;
  5. Accuracy of the duty cycle: 1% in Normal mode;
  6. Accuracy of the duty cycle: 0.1% in accurate mode;
  7. Service cycle range: 0.00% -100%;
  8. Output current: approximately 5-30mA;
  9. output amplitude: identical to the input voltage;

XY-KPWM UART User Guide

xy kpwm uart


End of answer

2
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Bex
    Commented Oct 21, 2019 at 9:08
  • You suggestion is very good. So I have improved my answer. Cheers.
    – tlfong01
    Commented Oct 21, 2019 at 9:34
1

'F10.5' :Set frequency is 10.5KHz.' 10.5' can by replace by 10.0~99.9;

Range 65.5-99.9 does not work. Probably something wrong in generator code - uint16_t limit overflow.

1
  • Also in my case only "read" "Fxxx" and "Dxxx" commands are workng.
    – Gawron
    Commented Jun 28, 2023 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.