Sie sind auf Seite 1von 25

Programmable DC Power Supply

Flash Innovation Contest 2003 Project F2026

F2026

Flash Innovation Contest 2003

Table of Contents
1. Project overview...............................................................................................................................3 2. Hardware..........................................................................................................................................5 2.1 CPU ...........................................................................................................................................5 2.2 IMonitor ....................................................................................................................................6 2.3 Protection...................................................................................................................................7 2.4 VMonitor ..................................................................................................................................8 2.5 Vout.........................................................................................................................................10 2.6 LCD ........................................................................................................................................11 2.7 InputProcessor..........................................................................................................................12 2.8 System Bus...............................................................................................................................13 3. Software..........................................................................................................................................14 3.1 Overview..................................................................................................................................14 3.2 OS............................................................................................................................................14 3.3 PowerSupplyTask ...................................................................................................................15 3.4 VMonitorTask..........................................................................................................................17 3.5 IMonitorTask...........................................................................................................................18 3.6 LCDTask .................................................................................................................................18 3.6 InputProcessor..........................................................................................................................20 3.7 Vout module............................................................................................................................21 3.8 SPI Bus....................................................................................................................................22 3.9 EEPROM.................................................................................................................................22 4. Operation........................................................................................................................................24 5. References......................................................................................................................................25

F2026

Flash Innovation Contest 2003

1. Project overview
A power supply is one of the basic instruments in any electronic lab, be it in a company or at home (for a hobbyist as in my case). And since I was tired of my classic transformer regulator lots of wires - 5V power supply, I decided to take the challenge and design something more like a real tool. Priorities in this enterprise were complexity versus necessity, and price. Featues: output voltage: 0.6 to 20 V, resolution 8mV output current: 0 to 2.5 A, resolution 10mA short-circuit protection adjustable current limit (5ms response time) output ripple: 5mVpp max metering display: 16x2 LCD with backlight voltmeter range: 0.650 to 20.000V, resolution 2mV ammeter range: 0.065 to 2.500A, resolution 10mA power requirements: 100V, 50Hz dimensions (H x W x D): 140 x 120 x 220 user friendlines automatically adjustable setting speed simple and intuitive user interface A few explanations are required. 1. The current resolution of 10mA might seem too coarse. It is and it can be improved if you really need to, but for all the projects I worked on until now it is more than enough. Its purpose is just to give a rough idea about the load current and, the most important, to provide a reasonable current limit. Generally the load current can not be predicted in advance very accurately. Moreover a load will have variable current consumption depending on what it is doing at a certain time. 2. The lower limit for voltage is 0.6V and not 0. Well, this is because some of the op amp used. They are not rail to rail, but I can live with this. I can not think to any useful load working with 0.6V. Concerning the current limit, it has a usable range of 65 to 2500mA, which I consider resonable. 3. The voltage resolution of 8mV should be enough for most applications. 4. The only serious issue could be the response time of the current limit 5 ms. I agree that some sensitive devices could get smoked in 5ms and there are at least 2 available options in this regard. Either slightly update the code and obtain a 3ms response time, or slightly change both the code and the hardware and get a few microseconds response time.
3

F2026

Flash Innovation Contest 2003

EEPROM

IMonitor

Protection

System Bus CPU

HC908QT4

VMonitor

Vout

LCD

Input Processor

Fig. 1 Block diagram

The main block is the CPU. It is the interface between the hardware blocks and the software. The software is responsible for coordinating all the other blocks, sharing resources between them, managing system states etc. The communication with the subsystems is done through the system bus, which is in fact nothing more that the processor's I/O lines. Some of these lines function as a SPI bus, described in section 2.8. Most of them have more than one functionality, but details are provided in each block's section. The names of the building blocks should be suggestive for their purpose. Few of them require further details. The EEPROM is responsible with retaining last settings when the supply is turned off. It is implemented in the FLASH memory of the CPU. Protection block disconnects the output in case the load current exceeds the preset limit or a short occurs. Input Processor decodes user input: button press or knob rotate. The following paragraphs describe in detail each of the building blocks.

F2026

Flash Innovation Contest 2003

2. Hardware
2.1 CPU

Fig. 2 CPU block

All the logic is powered from a 5V regulated supply. This is done using the low dropout regulator LM2936 (IC3). This type of regulator has very good characteristics and this is important since the ADC uses it as reference. After development and testing of the prototype using the provided development board, the CPU was relocated to a new board specially designed for this project. The connector CON1 and the push button SW1 allow for connecting this new board to the original one and thus make possible upgrade of the software. The I/O lines form the system bus, which is described in section 2.8.

F2026

Flash Innovation Contest 2003

2.2 IMonitor
This block is responsible with monitoring the load current and informing the CPU about any faults.

Fig. 2 IMonitor block

The current is sensed through R16 (0.1ohm/1%) placed on the high side. This means the measured current will also include the current drawn by LM338 (about 10mA). However, this will be subtracted in software. Moreover a precision of 10mA when measuring the current is satisfactory for this application. The goal is to protect the load and not to measure the current with a micro amp resolution. The current drawn by the load is in range 0 2.5A. This will yield a voltage drop across R16 of approx. 0 250mV in the presence of a 28V common mode voltage. This signal is measured by the U2 (AD8200). From its datasheet:AD8200 is a single-supply difference amplifier for amplifying and low-pass filtering small differential voltages in the presence of a large common-mode voltage. Internally it has one amplifier with gain of 10 followed by a second amplifier with gain of 2. The connection between these 2 internal amplifiers is done through pins A1 and A2 (and one 100k resistor) allowing thus to externally implement a low pass filter (C11). In this project the voltage drop across R16 is amplified 20 times and is send to the ADC through IC4A configured as a buffer. IC4A buffer is required because AD8200 is not able
6

F2026

Flash Innovation Contest 2003

to drive the line A5 (fan-in too high). Iload = VR16/R16 ILM338 = VR16 * 10 - ILM338 VA5 = (VR16 * 10) * 2 = 0 .. 5V The final multiplication by 2 scales the input range of 0 2.5V to 0 5V, which is equivalent with improving ADC's resolution from approx. 19.5mV to 9.7mV. So, the current is measured with a resolution of about 10mA. The current through LM338 is almost constant. The software considers it as an offset and allows for calibration (set the value that will be subtracted from the output).

2.3 Protection
The role of this block is to disconnect the load in case of a short-circuit or a current bigger than a preset value.

Fig. 3 Protection block It is build from a power MOSFET used as a controlled switch and a driver for it. IC2A is responsible with this task. According to superposition theorem: VGS = (VOUT/2)*2 + (VCMD/2)*2 = VOUT + VCMD, where VCMD is either 0V or 5V.

F2026

Flash Innovation Contest 2003

The type of the power MOSFET is not critical. Any power MOSFET will work if it can withstand at least 5V gate-source voltage. Since it is a MOSFET transistor, its rDS resistance is in the range of few mili-ohms, so it does not need a heat sink. This block is controlled directly by the pin A0 of the microcontroller. Immediately after initialization, A0 is set to 1 and the output is enabled. Every 5ms ImonitorTask (this block's mirror in software) checks the current through the load and, if this exceeds the preset limit, immediately sets A0 to 0 disconnecting thus the load. The system enters then into ALARM state from which only a RESET will allow exit. This protection is doubled by the short-circuit protection inside LM338. Remark: Apparently, the protection could be implemented more simple: just set the output voltage to 0V in case of a fault. Unfortunately it is very difficult to set the output voltage to exactly 0V. Moreover this solution will have a longer response time.

2.4 VMonitor
VMonitor continuously measures the output voltage.

Fig. 4 VMonitor block

MCP42100 is a dual digital potentiometer of 100kohms, 8 bits resolution. This block uses only half of it, designated as DP2. R18 and C8 form a reset circuit so that the
8

F2026

Flash Innovation Contest 2003

potentiometer always starts from a known initial state. The wiper voltage (between 0 and 5V) is amplified 5 times by IC2B and then it is extracted from the output voltage by the U6 (AD8200). The difference is amplified 10 times (5 * 2 because of R5) and low pass filtered (C10). VA4 = (VOUT VDP2 * 5) * 10 VOUT = VA4 / 10 + VDP2 * 5 For obtaining the best possible resolution, the difference in the above equation should be in the range 0 0.5V. The software controlling this block (VMonitorTask) continuously tries to bring the difference in range and then it takes a measurement. Because the range 0 0.5V is scaled to 0 5V, the resolution of the measurements is approx. 2mV over the entire output range 0 20V! This is equivalent with using a 14 bit ADC!!! Actually this solution is better than using a 14 bit ADC because it is much less sensitive to noise. In case of a 14 bit ADC, the ADC step is 305 V if the reference voltage is 5V.

F2026

Flash Innovation Contest 2003

2.5 Vout
This block is responsible with setting the output voltage.

Fig. 5 Vout block

The power element is an integrated regulator LM338. It is mounted on a heat sink (see photos), and in this schematic is only represented by the connector CON3. Also, the rectifier bridge is mounted on a heat sink and is connected through the connector CON4. The transformer provides approx. 20VAC through CON2, which by rectifying gives about 28V DC. C17 filters this voltage. R20 discharges C17 when the power supply is turned off. The 2 diodes 1N4004 protect the regulator LM338 from the C15, C16 discharge when the power is turned off. LM338 has a reference voltage of 1.24V typical, which normally means it is able to provide an output voltage ranging from 1.2 to 32V. In order to obtain an output voltage starting with 0V, its adjustment pin must be driven to 1.2V below the GND potential. U3 (TC1121) is a charge pump voltage converter. It is powered at 5V and provides at the
10

F2026

Flash Innovation Contest 2003

output -5V. And it is a real trouble maker ! Its operating frequency of 200KHz is picked up by its neighbors. That is the reason for using C18, C19 and C20 besides the other decoupling capacitors. However, it provides the negative supply for IC1 (LM358). The positive supply for IC1 is obtained from 28V from which D1 subtracts approx. 5.6V Thus IC1 sees approx. 28V between its power terminals (max. allowed is 32V). MCP42100 (U4) is a dual digital potentiometer with 8 bits resolution. Its lower half, PA0PB0-PW0 is designated as DP0. The second half, PA1-PB1-PW1, is designated as DP1. R15 is set so that DP0 sees 0.5V at input (this is equivalent to 2mV/step). Thus, VADJ, the voltage at the output of IC1A is: VADJ = VDP1 * 5 VDP0 * 4 This output voltage has a resolution of approx. 8mV due to DP0. The software operating this block is Vout module. It drives DP1 in steps of approx. 0.4V and DP0 in steps of 2mV. Thus, the output voltage has no discontinuities over the entire output range 0 20V.

2.6 LCD
The LCD display used is a 2 row 16 character module (SC1602BSLB) with backlight.

Fig. 6 LCD block

In order to minimize the number of I/O pins, IC1 (74HC164) is used. It is a shift register of
11

F2026

Flash Innovation Contest 2003

8 bits. Also, the software never reads back data from LCD and that is why R/-W is connected to GND. The disadvantage is that always, for any operation of the LCD, the maximum time specified in the datasheet is allocated. The algorithm for sending some data to LCD is very simple: load data into the shift register set the appropriate value for RS line enable LCD using E line and thus load data disable E line This way, only 3 I/O lines of the CPU are necessary to drive the LCD, and 2 of them can be shared with other subsystems. For the backlight R1 is used. The current required to illuminate the LCD is set to about 60mA.

2.7 InputProcessor
This block is responsible with reading the user's input.

Fig. 7 InputProcessor block

The low number of I/O pins imposes the usage of a multiplexing scheme. The power supply has: a RESET button used to escape the ALARM state, or to leave a menu a SET button for settings a rotary encoder for adjusting values and navigating menus
12

F2026

Flash Innovation Contest 2003

A2 pin of the CPU is used for reading the state of these buttons. 74HC164 register is shared with the LCD module. When the InputProcessorTask (the image in software of this block) runs, it sends appropriate codes to the shift register so that only one of IC2A, IC2B, IC2D is connected to A2 line. This way it is possible to read all the buttons.

2.8 System Bus


IMonitor VMonitor Vout Protection LCD Input Processor

A0 A1 A2 A3 A4 A5
Fig. 8 System bus

The CPU I/O lines represent the system bus. They software uses a multiplexing scheme so that each building block is allowed to access the bus without conflicting with others. I/O line A0 A1 A2 A3 A4 A5 Function Command protection LCD E (enable) line InputProcessor read buttons CS line on the SPI bus SCK line on the SPI bus and ADC input for voltage measurement SDA line on SPI bus and ADC input for current measurement
Table 2 System bus lines

13

F2026

Flash Innovation Contest 2003

3. Software
3.1 Overview
The brains of this project is the software. It is responsible with managing system states, managing resources and the interface with the user. In doing so, there is a software correspondent for each hardware block. Their interaction is managed by a simple preemptive-cooperating operating system.

3.2 OS
This project is powered by a simple preemptive-cooperating operating system. It is a long name but the software behind it really does all the name says: resource sharing tasks management priorities In this project there are 5 tasks: PowerSupplyTask VMonitorTask IMonitorTask LCDTask InputProcessor IMonitorTask has the highest priority and it is allowed to interrupt any other task. Its job is to continuously check the current through load and, in case this exceeds a preset limit, to disable output and to signal an error condition. It is driven by the timer interrupt routine. All the other tasks have the same priority. They are managed by a cooperative scheduler and this ensures there are no resource conflicts (I/O lines, global variables).
for(;;) { PowerSupplyTaskRun(); VMonitorTaskRun(); LCDTaskRun(); InputProcessorRun(); } //run once through all tasks //update display 4 times/s

Though, IMonitorTask may interrupt each one of the other tasks and this could cause problems. To avoid such situation, there are available 2 macros:
Cpu_DisableInt(); Cpu_EnableInt(); // disable all interrupts // enable interrupts

Any critical section is delimited by these macros. The files related to the operating system are: Events.C containing timer interrupt routine nitro_power.C containing initialization of the system and the scheduler

14

F2026

Flash Innovation Contest 2003

3.3 PowerSupplyTask
This task represents the entire system at the software level. Its job is to transit the power supply through different states according to the diagram below:

Fig. 9 System states K = knob event (UP or DOWN) E = error condition (current through load too high) S = set key pressed R = reset key pressed

On power on, the system is initialized by the main function and transits to RUNNING state. For any state except the ALARM, an error condition detected by the IMonitorTask will determine the system to transit to ALARM state ignoring the current operation. From ALARM state, only a R event will allow exit and will transit the system to RUNNING state. For any MENU or submenu states, R will transit the system back to the RUNNING state ignoring the current operation. The settings are not updated in this case. A knob event in RUNNING state will determine transition to MENU state. Further knob events make possible to scroll through menu options. An S event will transit the system to
15

F2026

Flash Innovation Contest 2003

the selected submenu. In any submenu, knob events allow changing some setting's value. A second S event will update the value in the system's EEPROM and will return to RUNNING state. PowerSupplyTask is implemented as a function, PowerSupplyTaskRun, that is called once for each passing through the for loop in scheduler. What it does is to check for a new message (from user or system) since only a message can trigger some action. In case there is no such message/event, the function will return peacefully. PowerSupplyTask makes use of the following variables: userInputMessage it is a buffer into which other subsystems put messages to be processed system_state keeps the system state vref reference voltage used by the ADC (it is in fact the CPU power supply voltage). Resolution is in mV. stepA and stepB see explanations below. menu_option helps in traversing the menu and selecting an option step see explanations below. Ioff the offset value to be subtracted from the computed Iout in order to cancel the current drawn by LM338 Vout_reading the measured output voltage, updated periodically by the VMonitorTask. and stepB require special treatment. In order to save memory and processing power, all the computations are done using integer arithmetic. However this will introduce some errors from rounding, integer division etc. In order to minimize these errors, the precision of the ADC quantization step used in computations must be increased. An example will clarify this:
Variables stepA

The ADC module has 8 bits resolution over the 0 to 5V input range. Without stepA and stepB and using integer arithmetic: ADC step = 5V/256 = 19mV For a value of 200 returned by the ADC after measuring some signal it results: Vsignal = 200*19 = 3.800V Variables stepA and stepB are defined as:
stepA = (unsigned char)((vref * 10)/256); stepB = (unsigned char)((((vref * 10)%256)*10)/256);

This is equivalent with specifying the ADC step in 10microVolts increments/units! For the case above this will yield: stepA = 50V/256 = 195 stepB = ((50V mod 256)*10)/256 = 3

16

F2026

Flash Innovation Contest 2003

Vsignal

= (200*stepA)/10 + (200*stepB)/100 = (200*195)/10 + (200*3)/100 = 3.900 + 6 = 3.906V

The difference is significant ! And in case of some subsystems (VMonitor for instance) this difference would be even larger!!! The step variable keeps a value (1 or 10) and is initialized by InputProcessor task. Some values (voltage, current etc.) need to be adjusted from time to time. In case of the voltage, resolution is 8mV. Changing the output voltage from 1V to 20V in steps of 8mV would require approx. 2375 knob UP events. A complete turn of the knob can trigger at most 24 events!!! The user is not a probably a proficient high speed knob turner and surely this is not his purpose. Intuitively, when the desired output voltage is far away from the actual output voltage, any user will tend to rotate the knob faster. When getting close to target voltage, intuitively the user rotates the knob slower. Here is where step variable cames into play. The InputProcessor task determines the knob speed and sets this variable to an appropriate value. If the speed is high, step will have a large value and that value is used by the PowerSuplyTask in doing settings. Thus, the above potential 100 knob turns are reduced to only 10. This is automatically adjustable setting speed from the feature list. The files related to the PowerSupplyTask are: PowerSupplyTask.c PowerSuplyTask.h containing

3.4 VMonitorTask
VMonitorTask is the software module responsible with controlling VMonitor hardware block as described in section 2.4. It continuously tries to bring the difference seen by the ADC in range by adjusting the DP2's output voltage. These adjustments are made in steps of approx.: (3 * 19mV) * 5 = 285mV. This is fast enough so that a trip over the entire range takes 255 / 3 = 85 iterations, and it is fine enough so that always the difference between the output voltage and DP2 voltage can be brought in range. The algorithm is very simple: * enter critical section * get ADC lines * take measurement * exit critical section * if (in range) * update Vout_reading # return * else * try to bring in range by updating DP2 value # return #
17

F2026

Flash Innovation Contest 2003

A few remarks concerning the code: the variable Vout_reading is an int representing the output voltage in mV in hardware, DP2 is connected the the SPI bus, and it is cascaded after DP1-DP0 (U4) in order to save an I/O line. VMonitorTask related files: VmonitorTask.c VmonitorTask.h

3.5 IMonitorTask
IMonitorTask works closely with IMonitor hardware block described in section 2.2. This task has the highest priority and runs once at every 5ms. At every iteration, IMonitorTask measures the current through load and in case this is higher than a preset limit (i_limit variable), disables the output and sends an ALARM message into the system. The files related to this task are: IMonitorTask.c IMonitorTask.h

3.6 LCDTask
This task is responsible with updating the display. In doing so it works closely with the PowerSuplyTask since the messages printed out depend on the system state. Even if it is the largest software module in this project, its functioning is simple: wait 250ms update the display start over In counting time, lcd_counter variable is used. It is updated by the timer irq until it is 0. When this happens, LCDTask knows it has to refresh the display. It also reinits lcd_counter variable. In order to minimize the ROM usage, the fragments of code called often were grouped into small functions. Examples are: ComputeI, LCDSendByte functions.
toChar function might need a little attention. It converts an unsigned decimal integer to a string using the following formula: abcde = a*10000 + b*1000 + c*100 + d*10 + e = (((a*10 + b)*10 + c)*10 + d)*10 + e 18

F2026

Flash Innovation Contest 2003

This way, the algorithm becomes very simple and a huge reduction is obtained in ROM usage. After the conversion ends, the first leading 0 is removed if present 00.500V wouldn't be too nice. And finally, the first 2 digits are shifted in order to insert the decimal point. A nice trick is used to clear the display before updating it. The reason for doing so is that using the real command for clearing produces some unwanted effects: the flickering is much more visible and annoying sometimes the first character from a message gets eated - that could be only my display, but being the only one available, I had to solve the problem somehow. The idea is that any update will print out some message and this message will cover at least the first half of the LCD row. So, it makes sense to clear only the second half. This is done by printing space characters in the second half of the row. As positive side effects, the time used for erasing is minimized, and the flickering is reduced most of the time only the last digit will change. The files related to LCDTask are: LCDTask.c LCDTask.h

19

F2026

Flash Innovation Contest 2003

3.6 InputProcessor
This task works closely with InputProcessor hardware block and is responsible for processing the user's input. Its functioning is based on the following state diagram:

Fig. 10 InputProcessor state diagram

InputProcessor task starts from the IDLE state. At each iteration it reads the buttons and knob states. The knob has priority in decoding, so if both the knob is turned and some button pressed, only the knob event will be recognized. When a key event (button pressed) or knob event is recognized, this task will transit to either POSTDELAYKEY state or POSTDELAYKNOB. The former will introduce a delay of about 0.5s so that a longer key press will not flood the system with messages. The latter introduces a small delay of about 10ms before transiting to the next state. This is required to correctly decode the knob events. WAIT_11 state (or WAIT_SYNC as it appears in code) waits until the knob gets between clicks - the rotary encoder used is quadrature detented type. The variable time_counter is updated by the timer irq and is used in measuring the time between the knob events. If this time is shorter than 120ms, InputProcessor considers the
20

F2026

Flash Innovation Contest 2003

user is rotating the knob fast and consequently the variable step is set to value 10 (recall it is used by PowersupplyTask in adjustments). Otherwise, the step variable is initialized with the value 1. A remark: at each iteration, InputProcessor, before doing any input reading, checks the system message queue:
if (userInputMessage != I_ALARM) ...

The system message queue has a depth of only 1 message and if not carefully handled some messages could be overwritten before being processed. The files related to InputProcessor task are: InputProcessor.c InputProcessor.h

3.7 Vout module


This software module is in fact a group of functions called during the initialization of the system, and during functioning by the PowersupplyTask, when the output voltage is changed. The hardware correspondent of this block is Vout module described in section 2.5. Its functioning is based on the equation: Vout = 1.24V + VADJ = 1.24V + VDP1 * 5 VDP0 * 4 However, this is in theory because the op amps used will introduce some offset errors and also the reference 1.24V could have a slightly different value. That is why a separate measurement block is required. In adjusting the output voltage, DP0 is incremented/decremented in steps of 2mV, while DP1 in steps of 0.4V. This way the output voltage will cover the range 0.6 20V without any discontinuities. The array v_steps keeps the values necessary to adjust DP1 in steps of 0.4V. The files related to Vout module are: Vout.c Vout.h

21

F2026

Flash Innovation Contest 2003

3.8 SPI Bus


2 of the CPU lines are used to communicate to some SPI peripherals (digital potentiometers) and this software module is responsible with controlling them. It is implemented as a function that sends a byte over the bus. Also 2 macros were defined: SPIBus_enable, SPIBus_disable. These macros are required because the lines A4 and A5 (clock and data) are shared with the ADC. The files related to SPI bus are: SPIBus.c SPIBus.h

3.9 EEPROM
For this application a few EEPROM locations are required in order to keep last settings when the power supply is turned off. There are required 6 bytes for critical values to be stored: 2 bytes for Vout 1 byte for current limit 2 bytes for Vref 1 byte for Ioffset The FLASH memory of QT4 is organized in pages of 64 bytes. For implementing an EEPROM memory in this application one such page is used. It is the first available in the user program area. To simplify explanations, it is best to see a 64 bytes memory page as 8 groups of 8 bytes each, as in the figure below: 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1A 0x1B 0x1C 0x1D 0x1E 0x1F 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2A 0x2B 0x2C 0x2D 0x2E 0x2F 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3A 0x3B 0x3C 0x3D 0x3E 0x3F
Fig. 11 - EEPROM organization

The number inside each cell is the offset address of the corresponding byte relative to the beginning of the page.
22

F2026

Flash Innovation Contest 2003

In the following paragraphs a small group of 8 bytes will be referred to as a block. After erasure a memory page will be written block by block (8 times in this case) until it is full. Then it will be erased again. Thus the endurance is increased from about 10000 erase cycles to 80000. A block has the following structure: Offset inside block 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 Meaning Block written flag Value of DP0 Value of DP1 Imax Vref high byte Vref low byte Ioffset reserved

The reason for defining a block as an 8 bytes group is to keep things as simple as possible and to have a small reserve in case of a further development. The requirements for the EEPROM subsystem in this application are very simple: retrieve a previously saved value and update a value. In both cases it is required to locate the last written block. For the former it will contain the value requested, for the latter it will help in deciding the next available block for writing into. It makes sense to have a routine to locate the last written block and that is EEPROM_findLast. The update function requires a way to write new values and from time to time a method to erase a memory page. These functionalities are provided by the 2 routines ERARNGE and PRGRNGE from the monitor.
#define ERARNGE #define PRGRNGE 0x2806 0x2809 // start address of the erase routine // address of the program routine

These routines require a special buffer area in RAM from which they take the values to be written, address of the memory page, etc. The start address of this buffer is fixed. It is declared as a struct:
struct { unsigned char CTRLBYTE; // page erase or mass erase for ERARNGE unsigned char CPUSPD; // CPU clock in 0.25 MHz increments (approx) unsigned int LADDR; // last location to be written by PRGRNGE unsigned char DATA[8]; // EEPROM block has 8 bytes } EEBUFFER@0x0088; // put this at RAM+0x08 as requested by ROM routines

23

F2026

Flash Innovation Contest 2003

The update function is based on the following algorithm: * find last written block * copy values to RAM buffer * put into RAM buffer the value to be updated * if there are no more empty blocks in the page * erase page * determine next empty block * write RAM buffer into FLASH # A few remarks about this function: the VREF const was introduced and used in order to simplify updating of the Vref, which is an int value. PRGRNGE is a critical subroutine and is not recommended to interrupt it. It won't blow the power supply but it will probably drive crazy any user attempting to change settings. That is why all the interrupts are disabled before calling it, and they are enabled afterward. As a final remark, C makes possible an implementation very elegant and easy to follow. It is also very easy to extend it with new functionalities. For instance a set of 3 EEPROM memories could be implemented so that 3 different voltage/current settings could be stored and retrieved. The files related to the EEPROM are: EEPROM.c EEPROM.h

4. Operation
This power supply was designed to be as user friendly as possible. The interface with the user is very simple and comprises 2 push buttons, one knob (rotary encoder) and one display. The knob allows to scroll through the menus and to change some settings. SET button allows to select some menu or to update a setting's value into internal EEPROM. RESET button allows to exit any menu without updating any settings into EEPROM. If the value of a setting was changed before RESET was pressed, the change is lost after RESET. Also RESET button allows to recover from ALARM state. Before using the power supply for the first time, 2 calibrations must be made: reference voltage offset current The CalibrateVref menu allows to calibrate the reference voltage. This is required
24

F2026

Flash Innovation Contest 2003

because the ADC uses as reference a voltage regulator, which is also used as a power supply for the logic. The procedure is very simple and it must be done only once: measure VDD set new value this can be set in the range 4.500V 5.500V with a resolution of 1mV. The more exactly this value is specified, the more precise the measurements will be (Vout, Imax etc). The second calibration refers to an offset current. This is introduced mainly by the LM338 regulator since the current is measured on the high-side. The Calibrate Ioff menu allows for this calibration. The procedure is very simple: select some resistor and set the output voltage so that the current through the resistor is 100mA adjust Ioffset until the displayed value is 0.100A This procedure is required only once. The other 2 menus (for setting Vout or Imax) are very simple to use .

5. References
1 HC908QT4 microcontroller datasheet (available from e-www.motorola.com) 2 LM338, LM2936-5 datasheets (available from www.national.com) 3 MCP42100 datasheet (available from www.microchip.com) 4 AD8200 datasheet (available from www.analog.com) 5 AN2346, AN1831 application notes from Motorola (e-www.motorola.com)

25

Das könnte Ihnen auch gefallen