Skip to content

Board XH M188

Elliot Williams edited this page Aug 4, 2017 · 11 revisions

XH-M188 "Power supply"

The XH-M188 is a cheap regulated power supply advertised as "XH-M188 numerical control voltage regulation module", and rated "0-12V 1.5A 18W".


The module has the following features:

  • STM8S003F3P6 (8K Flash, 1K RAM, 128 bytes EEPROM), 5V operation, no crystal
  • 4 Pin SWIM interface (unpopulated), PD1/SWIM shared with 7S-A
  • UI: 3 keys, 3 digit LED display
  • TIP142 Darlington transistor for output
  • output voltage set-point by 4.5 kHz PWM with PC6/TIM1_CH1
  • L7805 5V regulator for "reference voltage"

Out-of-the-Box Product properties:

  • the "numerical control" is limited to setting the PWM duty-cycle with "+" and "-" key
  • there is no digital feedback loop (analog control with LM358 and TIP142)
  • the display value represents "duty cycle * X"
  • the output voltage can be adjusted with the help of a trimmer potentiometer
  • the LED multiplex clock is about 16 PWM cycles

Due to a bug in the PMW code, every 16th cycle is only about half. This leads to an analog ripple with about 280 Hz, and more importantly to an offset (which can't be compensated with a trimmer). The ROM code of the STM8S is, of course, read-protected.

Board Support

@hexagon5un contributed board support code which is part of the binary release as of v2.2.11. There is also a project on tracking the progress.

Correcting the firmware PWM routine, and supplying 15.2 V or more (to compensate for the output transistor's dropout) yields very accurate voltage output across the 0 V - 12 V range.

Serial Console

In the default XH-M188 Forth binary, the Forth console communicates through pin1 (PD5/TxD) and pin10 (PD6/RxD) of the 7S-LED socket. By changing the settings in in the board folder it's possible to use other GPIOs for the serial console, and it's also possible to use two serial interfaces concurrently.

Please refer to the serial interface instructions.

Voltage Control PWM Output


; PWM! ( pwm -- ) 
; Set PWM duty cycle
; Max seems to be around 3300 (3583 is full on)

; MV   ( millivolts -- )
; Set PWM to desired voltage output.

Once the (sub-par) code in the original firmware is replaced, the voltage output can be trimmed to be fairly accurate. To match the default scaling, set it to 5.000 V (5000 MV) and then adjust the trimpot until 5.000 V is output. YMMV, but my two samples are within ten millivolts of the desired value from 1.000 V to 12.000 V.

Analog Inputs

Analog inputs can be used with the words ADC! (select a channel), and ADC@ (read a selected channel):

\ define word to read from Ain4, pin2 of the 7S-LED socket 
: 4 ADC! ;

\ measure and print the result
ADC@ . 1010 ok

Pushbutton Character I/O

The 3 keys of the XH-M188 are supported by STM8EF vectored I/O: In a background task the ?KEY vector is assigned to ?KEYB for reading board keys in the same way as ?RX does in the foreground task for reading characters from the serial interface.

In a foreground task, ?KEYB detects a button press event, and returns true once when a button is pressed. The word BKEY reads the board pushbuttons as a bit-field (with '-'=1, '+'=2, and 'on/off'=4). Between these two, it should be possible to read and react to user input.

Technical description

The schematics of the XH-M188 is unknown, but it seems to be very simple. Besides the power supply (LM7805, SS54), and the output voltage regulator (LM358, TIP182), there is the "numerical control" circuit (STM8S003F3P6, 7S-LED 3361BS common anode, 3 keys with pull-up). The LED display is on a socket, providing access to 11 GPIOs by simply removing the LED display.

The STM8S003F3P6 has the following connections:

Pin	STM	Connected to
1	PD4	7S-D (R12 470R)
2	PD5	7S-E (R13 470R)
3	PD6	7S-F (R2 470R)
4	NRST	ICP pin 3 
5	PA1	7S-G (R9 470R)
6	PA2	7S-DP (R11 470R)
7	VSS	GND, ICP pin 4
8	Vcap	C
9	VDD	+5.0V, ICP pin 1
10	PA3	7S-V3 (anode digit 3)
11	PB5	Key "+" (R8 470R to +5V)
12	PB4	Key "-" (R6 470R to +5V)
13	PC3	(n.c.)
14	PC4	Key "on/off" (R3 470R to +5V)
15	PC5	7S-V2 (anode digit 2)
16	PC6	PWM (to LP-filter)
17	PC7	7S-V1 (anode digit 1)
18	PD1	7S-A (R1 470R), SWIM ICP pin 2  
19	PD2     7S-B (R5 470R) 
20	PD3	7S-C (R10 470R)

Note that my sample has problems with ICP programming unless a pull-up resistor (e.g. 1k) is applied. This indicates generally poor PCB layout or insufficient decoupling (general neglect of the design rules in AN2752).

LED Display Pin Assignment

The 7S-LED display can be removed and the socket can be used as a µC port breakout. This option is attractive for applications that require cheap, and easily available programmable power supply board, but no LED display. GPIOs with additional features (robust communication, SPI, ADC, timers) are readily available at the LED display pads. Pin 6 (NC) can be connected to ground, and used as a ground connection for a stacked circuit board.

7S-LED Pin segment GPIO pin STM8
1 E PD5 pin2 (470R)
2 D PD4 pin1 (470R)
3 DP PA2 pin6 (470R)
4 C PD3 pin20 (470R)
5 G PA1 pin5 (470R)
(6) - - -
7 B PD2 pin19 (470R)
8 V1 PA3 pin10
9 V2 PC5 pin15
10 F PD6 pin3 (470R)
11 A PD1/SWIM pin18 (470R)
12 V3 PC7 pin17

Power Supply Properties

The output voltage is controlled by the duty cycle of PC6/TIM_CH1. Please note that when PC6 is in input mode the output voltage goes to the maximum (e.g. software error, stuck-at reset). The design doesn't have any fail-safe properties, and consequently unprotected loads can get destroyed by over voltage.

Display value and PC6/TIM1_CH1 duty cycle:

  • "00.1" - 1µs / 221µs
  • "02.5" - 32µs / 190µs
  • "05.0" - 63µs / 159µs
  • "07.5" - 95µs / 123µs
  • "10.0" - 126µs / 96µs

The maximum output voltage seems to be 11.4 V (at the rated supply voltage of 15 V). The accuracy drops considerable from just below 11V.

All this doesn't mean that the board is good for nothing. At $4.75 it's a candidate for inexpensive lab equipment for home-brew test automation if certain precautions are taken. However, the only GPIO on a header is also used for the 7S-LED display, and this makes establishing a communication link tricky.

You can’t perform that action at this time.