easy for you, difficult for me

jwhooper

Senior Member
I built a device, with the help of this board, a year or so ago. It works, but now I would like to be able to vary two things: output amperage and duty cycle.

The picaxe is responsible for the duty cycle, so I think that to make it variable I could just read an input voltage controlled by a pot, right? I think I can control the output amperage the same way, in my one-size-fits-all mind.

Also, when you vary duty cycle, do you lenghten the time and keep the pulse width the same, or do you vary the pulse width within the same time frame?

This is a CES (Cranial Electrical Stimulation) device. It basically sends 1 mA from ear to ear at a 20% duty cycle, which is harmless and relaxing. However, there is some argument as to the optimal duty cycle, frequency, and amperage. The way it is set up now, the picaxe could alter the frequency and duty cycle. I think I would read an analog input with a pot controlling the voltage. Well, I would need two, I suppose.

On the output side of things, it should be fairly easy to use a pot to go from 1 mA to none. It would be nice to know where it is set, exactly, but then I might bust my $20 budget ;-)

It's just a picaxe08m and a few resistors right now, really. But it works great.
 

Grant Fleming

Senior Member
"This is a CES (Cranial Electrical Stimulation) device. It basically sends 1 mA from ear to ear at a 20% duty cycle, which is harmless and relaxing."
To relax I normally put my feet up and read a good book!
Cheers,

Grant
 

Grant Fleming

Senior Member
"You should try to involve electronics in everything possible, didn't you know?"

I'm be worried about my "carbon footprint" while trying to relax!

Sorry I'm not much help at the moment with your question, bit busy at the moment, I'm sure others will reply.

Cheers,
Grant
 

womai

Senior Member
I think I can roughly remember helping on that project, although the details of the final outcome are a bit blurry.

To vary the duty cycle, I'd keep the period constant and vary the pulse width. Your idea of using a potentiometer is very feasible. Attach the two ends to Vcc (5V) and GND, respectively, and the wiper to an input that can be read using readadc or readadc10. Then use that value to set the pulse width for the pwmout command.

For changing the current from the Picaxe (so you know what it is set to) you could use a so-called "digital potentiometer". Analog Devices (www.analog.com) has a good selection, as does Maxim (www.maxim-ic.com). I can't remember for sure if your project used voltages larger than 5V, if it does your selection is limited (Analog used to have the AD7376, even available in DIP package, that could go up to >30V, but it is now obsolete - and I am going to hold onto my few remaining devices for good, sorry :) For <= 5V there are a lot of usable candidates. Note that those companies (especially Maxim) will send you samples for free, you just have to request them from the respective product page. Should help with your limited budget. User control could be the same as above (i.e., read normal potentiometer with readadc).

The only possible issue with driving them is if you use a 08M. An SPI interface needs usually 3 pins (clock, data, enable), while I2C needs only 2 but the 08M does not natively support I2C - I believe Hippy produced some manual I2C code but this isn't for the faint hearted (and not easy to fit into the limited program size of the 08M).

Thinking it through further, another - much easier - option would be to use a normal potentiometer to vary the current, but to add a series resistor into the current path, one end going to GND, and measure the voltage on the other end. You'd probably want to low-pass filter that as well as add some gain before the Picaxe measures it. Could be done with a single op-amp (which buffers the pick-off and scales up the voltage) plus one resistor and one capacitor (forming the low-pass filter, so smoothen the pulsing waveform). Total part cost <$2. For determining the true current you'd need to take into account the duty cycle of the signal - i.e. if you measure a filtered current of 0.1mA and your duty cycle is 25%, then the current during the pulses is 0.1/0.25=0.4mA, but the dutyc cycle is a known quantity.

Maybe you could post your current schematic and then we can take a better look at what can be done.

Wolfgang
 
Last edited:

manuka

Senior Member
Yikes - "1mA ear to ear" = electrical safety red alert. Trust you have quick release electrodes!

Suggest we all have a background CES browse => http://en.wikipedia.org/wiki/Cranial_electrotherapy_stimulation and => http://www.picaxeforum.co.uk/archive/index.php/t-7004.html

Thought: This unit must be effective if it's been more than a year (since you first switched it on) before asking for further help. You don't get that sort of extended relaxation from a good book, Bach or a stiff gin & tonic !
 

kevrus

New Member
Some people drill holes in their skull to allegedly improve their feeling of well bieng, (trepanning is the name that springs to mind)...would'nt want to try that, at least not on my head
 

Rickharris

Senior Member
Some people drill holes in their skull to allegedly improve their feeling of well bieng, (trepanning is the name that springs to mind)...would'nt want to try that, at least not on my head
Been done for years - Mummy evidence shows Egyptians had holes in their heads often partially healed - How stupid were they?


Seems from a bit of cursory research that electrical stimulation of the brain is being used to combat chronic pain, Parkinsons and epilepsy - BUT by doctors who a) understand what is happening b) have the means to resuscitate the patient if it goes pear shaped.

It is already known that electrical stimulation can cause convulsions similar to epilepsy - 1MA seems a lot when the brain activity is measured in micro amps.

I would count this as a safety critical application and outside our scope of involvement. Sorry - Just because no one die (yet) isn't a good reason.

Curiosity does make me ask WHY? Don't tell me you read the stuff about rats pleasure centres? - In the 1950s researchers stimulate rat's pleasure centres when they pressed a lever. Some pressed it 2000 times an hour (you would wouldn't you) - remember Rats are cheap and don't litigate.
 

Dippy

Moderator
And some people fill holes in their skull with beer to allegedly improve their feeling of well bieng...
 

Mycroft2152

Senior Member
If you've got to play with electro stimulation, keep it down at the south pole, a few fried gametes won't matter.
 
Last edited:

Dippy

Moderator
... though I hear it does help people with their spelling.

Hey Myc, why did you edit :) ?
 
Last edited:

Dippy

Moderator
Don't different heads/brains/ears have different impedances? (comments here please!)

How r you controlling current with that in mind?
 

KMoffett

Senior Member
Dippy,

Good electrode contact is 1K to 5K per electrode in a clinical setting. Total is two series contact resistances, plus what ever appears across the body. Dry skin can go to the Meg&#937;'s. It seems the OP is talking current but trying to control voltage and duty cycle with out considering the circuit impedance. Needs a trip back to Ohm's law. ;)

We used 60VDC to generate a 1.5 mA constant-current for iontopheresis studies.
http://en.wikipedia.org/wiki/Iontophoresis
In the old'n days we used a 67.5V battery, a 2mA meter , and a 250K pot...and carefully watched the meter.

Ken
 

jwhooper

Senior Member
I know that most of the units used in studies used 9v batteries. All of the CES units I know of on the market use fairly low voltages. I'm not saying that is right or wrong, but they do seem to get results somehow.

Here is a curious statement by Alpha-Stim:

"Cranial electrostimulation uses microcurrent pulsed high frequency carrier waves (15,000 Hz)"

Now I know this company uses the .5 Hz protocol, so what is this microcurrent? As usual, I don't get it.
 

jwhooper

Senior Member
What I meant was: how is it 15,000 Hz frequency microcurrent and a .5 Hz frequency ... pulse, or whatever. What is producing the 15,000 Hz frequency?
 

hippy

Ex-Staff (retired)
From "uses microcurrent pulsed high frequency carrier waves (15,000 Hz)" I would read that as it's a 15kHz stream which is on for one second, off for another, 0.5Hz.
 

Dippy

Moderator
I'm still trying to work out what "... .5 Hz protocol" means?
Is that a fancy way of saying "everyone uses it" ?

Anyway - like hippy says I reckon. What produces 15kHz? A 12F 50cent PIC I'll bet.

I was just looking at the spec for the Alpha-Stim 100.

"Timer Settings
Probe (10 seconds on, alternating with 2 seconds off), 10, 20, 60 minutes, and continuous.

Current 10 to 600 µA continuously adjustable.
Frequency 0.5, 1.5, or 100 Hz (pulses per second).
Waveform Bipolar asymmetric rectangular waves, 50% duty cycle."



What a laugh... "Bipolar..." marketing-man talk for a bit of wobbley square wave with overshoot , probably a bi-product of creating plus/minus AC.
Me cynical?
But I guess it stops your ears from becoming copper-plated.

Joking aside, I did find my TENS machine got rid of my tennis-cramp.
 

jwhooper

Senior Member
Let's say I have this program:

main:
high 1
pause 500
low 1
high 2
pause 500
low 2
pause 1000

goto main

To me, keeping in mind that I'm not all that smart, this seems to be the .5 Hz 50% duty cycle. One wire on 1, the other on 2. I put my meter on it and I see a nice +5, -5, 0 pattern.

Now if I want this 15,000 Hz frequency, what do I use? Do I use the PWM pins and set them to 15,000 Hz for half a second?
 

BeanieBots

Moderator
That should do it. To get the "bipolar" (I agree with Dippy) feature, feed the PWM into an inverter and take the output lines from the inverter input and its output.
You might want to buffer the non-inverted signal by using two inverters in series.(most packs contain six inversters eg 74HC14). Or, use the hardware PWM feature of the 28X1 designed for driving 'simple' H-bridges.
 

jwhooper

Senior Member
So, let's say I had this program:

main:
pmwout 2,66,133
pause 500
high 1
pause 500
low 1
pmwout 2,0,0
pause 1000

goto main

I set pin 2 to 15 kHz for half a second (lets say this is the left ear), then bring pin 1 high which switches the pin 2 signal to the right ear. Then I set it off for a second.

Is that exactly the same thing as using an inverter on the left ear? Which one is cheaper/easier? Why would I want to buffer using two inverters in series? I'm sure there is a good reason for it, but I don't understand.
 

BeanieBots

Moderator
No.
In your first program, you were setting 1 high and 2 low, then 1 low and two high. That is bipolar drive.
Unless you have a 28X1 and are using the hardware PWM then it is not possible to get bipolar drive from the PWM pin without using an inverter.
I suggested using a buffer (two inverters) to prevent any external loading from 'interfering' with the main signal that drives the inverter.
If you also want to switch from ear to ear then you are going to need to add more circuitry. Quite easy with a few gates and a few more outputs.
 

jwhooper

Senior Member
Remember that every question I ask is likely a basic electronics questions ;-)

What I was trying to ask, is whether or not it is functionally the same to switch from ear to ear compared to setting the output from positive to negative on one ear. They would seem to be the same. The electrons flow one way, then the other.

I will get a couple of inverters and try to figure it out. Or I guess I just need one 74HC14. I'll buy two just in case.
 

BeanieBots

Moderator
whether or not it is functionally the same to switch from ear to ear compared to setting the output from positive to negative on one ear. They would seem to be the same. The electrons flow one way, then the other.
I wouldn't have the faintest idea if electrocuting yourself with a bipolar signal is functionally the same as stuffing DC into one ear!

Honestly though, it has to be up to you to decide which way the electrons flow for how long and from which ear to which ear in what order.
Don't forget, the body has significant capacitance and I'm sure whatever effect is to be gained will depend on many factors. So, in brief, I doubt very much if setting one ear high whilst pusling the other would have the same effect as applying a true bipolar signal across both. Maybe you should experiment to see what gives the desired result.

By the way, from memory, 1.6mA across the heart will stop it:eek:
Maybe the good Doc can advise on how much is required to get it going again?
 

hippy

Ex-Staff (retired)
What I was trying to ask, is whether or not it is functionally the same to switch from ear to ear compared to setting the output from positive to negative on one ear. They would seem to be the same. The electrons flow one way, then the other.
I'd say 0V/5V switching to 5V/0V is the same as if it were -2.5V/+2.5V switching to +2.5V/-2.5V.

Following on from BeanieBots, take a look at the 14M; that should allow control over the HPWM capabilities of the Chip which can deliver the in-phase and out-of-phase signals without needing extra hardware.
 

jwhooper

Senior Member
I have a PICAXE-18X ... will that work?

Bipolar, 15 kHz carrier, all that stuff is from a very well-tested unit that has been used in dozens of studies. They cost about $600.

I have a 555 timer and a 556CN timer if that helps. The 556 has two outputs. The worthless electronics store in my area didn't have ANY inverters of any kind.

I think I have a PNP transistor as well ... or maybe it's an NPN.
 

hippy

Ex-Staff (retired)
Any PICAXE with PWMOUT will work, but you'll need the inverter if you want an inverted, out of phase signal. Likewise I'm sure 555 timers will work, but I have no idea how that would be done.
 

jwhooper

Senior Member
Wouldn't it be "bipolar" if I put the current to one side and then the other, regardless of the 15 kHz carrier wave thing? Isn't there something simple that would just switch the current from one ear to the other? Can't I take the PWM output and merely have something that the picaxe controls that allows the current to flow first to the left, then to the right?

I guess I'll have to order the inverters and wait. I hate it when shipping costs more than the parts.
 

BeanieBots

Moderator
In theory, yes. If the ONLY connections to your body are on each ear.
My concern is if there are any other effects such as the current which will flow down your neck due to capacitance of your torso and other similar effects. I honestly don't know. Just pointing out possibilities.

Different scenario totally but consider a transmitter aerial. Broadcasters can pump killowatts of power into a 'length of wire' with just a connection at one end. I only use that as an example to demonstrate that a circuit does not need to be complete (in the DC sense) for current to flow.

Also, bipolar doubles the voltage difference.
 

hippy

Ex-Staff (retired)
Isn't there something simple that would just switch the current from one ear to the other? Can't I take the PWM output and merely have something that the picaxe controls that allows the current to flow first to the left, then to the right?
To reverse current flow you have to switch so that one ear which was at a higher voltage potential to the other has a lower voltage potential than the other. That can be done using an inverter or it could be done by providing a fixed 2.5V to one ear and switching between 0V and 5V at the other, or it could be done by keeping one ear at 0V and switching the other between 2.5V and -2.5V.

In order to stop current flow you need both ears at the same voltage potential. To minimise any short spikes when stopping current flow if using an inverter you would probably need to gate both the in-phase PWM and the out-of-phase inverted signal from a common I/O line. On a PICAXE, there would be a short period between turning PWM off and disabling the inverted signal. I have no idea if this resultant short pulse would otherwise be detrimental or not.

Using the HPWM abilities of a 14M/28X1 it should be possible to set both the PWM and inverted PWM to 0V simultaneously but you'd have to read the datasheets to check that.
 

jwhooper

Senior Member
OK, here's another attempt. Unfortunately I don't have an ocilliscope, so I can't check the output. The goal is a 15kHz carrier modulated at 100Hz with a 50% duty cycle, if that makes any sense.

The picaxe has to be set at 8 MHz to get close. That makes the pulsout scale at 5us. 65us pulses is about 15.4 KHz, but overhead might slow it down a bit. (65+65)*38=4940us, which is run left and right making it close to 100 KHz.

'pin 1 -- left
'pin 2 -- right
'pin 0 -- dummy

main:

'send 15KHz to left
b1=0
do
pulsout 1,13 '65us
pulsout 0,13 '65us
inc b1
loop while b1<38

'send 15KHz to right
b1=0
do
pulsout 2,13
pulsout 0,13
inc b1
loop while b1<38

'waste an equal amount of time
b1=0
do
pulsout 0,13
pulsout 0,13
inc b1
loop while b1<38

b1=0
do
pulsout 0,13
pulsout 0,13
inc b1
loop while b1<38

goto main
 

hippy

Ex-Staff (retired)
To get 15kHz square waves means 33uS for the pulse, but also 33uS between those pulses ( an overall cycle of 66uS ). With the speed of the PICAXE executing instructions, it seems unlikely you will get anywhere close to that.

The maximum frequency you could hit is from pulse time plus execution time, and if you wanted a square wave you'd have to stretch the pulse out to match the execution time, making it slower still.

To pulse a pin then pulse a dummy pin as you have, would only work if the PICAXE executed everything else near infinitely fast. I don't recall Rev-Ed having committed to achieving that :)
 

jwhooper

Senior Member
Rats. Oh well, I notice that the Picaxe40 has two PWM pins. Unfortunately, I think it needs a crystal, which would require that I, once again, would need to actually know something about electronics, or have the capacity to learn that I apparently lost some years back.

Maybe I can find a 74HC14 and then figure out what exactly I'm supposed to do with it. I mean, I would still only have the one PWM output. I don't see how just inverting it does me any good.
 

Dippy

Moderator
Could you use an RS232 driver to get the +/- ? Or some other charge pump inverter device?
Then you could keep one ear to the ground...
 
Top