Microcontrolled Biostimulator
Fall 1999
Prof. Land and Brian Wong



 







Introduction:
        The microcontrolled biostimulator is designed to be a inexpensive alternative to more expensive commercial models. By replacing costly discrete IC timers with one microcontroller, a huge price savings can be acheived; a microcontrolled stimulator can cost as little as five dollars. Due to the price savings, a stimulator can easily be distributed in classrooms, labs, and field experiments. Note the microcontrolled biostimulator is not "cheap" alternative. Timing parameters and errors are similar or better than a normal discrete IC based designs.


Specifications:
Maximum Minimum Comments
Input Voltage 20V 5V Using Atmel development board
Output Voltage 5V CMOS compatible
Time step 100us 100us Firmware adjustable
Beats 255 0
Interval 65536 * Time step 0
Duration 65536 * Time step 0
Inital Delay 65536 * Time step 0
Interbeat Interval 65536 * Time step 0
Sync Pulse Yes
Manual Pulse Yes
Y2K? Yes


Philosophy:
        The biostimulator is divided into two discrete parts. The first is the "Timer Core"; this segment controls all the timing for the stimulator. The timer core is part of every stimulator. The second part is the "Wrapper"; this segment provides  interface between the core and the user. As the timer core is a stand-alone component, the stimulator can adapt to a wide variety of situations.


Timer Core:

   The timer takes five different values:

        With the exception of the the "Beats" field, all variables are 16 bits wide. This allows the timer core to span enough "time space" for biological systems to register.  The "Beats" field, however, is only 8 bits wide. This can be increased to 16 bits, but will require slight modification of the code.
        The timer core just controls the timing, nothing more. It assumes the values that it is given are correct. As this is a "core", it can be used with other wrappers, as long as the values passed from the wrapper to the core, namely the above, are present. Think of it as a function that needs to be passed information about the interval, duration, sync delay, interpulse delay, number of pulses, and a single or multiple interval run.
        The pulse train is specified as follows. The basic unit is the interval, defined as the time from one sync pulse to another. Inside the interval, there can be pulses or "high" signals that have a certain duration, spaced apart by an interpulse delay. This train of pulses can then be shifted around the interval by changing the sync delay. Finally, if only one interval of pulses is desired, then the timer should be set to "single". If a continuous stream of intervals are wanted, then the timers should be set to "multi".
 

    Inputs and Outputs are as follows:
        PortB #3 is the pulse output.
        PortB #0 is the syncronization output.
        PortA #5 and #6 are Pulse/external inputs.

        The timer core is quite simple. TimerA controls the time base, the "tick" for the clock. Currently it is set to a 100us tick. When TimerA overflows, it provides a 'tick' to TimerB. As the microcontroller runs TimerB accumulates a value from these ticks.  While running, the controller polls TimerB to see if certain points in the specified pulse train, like the end of a duration, have been reached. When this happens, PortB#3 is turned on or off, depending on the previous status of the port. At the same time, the timer calculates the next milestone that TimerB needs to hit. When the new value is detected PortB#3 toggles again. This repeats as necessary. When the interval is over, everything resets and starts anew with a new sync pulse. The sync pulse and the pulse output can be syncronized when the 'Sync delay' is set to zero. Having a non-zero value shifts the pulse train so that it starts later than the sync pulse.


Wrapper:
        The "Wrapper" is simply a user interface for the biostimulator. Depending on the application, it can take many forms. Lab users may prefer the RS-232 support, while field and classroom use may enjoy a LCD/button type interface. The wrapper is also totally unnecessary; if long term embedded solutions are needed, the stimulator can be used as an OTP device.
        In its current iteration, however, the RS-232 support is implemented. Using a PC, new timing parameters can be inserted to the biostimulator. It must be noted that you need a serial program like "Hyperterminal" to communicate with the stimulator. To set up a serial link,  the computer needs to have the serial cable attached to COM1 and the serial port on the evaluation board. Then in hyperterminal, set the protocol to 9600-8-N-1.
        9600 refers to the baud rate, or speed, of the serial communications. The baud rate on the computer can be set to a higher setting, but the user must manually change this setting in the microcontroller code. Right now it is set to 9600, and it is fast enough for most purposes.
        The '8' refers to the the word size. All communications for the biostimulator will only use 8 bit words.
        For parity, set it to 'N' for none, set the stop bit to '1', and there is no flow control.
 
 
 

Here's how to use the RS232 implementation:

                Parsing ASCII into binary is fairly easy. Clear the top 4 bits of each number to remover the ASCII prefix, and multiply the lower 4 bits by the corresponding decimal mulitiplier (ie:1,10,100). A simple multiply and add chain does the trick.

                Once all the numbers are parsed, the stack is flushed. This is to return the stack to its original state when it first entered the parse routine. This is important, or else the microcontroller will interpret one of the numbers that was entered to be a memory address to jump back to. To do this, a small 'pop' routine runs at the end of the parse routine. This loops only as many times as there are digits entered. Once all then numbers are popped off, then the program returns normally.

The source code.



Problems and Improvements:
        As with all projects, perfection is impossible. Below are some caveats and ideas for improvement.

    Timer Core:


    Wrapper: