Thursday, May 24, 2012

Quadrupole Magnetic Lens Simulation

Over the last month I've done a series of posts about magnetic lenses and their ability to steer and focus electron beams.  The simulations are done in Octave and investigate electrons passing axially though single or multiple loops and how current can effect their trajectories.

Electron Beam Magnetic Lens Simulation
High Current Magnetic Lens Simulation
Multi-Turn Current Coil Magnetic Lens

While doing research I came across the following image of a quadrupole lens similar to the one used in the Australian Synchrotron.

Quadrupole Lens

I was intrigued and thought I would try to simulate how the lens worked.  A quadrupole lens is conceptually basic, it consists of 4 multi-turn coils mounted on a high permeability core to direct and contain the magnetic field.  There are two north poles and two south poles, with opposing poles being of the same type.  The geometry for my simulation is going to be simpler.  I'll replace the multi-turn coils with single turn rectangular coils and leave out the core.  A cross section of the magnetic field produced is shown below.

Quadrupole field cross section

This kind of lens can only focus one plane at a time, but as it does it will defocus the plane perpendicular to it.  For example, it will focus the beam in the horizontal direction, but defocus it in the vertical direction.  However, by using two quadrupoles with sufficient separation, one focussing vertically, and one focussing horizontally, the beam can be brought to a focus.

The code for my simulation isn't very pretty but it gets the job done.  In fact it is rather inefficient.  There are many opportunities to vectorise the code, but the 10 hours it took to run while I was at work cost me no time, whereas improving the code would have taken a couple of hours.  The simulation was split into separate parts, with data from the first stage saved to disk before continuing to the next stage.  The files can be found here.

To start off I have created a function called "B_Wire" that calculates the magnetic field created by a straight finite wire.  It takes three position vectors and a scalar as inputs.  The vector P1 is the start of the wire, P2 is the end of the wire, and T is the position where the magnetic field needs to be calculated.  I is the current in the wire.  With some vector operations, BT, the magnitude of the magnetic field can be easily calculated.

Magnetic field magnitude calculation

The direction of the magnetic field can be calculated by first finding the position vector M.  The location of M is set by making vectors d and D perpendicular.  Once M is found, a vector in the direction of the magnetic field can be found by taking the cross product of (P2-M) and d.  A unit vector in the direction of the magnetic field can be found by normalizing the result.


Calculating the position of M

However, as I write this I realise that I didn't need to do any of that.  By taking the cross product of the vectors C and D you get a vector in the direction of the magnetic field.  Oh well, either way should work.

The function BLens calculates the field of a single quadrupole via multiple calls to B_Wire.  The function B2Lens then calculates the field from 2 separate quadrupoles.  To examine the effects the quadrupole lenses have on an electron beam, 24 different trajectories with the same initial velocities in the x direction, and varying y z starting coordinates, were calculated.  By taking cross sections of the beams along the x axis the focussing effects can be observed.  The current in the second lens is in the opposite direction of the current in the first lens.  The magnitude of the current was found by trial and error.  Actual specifics aren't that important in this simulation as this is just to prove the concept.  The speed of electrons in a synchrotron is close to the speed of light, whereas in my simulation the electrons have a velocity of about 20% of that.  Combining that with the fact I have a simplified geometry, we can't take the numbers too seriously.




It can be seen that after the electrons pass through the first lens the beams start to focus in the z direction but defocus in the y direction.  As the beams pass through the next lens that focusses perpendicularly to the first one, the spreading of the beam in the y direction stops and the beams start to converge.  Convergence of the beams in the z direction imparted by the first lens starts to decrease, but isn't completely stopped.  The motion in the y and z direction is now balanced to bring the beam to a focus approximately 2.2 meters after the first lens.

Although the simulation uses a very simple model and does not accurately replicate how the lenses in a synchrotron work, the basic principles of operation can be seen.  The focussing of the beam in one plane and the defocussing of the beam in the plane perpendicular to it was observed.  Bringing the beam to a focus by using two quadrupole lenses was also demonstrated.

Sunday, May 20, 2012

Replacing a Motor Run Capacitor

Lately I've had a bit of trouble with a pump connected to our rain water tanks.  Not turning on, stalling, just generally not working.  Catchup on my previous attempts to fix the pump in my last post to bring yourself up to speed.  The pump in question is an Onga JM100 pump.  The specs are shown below.

Pump Specifications

Warning - This article describes equipment and circuits that operate at high voltages.  Don't attempt to repair any high voltage circuits if you're not trained to safely work with electricity.  You may be seriously injured or even killed.  For further information read the blogs Terms Of Use.

Well it turns out that I was wrong about the cooling fan cowling.  It wasn't too tight and causing the motor to stall.  How do I know?  I took it off completely and let the pump run, but after cycling a couple of times it stopped working again.  All I had left to check was the pressure switch, the motor capacitor, and the motor itself.  If it was the motor I didn't have a hope. So hoping for something easy, I decided to take a look at the pressure switch and check if the contacts were dirty. I thought the humming noise I was hearing may be the contacts chattering or the motor humming because it couldn't get enough current because of high contact resistance.

Pressure switch

The pressure switch is a mechanical switch is by a company called Square D that is now owned by Schneider Electric.  The pressure of the water controls two sets of contacts that break the neutral and active lines.

Pressure switch mechanism

In the above photo, just above the screw terminals where the wires are terminated, you can see the set of contacts that break the neutral line.  Sometimes after a long period of operation the contacts can become dirty and  increase the resistance of the switch, but after listening closely to the switch and testing it with a multi meter it was clear that the switch was working fine.

The only thing left to check that I could actually fix was the motor run capacitor.  It's housed in a box that's mounted on the top of the motor.  In a single phase induction motor a second winding that is 90 degrees (or as close as possible) out of phase with the main winding is needed to create a rotating magnetic field.  The capacitor in series with the start winding is used to produce this phase difference

Motor run capacitor housing

The capacitor is connected via standard spade connectors, so it's easy to remove, but before doing so I labelled all the wiring to make sure I knew how to reconnect the windings.

Removed capacitor

As you can see from the markings on the capacitor above it's meant to be 10 uF.  So I pulled out my multimeter to test if it really was.

Removed capacitor measurement

I know I don't have the best multimeter in the world, but come on, 2.1 uF?  To make sure, I double checked the multimeter against a know capacitor and the measurement agreed to within 5 percent.  Just to be extra sure, I set up an RC circuit, fed it with a low frequency square wave, and measured the time constant with a scope, and once again I got 2 uF.  So it looked like this capacitor was the culprit.  That was great, after all, this was the first time I could point at something that I knew was definitely wrong.  Two days later I had new capacitor in my hands from RS components.  Not exactly the same part, but its specs were equal or better.  Like the old one it's a four terminal device with two terminals connected to either side of the capacitor which allows you to jumper connections off it.

New capacitor

New capacitor measurement

Before installing the new capacitor I measured its value to make sure it agreed with the marked value of 10 uF.

New capacitor installed



Although I marked the leads on the capacitor, it doesn't hurt to double check the connections.  By measuring the resistance between the leads of the motor you can tell how the motor is wound.

Wiring diagram

On this motor if you measure the resistance between the black and blue wires you measure the resistance of the main and start windings in series.  If you measure between the brown and black wires you get the resistance of the start winding, and if you measure between the brown and blue terminals you get the resistance of the main winding.  The measurement with the lowest resistance is typically going to be the main winding.

Confident that I had reconnected all the wiring correctly I replaced the covers, turned the pump back on, primed it and got the outlet line up to pressure.  I then turned the tap on and cycled the pump about 10 times.  Each time the pressure switch cut in and the pump started.  What was immediately noticeable was the increased flow rate of the pump and a reduction in the amount of noise it produced.

The reduction in capacitance causes a drop of current in the start winding, which reduces the starting torque at certain rotor positions.  This also has a side effect of reducing the power output of the motor, and creates a fluctuating rotating magnetic field within the motor which causes increased operating noise.

So far the pump has been operating correctly for the past two days, which I think is a good indication that the problem is fixed.  I learned quite a lot during the repair process, and as usual the last thing I checked was the actual problem, but as with any problem worth solving it came down to the electronics.

Sunday, May 13, 2012

Fixing a Pressure Pump

Today I did something a bit different and did some mechanical work on a pump that we use to supply our washing machine and toilet with rainwater from tanks.  Recently it has been making some strange sounds, and sometimes it doesn't cut in at all.

Pump without the water outlet

The pump is part of a standard set-up, water comes from the rainwater tank and is pressurised and sent to where it needs to go.  A pressure switch on the outlet port of the pump turns the pump on when it senses a drop in line pressure created by a tap being opened, it then cuts out when a certain pressure is reached.  To stabilise the system, and stop the pump constantly cycling, a pressure tank is connected to the output.  This consists of a pressurised bladder of air in a tank, as the water is pressurised it compresses the bladder.  If you want to think of it in electrical terms, the pressure tank acts like a capacitor and the pressure switch adds hysteresis, creating an oscillator.  The larger the capacitance, or pressure tank in this case, the lower the oscillation frequency.

After a few tests I could tell that the pressure tank was fine and only needed to be topped up with some air.  The strange sounds that I heard sounded like something was rubbing when the motor turned.  This could have been a dry bearing, something wrapped around the impeller shaft, or a object obstructing the cooling fan.  The only way to find out was to remove the pump and pull it apart.

To start with I removed the outlet of the pump to make sure there was nothing wrapped around the impeller causing the sound I was hearing.  There was a bit of slime, but in general it was clean as you can see in the image below.


Pump Impeller
The next most likely culprit was the cooling fan that blows air over the motor casing.  After removing the cowling I was able access to the fan and found a build up of dirt.  What's basically happening is air with dust in it gets draw into the fan, the dirt being heavier hits the blades and gets flung into the cowling where it builds up until it rubs against the blades and causes a rubbing sound.  Pieces then break off and rattle about the fan housing.  If your really unlucky the pieces jam the fan blade and stall the motor.

Dirt on the fan and cowling

Dirt on the fan blades

After a clean up with an old toothbrush it was as good as new.  The cowling was replaced and the pump was reconnected.  It worked perfectly.  The pump was pumping and the strange sound had disappeared.  Then it stopped working again.  I tapped the cowling off a little bit and all was good again for a while.  From what I can see, I think the cowling is a tight fit and if it is slightly misaligned it will touch the fan blades.  The next step is to remove it completely, let it go for a week and see if it works.  If it does, which I think it will, I'll have to make my own fan cover or file a tiny bit off each of the blades.

Update - 20 May 2012
With further investigation and testing I have discovered the fault with the motor.  The problem and how to fix it can be found here.

Tuesday, May 1, 2012

Multi-Turn Current Coil Magnetic Lens

My last couple of posts on magnetic lenses herehere left me mostly satisfied, but still curious about the electron beam trajectory.  From the research I did on the topic I thought that the beam should spiral around the axis, but equally I can make a case for it not doing so.  Electrons tend to move in spirals around magnetic field lines, and that is evident in the the high field simulation as the spiral tightens and moves in towards the axis as the field lines bunch up and pass through the coil.

I thought that I may see some of sign of the beam spiralling around the axis if I had a larger region where the field was more uniform.  To test this hypothesis, I did another simulation where I replaced the single coil with twenty, all carrying 5 percent of the single coil simulation current.  The results however were essentially the same.  The graphs below are from the simulation output.  The Octave code for the simulation is located here.

Cross section of the field through the coil axis
Cross section of the field near the centre of the coil
In the two graphs above it can be seen that the field is more uniform throughout the length of the coil.  The second diagram also shows that there is almost no radial component to the field in the centre of the coil.

Electrons spiralling along through the coil
Electron trajectory through the coil

I have selected a high current for the simulations to exaggerate any effects that may be present and once again I got the same result, the electrons spiral along "kissing" the axis and moving away from it again.  In reality, most of these simulations are unrealistic and can't be tested, and without some sort of physical experimentation I can't confirm my results, but the model seems sound.  The results from basic simulations with a constant field agreed with theory, and there aren't any obvious instabilities.

If anyone has any experience with a similar model, either a simulation or a physical device, I would like to hear from you.  What type of trajectory should I be expecting to see?  Are these simulations close to reality?

I found these simulations quite satisfying really, the way a simple equation like the Lorentz force equation, combined with some initial parameters, produces such a complex result.  At least I have a better idea of how electrons move in magnetic fields, that and I got to sharpen my MATLAB skills again.  The code isn't optimised but it does the job.