Physiological Stimulator
Introduction
The goal of this project was to build a small, cheap, light-weight stimulator
for student use in electrophysiology labs. Specifically:
- Computer-controlled pulse trains, with optional manual trigger.
- Times:
- Pulse duration 1-4000 milliseconds
- Pulse spacing 1-4000 milliseconds
- Stimulus interval 1-4000 milliseconds
- Pulse train setable from 1 pulse to 255 pulses
- Two versions:
- Controlled via an rs232 port on a host computer.
- Controlled via a keypad and LCD display.
The traditional stimulator is a box full of analog and digital parts. We replaced
all these with a cheap microcontroller.
PC-controlled version
There are four processes which run on the microcontroller:
- The RESET entry point initializes the ports and timers, then waits for
the operator to enter stimulation parameters on the host-computer keyboard.
When the stimulator is running, a main loop detects a button push (if in manual
trigger mode) and detects a '
s
' keypress on the host-computer
keyboard to stop the stimulator and prompt for new parameters.
- The timer 1A compare-match ISR (interrupt service routine) occurs when a
new stimulus is ready to start. The ISR initializes pulse counters and emits
a synch pulse, then does nothing else until the next repitition of the song.
Timer 1 ticks once every 64 microseconds. In manual mode, this ISR is disabled,
but is entered as a subroutine call when the trigger button is pushed.
- The timer 1B compare-match ISR occurs whenever a pulse starts or ends. The
ISR sets the pulse variables, then sets it's own next occurance by keeping
track of the next pulse start/end time.
- The timer zero overflow ISR occurs once per millisecond. This ISR is used
for general timing, including debouncing the trigger button. Timer 0 ticks
once every 16 microseconds.
This AVR assembler code is the program running on the
mcu (march 23 version).
Using the PC-controlled stimulator
This version of the stimulator assumes that you have a terminal emulator (or
custom program which can emit rs232 commands) on the host-computer. The communications
port should be set to 9600 baud, 8-bits, no parity, one stop-bit, no flow control.
If you are using an AVR prototype board, then you must configure it for serial
communication.
When the microcontroller is reset, it will prompt the user for 4 numbers with
the following message:
Enter number, dur, spacing, interval>
A typical response might be:
4 1 3 500
meaning that a stimulus should be 4 pulses, each 1 millsec long, separated
by 3 millsec, and repeating every 500 millsec.
The mcu will then prompt the user for free run vs manual trigger.
Press m for manual, r for freerun>
The only valid responses are 'm
' and 'r
', for manual
and free run respectively. If the manual option is chosen then there will be
exactly one stimulus sequence from the mcu when a button is pushed.
PortD.0 and PortD.1 on the AVR mcu are the serial connection to the PC. PortB.0
is the stimulus output. PortB.1 is the synch pulse output. A pushbutton with
pullup resistor must be attached to PortD.2 for the manual trigger.
Stand-alone version
There are four processes which run on the microcontroller:
- The RESET entry point initializes the ports and timers, then waits for
the operator to enter stimulation parameters on the 16 button keypad. When
the stimulator is running, a main loop detects a button push (if in manual
trigger mode) and detects a '
#
' keypress on the keypad to stop
the stimulator and prompt for new parameters. All text is displayed on an
LCD display.
- The timer 1A compare-match ISR (interrupt service routine) occurs when a
new stimulus is ready to start. The ISR initializes pulse counters and emits
a synch pulse, then does nothing else until the next repitition of the song.
Timer 1 ticks once every 64 microseconds. In manual mode, this ISR is disabled,
but is entered as a subroutine call when the trigger button is pushed.
- The timer 1B compare-match ISR occurs whenever a pulse starts or ends. The
ISR sets the pulse variables, then sets it's own next occurance by keeping
track of the next pulse start/end time.
- The timer zero overflow ISR occurs once per millisecond. This ISR is used
for general timing, including debouncing the trigger button. Timer 0 ticks
once every 16 microseconds.
The AVR code (march 23 version) and schematics will
be here soon...
Using the Stand-alone version
Stay tuned, still under revision...