Digital Benchtop Power Supply (3) : Part 3: The Software
Digital Benchtop Power Supply (3) : Part 3: The Software
Digital Benchtop
Power Supply (3)
part 3: the software
Design by R. Pagel
yes mark
button 8
BASIC Program button
no
The source code listing for the microcontroller
appears in Figure 2. The microcontroller pro- button ja
pressed
gram, written in PIC BASIC 1.3, can be down-
loaded from www.pic-basic.de. no 000166- 3 - 11
PIC BASIC allows microcontroller pro-
grams to be written quickly and easily. It also Figure 1. Flowchart for the microcontroller software.
32 Elektor 1/2002
POWERSUPPLY
‘———————————————————————————-
‘Scan buttons
‘Subroutines
Entry:
‘Depending on value in Callcounter, ButtonScan shifts one of
Accu = %00010000 ‘Bit 4 High (reset by pressed button) ‘eight bitpatterns to the pins of the HC164.
CV Callcounter, Buttonnumber ‘Only the button at the pin with the 0 on it
Call ButtonScan ‘can pull PB4 Low. PB4 then indicates if a button was pressed
Call ButtonScan or not,
Call ButtonScan ‘while Callcounter reveals the button identity
Call ButtonScan
Call ButtonScan
Call ButtonScan Sub ButtonScan
Call ButtonScan LookUp Callcounter, %11101111, %11011111, %10111111,
Call ButtonScan %01111111, %11111011, %11110111, %11111110, %11111101,
Branch Buttonnumber, Start, Button1, Button2, Button3, Button4, Bitpattern
Button5, Button6, Button7, Button8 EXPo B5, Bitpattern, 0 ‘only Button 0 of bit pattern can
pull B4 Low
Inc Callcounter
Button1: PBI %00010000 = Accu ‘read only bit 4 of Port B
If Uvalue > 240 Then Skip ‘Line for 2.5A If Accu <> 0 then Skip ‘skip when no button pressed
‘If Uvalue > 190 Then Skip ‘Line for 1A Buttonnumber = Callcounter ‘mark Button number
Uvalue = Uvalue + 10 EndSub
Goto Display_Uvalue
1/2002 Elektor 33
POWERSUPPLY
‘The auxiliary subroutine called Packer saves 8 bytes of pro- Packer: ;no repeating of lines; saves 8 bytes of program
gram memory memory
‘Packer calls machine code program SOSS°, which is contained in MOVWF FSR
the CALL SOSS°
‘PB compiler output, when the commands SerOut - #WordVar MOVF LWERT1,W
‘or LCD - #WordVar” was employed. EndAss
‘It returns the decimal number equivalent of a wörd variable.
‘It divides te value contained in HWERT2/R21 by the value from
the ‘RS232E controls data reception at the interface. Each time it
‘jump table SOTT° (also contained in compiler output). it called, the CTS line is pulled High for 1.5ms.
‘The value(!) in the FSR has to be the ADD value ‘If a character arrives via RxD within this period, the D-PSU
‘of the jump table (Pos. 5 = 0, 4 = 2, 3 = 4, 2 = 6, 1 = Rest goes into Receive mode i.e.
in R21). ‘subroutine Read is called. Next, 2 values with terminating CRs
‘LWERT1 contains the ASCII code (characters 0-9) as the result. ‘have to arrive at the interface before the controller is
allowed
Ass Format ‘to leave the subroutine
;format voltage
MOVF 24,W Ass RS232E
MOVWF HWERT2 CLRF 35 ;Clrf Y (= R35)
MOVF 23,W RS232:
MOVWF 21 BCF PB,2 ; CTS: ready to receive
MOVLW 2 BTFSS PB,0 ; RxT pin test
Call Packer Call Read
MOVWF 27 DECFSZ 35,F ;
MOVLW 4 GOTO RS232 ; repaet loop 256 times
Call Packer BSF PB,2 ; CTS: not ready to receive
MOVWF 28 EndAss
MOVLW 6
Call Packer
A/D converter
The command
ADW A2, 5380, 0, Meas_Voltage
carries out an analogue-to-digital
conversion and writes the measured
value into the variable Meas_Volt-
age (measured voltage). The scale
factor can be adjusted by changing
the value 5380 above. The circuit is,
however, designed so that this will
not normally be necessary.
Assembly code subroutines Figure 4. Power supply display on the PC’s monitor.
Under Format measured values plest place to put the CLRWDT instruction is
the assembly code subroutine For-
mat is called. This subroutine is immediately after the label Entry. power supply (Figure 4). Just as in reality, the
30 bytes long and uses some (PIC The following code is then shifted voltage and current set values can be
BASIC) subroutines, provided for the down by one location, which makes adjusted using the eight buttons. When the
use of other BASIC commands, to no difference in this case. mouse button is released the values are sent
format the measured values for dis- to the power supply. The set and actual val-
play. Using this trick a large amount The interface protocol ues are shown on a simulated LCD panel. If
of precious program memory can be The data packet that the power sup- you click in a region of the main program win-
saved. ply sends out over its interface is dow other than on the buttons, a settings
The eight-byte subroutine RS232E structured as follows: window appears. Here the version of the
is also written in assembler. It sets power supply (2.5 A or 1 A) and the COM
the CTS signal high and waits for a Duuuuuiiiii↵ port (1 to 4) used for data communication can
period to check if data are being sent be configured. If a mouse is connected to
from the PC. If so, the assembler First a D is sent, followed by five- COM1 it can happen that the program does
subroutine calls the BASIC subrou- digit values for voltage and current, not work correctly with COM3, but this is a
tine Read which is responsible for and finally a carriage return charac- common problem with PCs.
actually reading the data in. ter. The least-significant digit of the In the right-hand part of the settings win-
All the remaining parts of the pro- voltage value represents 10 mV, and dow the names of a log file and of a control
gram are written entirely in BASIC. that of the current value 1 mA. The file can be specified. A click of the mouse on
The compiled code size for the com- two values are thus given to a reso- the adjacent `Start’ button and a file is either
plete program is either 1009 bytes or lution ten times higher than that read or written: the file contains the dis-
1021 bytes (for the 2.5 A and 1 A ver- shown on the LCD panel. The lead- played readings along with a time stamp
sions respectively), and so just fits ing digit of the voltage and current indicating when they changed (in the case of
into the program memory of the values is always zero. a log file), or when they are to be changed (in
PIC16F84. The program lines that When set values are sent to the the case of a ready-prepared control file). In
need to be changed between the power supply, both voltage and cur- the simplest case the control file can be cre-
two versions of the power supply are rent settings must be sent, one ated from a log file by modifying the time
marked in the BASIC program list- immediately after the other. In both stamps.
ing. cases up to 3 digits can be sent. The following example one-line data
record shows the format used for the log and
If it is desired to enable the watch- uuu↵ iii↵ control files:
dog timer in the microcontroller, the
configuration word in the assembly After each value a non-digit charac- #2000-08-20
output must be changed as follows: ter (for example a carriage return 14:35:53#,”04.9V”,”0.97A”
character) must be sent. For either
CONFIG B’11111111110101’ version of the power supply a volt- Between the two hash symbols (‘#’) we have
age value of 20 V must be sent as the date (in international format) and the time
Also, a CLRWDT instruction must be 200. For a current of 1 A, a value of when the indicated change occurred or is to
inserted at one point in the code, in 100 should be sent in the case of the occur. Within the record the time stamp and
the main loop and in the push-button larger model, 200 in the case of the the two electrical values are separated from
scanning loop. The latter loop runs smaller model. one another by commas. This allows for the
in just over 500 ms and the main processing and, for example, the graphical
loop runs in about 780 ms. With the presentation of the contents of the file using
values set in the Option register on Visual BASIC program a spreadsheet program.
power-up, a watchdog reset will The control program, written espe- (000166-3)
occur after 2.3 s. This is enough time cially for this project, runs under
for both loops (indeed, even half the Windows 95 or 98. Its control inter-
time would be adequate). The sim- face resembles the front panel of the