edurant.com > MSOE > SEED > Final > Design Documentation: Control Blocks: Firmware

Firmware

The system firmware was written with version 3.10 of the Introl C cross-compiler (Appendix B: Acknowledgments for information about Introl). This greatly eased the use of the complicated data structures and procedure call chains required by this application.

The firmware was designed with extensibility in mind. Hooks have been implemented for several features that are not active in the prototype. Global variables, especially for the supply descriptors and data, were used to simplify variable passing in the upper routines, but most lower routines access this data through passed pointers, making them more generic.

The firmware functionality is broken into seven categories with minimal overlap. These are based on the tasks of the system.

Figure 11 shows the relations between all non-system functions. A brief discussion of each category and these functions then follows. Flowcharts of non-trivial functions are included in Appendix D: Firmware Flowcharts. A complete code listing is included in Appendix E: Firmware Code. Also, several of the Introl configuration files had to be modified to work with the 68F333 (see Appendix J: Microcontroller Specifications). These are included in Appendix F: Compiler Configuration.

Figure 11: Firmware Function Hierarchy
Firmware Function Hierarchy

Main Loop

This routine sets the data direction registers, writes the keypad ISR vector, initializes the supply, display and alarm systems and goes into an endless loop. The endless loop toggles the COP, sets the master relay, updates the display, regulates the supplies and changes the system status to "off" when an error is detected.

High Level Supply Control

The high level supply control functions maintain the supply data points and perform the regulation based on this data.

Initialize Supplies (initSupplies)

This function puts the supply control lines in a known state, links constant supply data to the main supply data structures and initializes all dynamic supply data (including set points, target point and voltage or current control selection).

Regulate Supplies (regulateSupplies)

This function steps through all supply modules, calling routines to update the set point, output the present set point, take and save voltage and current readings and check for errors.

Update Supply Set Point (updateSetPoint)

This routine uses the system response parameters (threshold, inertia, and maximum dv/dt) to tune a supply.

Calculate Moving Average (historicAverage)

This function returns the a voltage or current average for the requested supply and polarity of a supply.

Initialize Reading History (initHistory)

This function initializes the history for the active control method (voltage or current) to indicate that the desired value has been reached. The history of the other parameter is initialized to 0. This makes the regulation routine believe that the supply has reached it's goal before it starts regulating and softens the response, mitigating glitches.

Update Reading History (updateHistory)

This routine inserts a new reading into the history data for a supply, discarding the oldest. This allows a moving average to be calculated.

Low Level Supply Communication

Get Reading (getReading)

This function asks the currently selected supply for the currently selected statistic (voltage or current).

Put Supply Data on Data Lines (putSupplyData)

This routine puts a 10-bit data word on the supply data output lines.

Put Supply Address on Address Lines (putSupplyAdr)

This function takes a supply and polarity and puts the appropriate address on the supply address lines.

Display

Initialize Display (initDisplay)

This procedure goes through the startup procedure specified by the LCD display manufacturer. It also outputs the names of the supplies (which do not change) and the initial status line.

Update Display (updateDisplay)

This routine prints the voltage and current values for all relevant polarities of all supplies on the display. It also updates the status line which shows:

Put String on Display (putString)

This function outputs a string to the specified display location.

Put Center-justified String on Display (putStringCenter)

This routine outputs a string centered on the specified display line.

Clear Display (clearDisplay)

This clears the display.

Strobe Display Enable Pin(s) (strobeDispEna)

This function strobes the specified display enable pin, affecting the corresponding display page. If a non-existent page is specified, both enable pins are strobbed.

Keypad

Keypad Interrupt Service Routine (keypadISR)

This procedure fetches the keystroke when the keypad system generates an interrupt. If the key is a number or a decimal point, it is appended to the input buffer if there is room. It also updates the buffer if the "clear" or "backspace" key is pressed. Additionally, system state bits are toggled by the appropriate keys. If "enter" is pressed, the validate keypad entry routine is called.

Validate Keypad Entry (valEntry)

This routine takes the keypad input (number and voltage or current selection) and updates the supply data accordingly.

Trap Invalid Key Sequence (keyTrap)

This function will not be entered under normal operation. Its purpose is to handle special or unexpected keypad input.

Error Checking / Safety

Toggle COP (toggleCOP)

Any function which needs to signal the computer operating properly system must call this routine. This function does nothing in the prototype.

Control Master Relay (masterRelay)

This procedure sends the requested signal (on or off) to the master control relay.

Error Check (errorCheck)

This routine examines the data for the specified supply and modifies the system error object if necessary.

Handle Error (handleError)

This routine zeros the output to the supply causing the error and prompts the user per the interface specification. Once the error is acknowledged, the set point is set to 0 and all history data is reinitialized to allow a "soft start up." Also, the display is re-initialized.

Put Error Message on Display (putError)

This function describes the error to the user based on the contents of the system error object.

Utility

Signum (sign)

This function returns the sign of its input.

Microseconds Delay (delay)

This procedure delays for at least the given number of microseconds.

Encode Voltages and Currents (encode)

This routine takes a floating point value and generates the corresponding 10-bit target word based on the supply characteristics.