0% found this document useful (0 votes)
68 views4 pages

Digital Benchtop Power Supply (3) : Part 3: The Software

The digital benchtop power supply is controlled by a microcontroller programmed in PIC BASIC. The microcontroller program runs in a continuous loop, measuring the voltage and current values and displaying them. It can also adjust the target voltage and current values up or down when the corresponding buttons are pressed, within the permitted ranges. The program flow is shown in a flowchart, and the PIC BASIC source code for the microcontroller is provided.

Uploaded by

Schunda
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views4 pages

Digital Benchtop Power Supply (3) : Part 3: The Software

The digital benchtop power supply is controlled by a microcontroller programmed in PIC BASIC. The microcontroller program runs in a continuous loop, measuring the voltage and current values and displaying them. It can also adjust the target voltage and current values up or down when the corresponding buttons are pressed, within the permitted ranges. The program flow is shown in a flowchart, and the PIC BASIC source code for the microcontroller is provided.

Uploaded by

Schunda
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

POWERSUPPLY

Digital Benchtop
Power Supply (3)
part 3: the software
Design by R. Pagel

The digital benchtop power supply is controlled by a microcontroller


programmed in PIC BASIC, while a Visual BASIC program is responsible
for producing the control panel display on a PC.
Figure 1 shows the flowchart of the program
500 ms display
in the microcontroller. At start-up a brief ini- pause target value
tialisation sequence runs, which resets the start

set values to zero and configures some of the


microcontroller’s pins. The next step, the scan set target
buttons value again
measurement of the actual voltage and cur- initialisation
rent values, already forms part of the main
yes
program loop. All the remaining parts of the button 1
mark
button
program follow sequentially in this loop. One measure voltage
no
and current
branch that can occur is when the push-but-
tons are being read. The procedure for read- button 2
yes mark
button
ing the buttons is indeed as cumbersome as it format
measured no
(unavoidably) appears from the flowchart. values
The idea is to read each button in turn and, yes mark
button 3
when one is found that is pressed, the micro- button
display
no
controller stores the corresponding key code. measured
values
Finally, under `button pressed?’ the micro- yes mark
button 4
controller checks whether any button was in button
output measured no
fact pressed. If so, a branch is taken to code values via RS232
which increases or decreases the appropriate yes mark
button 5
set value, as long as the value remains within button
if possible read
the permitted range. The new set point is target values
no

then displayed. A half-second delay follows, via RS232


yes mark
before the push-buttons are scanned again. button 6
button
This provides an auto-repeat function. If no output target no

button is being pressed, the program values via DAC


yes mark
branches back to the top of the main loop to button 7 button
measure the voltage and current again. no

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

‘D-PSU 25V, 2.5A or 20V, 1A Button3:


If Uvalue < 10 Then Skip
‘attention: modifications to the program require that register Uvalue = Uvalue - 10
numbers Goto Display_Uvalue
‘in the assembler subroutines are checked for changes!!!
Button4:
‘———————————————————————————- If Ivalue < 10 Then Skip
‘declaring the variables Ivalue = Ivalue - 10
VarB Lh1, Lh2, Lh3, Lh5, Lh6, Lh7, Uvalue, Ivalue, y Goto Display_Ivalue
VarB Buttonnumber, Accu, Callcounter, Bitpattern
VarW Meas_Voltage, Meas_Current Button5:
If Uvalue > 249 Then Skip ‘Line for 2,5A
‘———————————————————————————- ‘If Uvalue > 199 Then Skip ‘Line for 1A
‘Main program Inc Uvalue
Init: Goto Display_Uvalue
CV Uvalue, Ivalue ‘set to 0 on each start’
Low A3 ‘ADC output at 0 Button6:
High B2 ‘CTS: not ready to receive If Ivalue > 249 Then Skip ‘Line for 2.5A
‘If Ivalue > 198 Then Skip 2 ‘Line for 1A
Start: Inc Ivalue
‘Measure voltage and current ‘Inc Ivalue ‘Line for 1A (omit for 2.5A version)
‘Using value 5??? allows ADC scale factor to be adjusted Goto Display_Ivalue
‘ + - 20 equals approx. 1 digit
Low A4 ‘Mux to U Button7:
ADW A2, 5380, 0, Meas_Voltage ‘Voltage measurement If Uvalue < 1 Then Skip
Meas_Voltage = Meas_Voltage Shr 1 ‘equals / 2 Dec Uvalue
High A4 ‘Mux to I Goto Display_Uvalue
ADW A2, 5380, 0, Meas_Current ‘Current measurement
Meas_Current = Meas_Current Shr 1 ‘ equals / 2 ‘line for Button8:
2.5A If Ivalue < 1 Then Skip ‘Line for 2.5A
‘Meas_Current = Meas_Current Shr 2 ‘ equals / 4 ‘line for ‘If Ivalue < 2 Then Skip 2 ‘Line for 1A
1A Dec Ivalue
‘Dec Ivalue ‘Line for 1A (omit for 2.5A version)
‘Format measured values
Call Format
Display_Ivalue:
‘Display measured values on LCD ‘y = Ivalue Shr 1 ‘equals / 2 ‘Line for 1A (omit for 2.5A ver-
LCD B5, “ “, Lh1, Lh2, “,”, Lh3, “V “, Lh5, “,”, Lh6, Lh7, sion)
“A “ LCD B5, “ “, #Ivalue, “0mA” ‘Line for 2.5A
‘LCD B5, “ “, #y, “0mA” ‘Line for 1A
‘Send measured values over RS232 Pause 500
SerOut B3, 9600, “D”, #Meas_Voltage, #Meas_Current, 13 Goto Entry

‘Allows a new target value to be received over RS232


Call RS232E Display_Uvalue:
LCD B5, “ “, #Uvalue, “00mV”
‘Send target values over DAC Pause 500
PWM A1, Uvalue, 64 ‘Set voltage (200 = 20V) Goto Entry
PWM A0, Ivalue, 64 ‘Set current (200 = 2A or 200 = 1A)

‘———————————————————————————-
‘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

Button2: ‘The Basic subroutine Read is called from


If Ivalue > 240 Then Skip ‘Line for 2,5A ‘assembler subroutine RS232E
‘If Ivalue > 190 Then Skip ‘Line for 1A
Ivalue = Ivalue + 10 Sub Read
Goto Display_Ivalue SerIn B0, 9600, #Uvalue, #Ivalue
Uvalue = Uvalue Min 250 ‘limit to 25 Volt ‘Line

Figure 2. Listing in PIC BASIC.

1/2002 Elektor 33
POWERSUPPLY

for 2.5A MOVWF 29


‘Uvalue = Uvalue Min 200 ‘limit to 20 Volt ‘Line ;format current
for 1A MOVF 26,W
Ivalue = Ivalue Min 250 ‘limit to 2.5 Ampere MOVWF HWERT2
‘Line for 2,5A MOVF 25,W
‘Ivalue = Ivalue Min 200 ‘limit to 1 Ampere ‘Line MOVWF 21
for 1A MOVLW 2
Y = 1 ‘Leave loop immediately Call Packer
Endsub MOVWF 30
MOVLW 4
Call Packer
‘Assembler sub-routine Format employs the already available MOVWF 31
‘Resources for PB. It load the number registers Lh1-Lh8 with MOVLW 6
the Call Packer
‘ASCII values for Numbers 0-9 according to the values in the MOVWF 32
‘variables Meas_Voltage and Meas_Current. Return

‘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

makes compiling the program and program-


ming it into a chip easy. Further information
on PIC BASIC, as well as the most up-to-date
version of the program, can be found on the
Internet at www.pic-basic.de. At the time
of writing this article, the information on PIC
Basic is only available in German. We hope
that Mr. Pagel will eventually produce Eng-
lish translations.
Figure 3 shows in-system programming of
the 1 A power supply using the PIC BASIC
programmer.
First all the variables used in the program
are declared. There are 13 byte-wide vari-
ables and two word-wide variables, occupying
a total of 17 bytes of the microcontroller’s
RAM (and a further twelve bytes are reserved
by PIC BASIC as a scratch area). Then follows
the first part of the program: this is the part
indicated in the flowchart by `initialisation’.
The label Start marks the entry point for the
main loop. The program is so thoroughly com-
mented that a detailed description is not nec-
essary here. A few remarks are, however, in
order: Figure 3. In-system programming of the power supply microcontroller.

34 Elektor Electronics 1/2002


POWERSUPPLY

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

1/2002 Elektor Electronics 35

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy