Skip to content

Board CN2596

Thomas edited this page Apr 11, 2017 · 30 revisions

CN2596-2 "DCDC converter with Voltmeter"

Certain very low cost LM2596 based DC/DC converters with an STM8S003F3P6 based voltmeter can be modified into a programmable power supply with little effort. There is an ongoing project "Low-Cost Programmable Power Supply" on Hackaday.io, which also demonstrates use cases like automotive power-supply robustness test ("cold-cranking").

Release v2.2.8 introduces support for modified CN2596-2 boards.

PCB modification for LM2596 control

In order to control the LM2596 with the voltmeter µC some simple modifications of the board are required. The picture below shows a fully modified board.

CN2596-2 mod

1. Prepare the board:

  • remove LED "IN"
  • remove LED "OUT"
  • interrupt the connection between LM2596 pin 5 (!ON/OFF) and GND (i.e. cut the pin in the middle, and de-solder the lower half)
  • carefully cut the copper trace between the LM2596 heat sink GND and the 330R next to the trimmer.
  • cut the copper trace between LM317 pin2 and anode pad of LED "IN". Expose some of the copper of the trace near said pad.

2. Add new components:

  • solder a C 100nF between LM317 pin 2 and GND on the backside of the PCB
  • solder a 10µF ceramics capacitor 0603 or 0805 over the now cut copper trace between the LM2596 heat sink GND and the adjacent pad of the 330R next to the trimmer
  • solder a 47R 0805 resistor to the pads of LED "IN"
  • solder a 1k8 0805 resistor to the pads of LED "OUT"

3. Make new connections for controlling the LM2596:

  • add a wire between the cathode pad of LED "OUT" (PB4) and LM2596 pin 5
  • add a wire between the copper trace near the anode pad of LED "IN" (PC3) to the 330R pad, where also the 10µF capacitor is connected
  • connect (pin 2 || pin 3) of the trimmer to pin 1 of the voltage adjust trimmer on the board

4. Add a SWIM connector and program the µC:

  • add a 2 pin programming connector to GND and pin 4 of the 7S-LED display (segment C, PD1/SWIM).
  • get the binary from the v2.2.8 release (or later)
  • programming the STM8S003F3P6 with an ST-LINK adapter by programming SWIM and GND to the programming connector

5. Add and test the serial console interface:

  • solder the anode of a 1N4148 diode to pin 3 of the 7S-LED display (segment DP, PC7).
  • wire a 3 pin connector to pin 3 of the display, the cathode of the 1N4148, and to GND.
  • connect the RxD line of a serial-TTL converter to the "anode pin" of the serial connector, and TxD to the "cathode pin"
  • start a terminal program at 9600 baud, and test the connection by pressing ENTER

Note: the serial interface works in "half-duplex" mode without collision detection, which is sufficient for interactive use, and for command-response automation. Details are described here.

Code for power supply control

Using a voltmeter and the interactive Forth console, the function U=f(PWM) can be estimated. It turned out that between 0 and 1V the function is less smooth, and an extra grid point is needed.

PWM to U

Also, it wasn't possible to get below 20mV output voltage (after all, a bias to the feedback ground of an LM2596 is a hack). The last grid point is 469/20mV.

: @dif ( a -- n )     \ delta of value pairs
  dup 2+ 2+ @ swap @ - ;
: @inter ( x a -- y ) \ find value pairs, interpolate
  dup @ 1- >R 2+ dup begin 
    3 pick over @ < not while 
    nip dup 2+ 2+ next 
      drop dup
    else R> drop then \ eForth LEAVE idiom
  over = if           \ pointers equal: saturation 
    2+ @ nip 
  else 
    dup rot over @ - over 2+ @dif 
    rot @dif */ swap 2+ @ + then ;

@inter does a table lookup with interpolation. The input is the value and the address of a table with n value pairs (Xn, Yn) ordered by ascending values of X, and preceded by the number of n. @dif looks up two values returns the difference (X1-X0 or Y1-Y0 depending on the offset). Compiled, this code needs just 177 bytes.

When representing the voltage in units of mV, and the following table with 14 grid points does the linearization:

FILE NVM
CREATE vptab
14 ,
469 20 , , 451 500 , , 434 1010 , , 401 2000 , ,
367 3010 , , 333 3990 , , 297 5010 , , 261 5990 , ,
222 7010 , , 183 7990 , , 141 8990 , , 97 9990 , ,
50 11000 , , 0 12000 , ,
RAM HAND

The mapping of output voltage to PWM is simple:

FILE NVM
: mV vptab @inter pwm ;
RAM HAND

On the console, typing eg. 7500 mV results in an output voltage of 7.53V, which is quite accurate (for being a hack).

Here are more examples:

  • 5000 mV -> 5.02V
  • 3700 mV -> 3.73V
  • 3300 mV -> 3.35V
  • 2800 mV -> 2.83V

Through the saturation feature of @inter the following works, too:

  • 15000 mV -> 12.00V
  • -10000 mV -> 0.03V

Especially at in a lower output voltage range, some drift is to be expected (results can be improved a bit with closed loop control, although there is no voltage reference source).

Usage as lab-test equipment

Professional (and certifiable) programmable power supplies are expensive, and for acceptance testing they are necessary. However, exploratory testing can greatly improve understanding failure modes, and improve the robustness of a product. The programmable power supply can be used to produce some of the test pulses defined in ISO 7637-2:2011. A log entry at Hackaday.io show-cases this possibility.

CN2596 Circuit Info

STM8S003F3 supply volatage: about 3.1V (LM317)

LED Display CL3631AH

As suggested in a [discussion on Hackaday] the 7S-LED display can be removed and the pads can be used as µC port breakout. Pin 6 (NC) can be used as a ground connection for an attached circuit board.

CL3631AH

Pin     LED      Connected to
1       E        PC5 / key "in"
2       D        PC6
3       DP       PC7
4       C        PD1
5       G        PD2 / key "out"
(6)     -
7       B        PD4
8       dig3     PA3
9       dig2     PD6
10      F        PA1
11      A        PA2
12      dig1     PD5

STM8S003F3P6

Pin	STM	 Connected to
1	PD4	 seg B
2	PD5	 dig 1
3	PD6	 dig 2
4	NRST     (ICP pin 3)
5	PA1	 seg F
6	PA2	 seg A
7	VSS	 GND (ICP pin 4)
8	Vcap	 Cap
9	VDD	 +3.1V (ICP pin 1)
10	PA3	 dig 3
11	PB5	 -
12	PB4	 led "out"
13	PC3	 led "In"
14	PC4	 Vin (analog)
15	PC5	 seg E / key "in"
16	PC6	 seg D
17	PC7	 seg DP
18      PD1/SWIM seg C (ICP pin 2)
19	PD2      seg G / key "out"
20	PD3	 Vout (analog)
Clone this wiki locally