TENS Unit with digital user interface
A TENS (Transcutaneous electrical nerve stimulator) unit with computer control for all parameters. Officially designed for reducing pain, but they have other fun uses too.
Features of this unit:
3 independed outputs (pulselength 0 to 224 uSec in steps of 32 uSec)
Variable output frequency (1 to 3905 Hz in steps of 1 Hz)
Output amplitude (5 to 80 Volt in steps of 0.5 volt)
Lowfrequency oscillator (0 to 99 Hz step of 0.01 Hz)
Different output patterns (All, Seq1, SeqA, Pong, Grou, 1off, rnd1, 1/4, 1/8)
Easy menu navigation
Always working stop key
Lowpower standby mode
Runs on 4 NiCd batteries (4*1.2v = 4.8v) or on regulated 5 volt source.
Free schematic and software ;-)
Schematics and internal working of the device
The hart of the system is an Atmel RISC microcontroller. I have choosen the AVR Tiny26 because it has a lot of outputs and can be programmed (flash rom) while in the circuit. It has two independed PWM outputs which are both used for the highvoltage generator. I had few of these chips laying around from a previous project, so that made the choice for them also easier. The PAx and PBx names in the schematics show to which pins the microcontroller needs to be connected to make it work with my versions of the software.
The system is operated by a 5 key interface and 4 7-segment displays (They are a little dim however to save battery power, but are better readable as LCD in my opion). The system provides the user with a menu system which can be traversed with the left/right buttons. Choices can be made and settings changed with the up/down keys. The 5th button is always the emergency stop, which disables the outputs and turns the highvoltage generator off if pressed.
Although the the microcontroller has a lot of I/O line, the 7-segment displays and keys are multiplexed across the same lines to reduce the I/O usage. A 74HC574 is used as a shift register which has a running '0' in it to enable each segment of the displays in succession. Only one segment is active at a time. Including the 'dot' it takes 8 clocks to refresh the display. After 8 clocks a new '0' is inserted at the input of the shift register and at the same time the keys are read.
The CPU clock runs on an internal 8 Mhz RC oscillator, which has proven quite accurate in practice and saves 2 more I/O lines. The clock is divided by 256 by timer0 so the system times everyting at 31250 ticks each second. This explains the 32 uSec steps for the output pulselength (1/31250 Sec = 32 uSec).
The highvoltage generator is controlled from two PWM outputs. The PWM output on PB1 is set fixed at 80% duty cycle and is used to actually drive the generator. My first design only used this output with a variable dutycycle, but it was very difficult to control the output voltage this way. This new design uses a feedback loop to make fine control of ouput voltage possible (around 0.5 volt for each step) and the output voltage is almost independed on the output current unless the load is very high. With the current resitor values the maximum output voltage is around 85 to 90 volt which drops to 75v under heavy load. Changing the 1k and 1M resitors in the feedback circuit can change this working range.
The highvoltage is routed to 3 identical circuits, which drive the outputs. This is a simple push-pull driver that converts the DC voltage to a pulsed AC signal. The 100 Ohm resitor protects the driver against shorts at the output.
Go_ -> Rst_
. -> tEnS -> P000 -> FreQ -> PlS1 -> PlS2 -> PlS3 -> LFoF -> All
tEnS P000 0976 000u 000u 000u 00.00
Software and support files
tens 1.00 firmware (asm and hex)
tens 0.90 firmware (asm and hex)
For those who want to experiment, here is an alternative firmware for the tens unit.
It has a different menu structure as it allows selection of different patterns for each output.
The pulse width settings are removed and replaced with various pattern selections.
The internal resolution is increased from 32uSec to 16uSec to allow smooth transitions from 0 to maximum amplitude.
Go_ -> Auto
. -> tEnS -> P000 -> FreQ -> LFO -> Out1 -> Out2 -> Out3 -> Phase
tEnS P000 0976 00.00 1Sin 1Sin 1Sin 0 deg
On powerup the unit starts in standby mode (single dot on display) press any of the 4 menu keys to go to the menu structure. ('Tens' is displayed as greeting message)
Go_ is used to enable the unit, press up in this menu to activate the unit. Press the stop button once to deactivate it again. Pressing stop twice goes back to standby mode.
The P000 is overal power and runs from 0..255 (corrosponding with around 0..80 Volt output).
FreQ is the pulse repeat frequency and runs from 0Hz to 3KHz.
LFO is the frequency at which the patterns are played back. It is selectable in steps of 0.01Hz.
Out1 .. Out3 are the selections of the waveforms/patterns for each individual output. There are various patterns available:
off - no output
on L - continuous pulsing, each pulse 160 uSec
on h - continuous pulsing, each pulse 300 uSec
1Sin - Slow sin-wave modulation
2Sin - Two sin waves for each pattern run, only usefull when combining with other patterns on the other outputs.
4Sin - Four sin waves for each pattern run, only usefull when combining with other patterns on the other outputs.
Sn/2 - Sin-wave combined with half period of inactivity.
Up - Intensity rises slowly and falls quickly.
1/2 - Same as Up but twice as fast, and half the time the output is inactive
1/4 .. 1/16 - Faster pulses with more off time
Rnd1 - Random pulses
Plss - Alternating short and long bursts of pulses
Phase - shifts the phase between the three outputs. So if set to 120deg and all play the '1Sin' pattern they alternate in intensity.
The first output rises while the other two will fall in intensity. Using 1/4 .. 1/16 together with correct phase setting can create 'running' pulses across the outputs.
Auto - Increments the overall power each xx Seconds. There is a small bug as even when 'stop' key is pressed the power-level is incremented. So be carefull when using this option: Check the actual power level before activating 'Go_'.
While pressing down or up to change the values for Freq and LFO, the change rate can be increased by holding the 'up' or 'down' and pressing the 'left' or 'right' key at the same time. This is usefull as the both the Freq and LFO have a huge range. Take not the other settings don't have this option, this is to save flash-space (this small device is almost full).
tens alternative firmware 20070701 (asm and hex)
A look on how I build the thing