PWM Pulse Frequency Duty Cycle Adjustable Square Wave Signal Generator Module (WHL #43)
Haven’t reviewed a lot of China gadgets lately, have I? Well, what about a tiny PWM generator…
I remember having the need for some good old TTL PWM signal and being too lazy to program an Arduino for it. I mean it is dead simple and there are examples included, but hooking up some knobs for live modification of the duty cycle and possibly the frequency as well, nah. There has to be a Wan Hung Lo solution to this, and indeed, there is.
This unit was actually purchased via eBay, as Ali wanted significantly more money for it. I’ve checked and now the eBay is the more expensive dealer, as it basically always is these days. It’s also gotten a bit cheaper, around 2€-2.50€ now compared to the 2.92€ that I paid for. Which, dang, was only 364 days ago, almost nailed it…
Oh, and beware of the cheaper version with three seven-segment displays. That user interface has to be shitty, there’s no way to display the information properly on three digits. Just don’t save those 40 cents. Except, and scroll to the end of this, if you intend to run this over a serial connection and could use two PWM outputs instead of one. Then, by all means, get the crappy two-PWM version and hide it somewhere in your project.
Bare PCB, 5×3-ish centimeters, somewhat prepared for panel mounting. So I could imagine there’s also a version with a nice case available, let me know if you’ve found it!
Those chippies are actually large enough to show their markings with an additional light source, here we go:
Using an Holtek HT1621B display driver, 4 common / 32 segments, 3-wire serial interface for driving the LCD, and the smaller one is doing all the processing work. That’s an ST 8S003F3P6 “value line” micro, with 16 MHz, 8 bit architecture, 8 Kbyte of Flash, 128 byte EEPROM, 3 timers, UART, SPI and I²C. Obviously good enough to do the job! Both ICs feature internal oscillators so that there’s no need for an external crystal, and they don’t really need a precision clock for anything. So save those few cents, the chips are about 0.33 USD for the micro and 0.35 USD for the driver, in like 1-2k quantities. I’m a bit surprised about the thin PCB traces, but these folks in China just went with the pin width of both chips and used them all over the place. So 0.25mm is obviously just fine. Hint: Output power is close to nonexistent, but you wouldn’t directly drive a big-ass fan on your bench signal generator output, would you…
Input and output mounting pads/holes are all doubled, meaning it should be easy to hook them up in various ways. A standard USB plug fits juuust barely to the Vin pins if you extract the data pins. As there’s no mechanical support, I wouldn’t recommend doing that as a permanent solution, but it served me just fine doing my tests. Also, GND of voltage input and signal output are connected, so don’t do dumb things. The output however does survive shorts just fine. Oh, and if you want to hack into it, I guess the unlabelled four pins near the microcontroller could be your way in. They connect to NRST (=Reset), VSS, PD1 (HS/SWIM – the ST programming protocol), and VDD. Now tell me that doesn’t look like a programming interface.
A few more words on price and the LCD: The display fits the purpose of the device quite nicely, so initially I thought this was a custom LCD for it. Turns out: It wasn’t! They found something similar that has five additional fields, “C”, “V”, “W”, “Ah” on the right, and “IN” on the left. The output is always active (except for 0% duty cycle, duh), but the “OUT” field only disappears when changing settings – there’s a “SET” field for that. And there is the “%” field, for which I cannot think of an immediate need for in a DC energy meter, maybe it was a battery charger/discharger. So they found the perfect display from a more sophisticated unit and reused it to save a few cents, brilliant!
The “V”olt field isn’t in use as there’s no real voltage sensing circuit, the micro is sitting behind a regulator and doesn’t care much. It could, in theory, measure the supply voltage, it even has a 10-bit ADC for that. But you would need two additional resistors for a voltage divider, and probably another button on the front, not to mention a few extra bytes of code… So output voltage equals your input voltage, which should be 5-30V (the micro would operate down to 3V, but the LDO probably wouldn’t)
Now some scope measurements: Max frequency is 150kHz, which is displayed as “1.5.0” on the LCD to distinguish it from 150 Hz (“150”):
Sounds alright, frequency is a tad off, but who knows how accurate the hardware counter of my DS1054Z really is…that one says 148.873 kHz.
Minimum is 1 Hz, which is no longer captured by the hardware counter, but at 20 Hz it was spot on:
(yeah, technically the limit is 0 Hz, I’ll get you a screenshot once I found the “infinity seconds” setting on the horizontal knob)
Rise time? Actually not that great. 50ish nanoseconds, so using the 0.35/t rule, that’s only good for about 7 MHz, but the micro certainly will not issue commands that fast when running on the internal 16 MHz RC.
I thought the same would be true for the fall time, but the driver MOSFET does a much better job on turning off. Same scaling, 20ns per div:
That’s much better at 6-7ns, probably even faster – the (unhacked!) DS1054Z is only a 50 MHz scope, and that signal already is in the 50-60 MHz regime. So that’s certainly good enough for me. If you need better fall/rise times, you also probably need more than the 150kHz upper frequency limit, so there’s that.
Power consumption measured by the USB power meter from WHL#17 is 18 to 25mA at 5V, basically constant over the entire frequency range, only dropping below 20mA when on very high duty cycles. Could be a software thing where it goes to sleep, and there’s a bug that prevents it from doing on lower duty cycle settings. There’s no overlap in falling and rising edges, so it shouldn’t be gate capacities and/or switching losses that have a positive effect on high on-time settings.
Also, very low duty cycles (1, 2 and 3% to be precise) aren’t very stable, the scope sometimes missed them. Could be that they aren’t present for whatever reason, could be that I failed to set the trigger correctly (which then worked at 4% and above, hmm). So again, that’s good enough for me, but if you need to have exactly 2% duty cycle, you probably want another step before you go to 3%, which this device cannot do. But that’s what you get for 3 dollars…including shipping
Speaking of software, this unit has three more pins on the side, labelled GND, TXD and RXD for a reason – apparently, this one is also programmable by serial connection. Haven’t tried it, but it just translates the buttons into software:
serial control (single-chip TTL level communication)
9600 bps Data bits: 8
Stop bit: 1
Check digit: none
Flow control: none
1, set the frequency of the PWM
“F101”: Set the frequency to 101 HZ (001 to 999)
“F1.05”: set the frequency of 1.05 KHZ (1.00 ~ 9.99)
“F10.5”: Set the frequency to 10.5KHZ (10.0 ~ 99.9)
“F1.0.5”: set the frequency of 105KHZ (1.0.0 ~ 1.5.0)
2, set the PWM duty cycle
“DXXX”: set the PWM duty cycle to XXX; (001 ~ 100)
Such as D050, set the PWM duty cycle is 50%
3, read the set parameters
Send a “read” string to read the set parameters.
Set successfully return: DOWN;
Setup failed to return: FALL.
That could be quite handy for Arduino integration, don’t you think?
Now, where did I need the PWM signal for…last November