Tuesday, July 12, 2022

More About 2 to the millionth power: How Many Digits Does it Have?

Any old scientific calculator can tell you that log(2) is approximately equal to .301030.  The log of 2 taken to the power of one million (2^1000000) is log(2)*1,000,000, or 301030.  It's not trivial to use this number to determine 2^1,000,000 down to the last digit, but it IS trivial to say how _many_ digits the number has.  It is: 301,031 digits (because 10^0 is equal to 1, we need to add 1 to our result, then throw away the non-integer part).

For a simple verification of my assertion, let's take a look at 2^10, which is easy to compute:  it's 1024.  10 times .301030 is 3.01030.  Adding 1 to this is 4.01030.  Taking the integer value we get 4, and that's how many digits 1024 has.

In fact, we can use this scheme for any power of 2.  For example, we know that 2^16 = 65536.  16 times .301030 + 1 = 5.816, so we verify that the scheme works for any power of 2.  The limitation to the approach is the accuracy of the value we use for log(2), which is a transcendental number so it has an infinite number of digits.  But there are some online calculators we can use to get quite a few more digits.  One reports that log10(2) = 0.30102999566398114, which should suffice for determining how many digits 2^N has up to N = 10^17.  According to an earlier post of mine we already know that its least-significant digit is a 6 😀.

By the way, we know that log(2) MUST be a transcendental number because the relationship I described above has to hold for any arbitrarily-large power of N for 2^N.  It doesn't matter if N = 10 or 10^10^10.... 

Monday, July 11, 2022

Magnetic Latch Simulations, Part Two

 I changed my simulation scripts for two variations on a magnetic latch mechanism so I could plot force vs. distance for them.  One is the simple magnet and flat steel plate, and the other is one of my long-range latch designs.  The differences are pretty stark:



The long-range latch force vs. distance plot looks a little bumpy but the important thing to note is that it is exerting pretty significant pull as far away as 1.6 inches, while the simple latch just starts to do its thing at around one-half inch, and even at that distance is far less "strong".

Based on this result I think a combination of my long-range latch and a simple air pneumatic damper to get the soft-close effect should work pretty good.  And there's hardly anything that can wear out.  The most likely failure probably would be the one-way valve, and if that's the case I could easily make one using a bearing ball. Putting a tiny magnet in there to retain a steel ball would enable it to work in any position.  Of course, I'll have to use FEMM to simulate that 😃.






Tuesday, July 5, 2022

A deep dive: A broken soft-close drawer mechanism and finite-element analysis

 This post really highlights nurd-dom.

For some background, about 11 years ago we built our house.  We included soft-close cabinets for all the drawers -- the kitchen, all the bathrooms and the utility room.  At the time, the cabinet vendor we chose was including soft-close drawers at no additional cost, so of course we got them.

Ten years in, one of the two soft-close mechanisms in our most-often used kitchen drawer failed.  It was the silverware drawer.  The nifty latch mechanism that catches and releases the drawer at the right point broke.  It was just plastic and apparently not really up to the job.  That failure turned out to be pretty minor since the remaining soft-close device was still doing a good job.  However, about a week ago it also failed.  The latch thingie didn't break but it wasn't holding, probably due to wear.  It made a very annoying "sproing" sound every time the drawer was opened, when the latch let go.

Being a DIY kind of person I removed the drawer and examined the mechanism and figured out that it couldn't be repaired, so I just took the broken soft-close mechanism off the drawer slider.  Because the drawer no longer stayed closed I made a simple magnetic-latch using a counter-sunk ring magnet screwed to the back of the drawer and a wood block topped by a piece of steel, screwed to the back of the base unit.  It works to keep the drawer closed but it's really easy to close the drawer too hard so it bangs into the base unit, and in some cases has bounced back out.  I looked at some off-the-shelf soft-close replacements but the only ones compatible with the rest of our drawer hardware were exactly the same design as the one that had failed. I didn't have good feeling about that so decided to look elsewhere.

I started thinking about some kind of damper to slow that final approach so the drawer behaves more nicely when it's closed.  One my goals was to make something that is much more reliable than the original version, so I looked at a type of pneumatic damper to complement the (presumably pretty reliable) magnetic latch.

The basic idea I came up with was to make a piston and cylinder with a one-way valve so the piston could be easily withdrawn but the valve would close when the piston was being pushed back into the cylinder.  Air leakage around the piston would be slow enough to produce some back-pressure and slow the cabinet's entry at the end of its travel.  A rod attached to the piston would extend out so the back of the drawer would push against it and the piston.  To pull the piston out, the end of the rod would have a small magnet.  The magnet would be attracted to another steel plate, this time mounted on the back of the drawer.  Sounds a little complicated, but the idea was to use simple physical phenomena rather than a complicated and fragile mechanical latch mechanism to do the job.

I was pretty sure the damper would work, but the problem then came back around to the magnetic latch.  When the drawer pushes against the piston mechanism the force will initially be fairly high, so the latch needed to be able to exert enough force over about an inch's worth of distance to slowly pull the drawer in against the damper's resistance.  The force between a magnet and a flat plate, my basic magnetic latch design, has an extremely nonlinear relationship with regard to the distance between them.  It starts out very low and stays that way until the magnet is very close to the plate.  I wanted to extend the attractive force, to make my system work better -- or, perhaps, to enable it to work at all.

The thought I had was to make a different kind of steel piece to attract the magnet.  The idea was to make an iron cylinder with a Vee-shaped interior, where the magnet would travel inside to the bottom.  The iron would start out being fairly close to the magnet so the initial pull-in force would be sigificant, but to ensure that the magnet would continue to travel inside the cylinder its interior would be machined to have a V-shaped profile, becoming smaller as the magnet went inside it.  This way the magnetic force would act to continue to pull the magnet into the cylinder.

That geometry looked to be pretty difficult to get right -- it could take a lot of experiments to figure out what would and wouldn't work very well.  So I turned to software, in the form of a magnetic-field simulator called FEMM.  It solves magnetic field problems using a technique called finite element analysis, and one of its features is that it can calculate the force between a magnet and an arbitrarily-shaped iron pole piece.  Perfect....except that I wanted to easily change things like the angle of the V profile, the dimensions of the magnet and other features that I thought might make it all work better.  For simple problems you can create shapes by using your mouse, but that isn't very easy to use when creating precisely-shaped features.  Fortunately, FEMM also can be operated using a basic-like scripting language (called LUA), enabling me to create all the geometry with a program, then run the simulation and display the results, so I could easily change the physical design using a text editor and quickly evaluate the result.  For an example of the program's output, I offer this screen shot:


The intensity of the magnetic field is depicted by colors, where teal is very low and red is high.  In this model, the latch is basically shown from a top view, where the back of the latch is at the top of the screen.  The back of the iron pole structure has a hole in it to reduce the final holding force of the latch.  My simulations showed this worked to get the pull-in force to be comparable to the hold force, which in this case is the force needed to separate the magnet from the back of the pole piece.  It is NOT the same as the "lift capacity" of the magnet as specified by vendors like K & J Magnetics, due to the presence of the hole.

This is a theoretical study -- clearly, a structure with just the magnet and pole piece would be unstable because it would only take a minute offset one direction or another to cause the magnet to snap over to one side or the other of the pole piece, messing up my nice simulation work.  To prevent that, the inside of the pole piece actually will have a plastic insert (cast or machined) to fit closely between the pole piece and magnet.  That will keep the magnet centered so my simulations should be reasonable approximations to what actually happens.  I hope.....

I'm thinking that it may be possible to integrate the damper and long-range latch into one unit, but initial testing will be done using two separate parts to evaluate their separate functions.  One real concern is how to install the pieces correctly, to ensure proper operation.  When the drawer is installed it's almost impossible to see how everything lines up so that problem will need to be addressed.

More later :).


Monday, May 30, 2022

Is 2 taken to the power of one million minus 1 a prime number? NO! and I didn't have to calculate it to find out......I used some LSD

 Mersenne prime numbers are ones that have the form 2^N - 1.  Not all (actually relatively few) prime numbers have this relationship, and of course not all numbers that can be calculated using that formula are prime.  For a simple example, 2^4 = 16.  16 - 1 = 15, which is divisible by 3 and 5 -- so it's not a prime number.

You will have to read on to learn about the LSD.

Prime numbers are important when it comes to generating highly secure encryption codes, so they have been of interest for a long while.

For some reason, perhaps yet another sleepless night, I started thinking about powers of two, in terms of their digits.  More specifically, if the least-significant digit of them has any kind of pattern to it.  Some simple mental arithmetic revealed the answer, and it should become obvious when I write down the first few powers of 2, starting with N = 1:   2, 4, 8, 16, 32, 64,128, 256....and so on.  Looking at the Least-Significant Digit (the LSD, gotcha!!!) of this series we see:  2 4 8 6 2 4 8 6 .... so we have a sequence of 4 digits that endlessly repeats:  2 4 8 6 .... A little more mental gyrations and I came up with a way to predict what the first digit of any power of 2 is.  It does take a little more math, requiring the use of the Residue function.  Residues are calculted by getting the remainder of long division.  It's easier to show by example, like this:  take a look at 10/4.  Long division gives us a quotient of 2 because 4*2 is the nearest multiple of 4 that is closest (but not larger than) 10.  10 - (4*2) gives us the remainder, 2.  That is what the Residue function produces -- the remainder.  So if we examine the Remainder of (any whole number)/4, we find they can only be either zero, one, two or three.

Now let's create an array with the values [6,2,4,8] in it.  The array entries are a little different than what you might expect since the indices into the array are 0, 1, 2 and 3....4 isn't possible because its residue is zero.

Now let's determine what the LSD of 2 taken to the one-millionth power must be.  Some simple math says that the remainder of 1,000,000/4 is 0 (this will be true for any power of 10 greater than 1).  The first entry in the array is a 6, so we know that the LSD of 2 to the millionth power is a 6.

Recall that Mersenne primes have the form 2^n - 1.  If we subtract 1 from 6, we get 5, and all numbers ending in 5 are divisible by 5.  Therefore, it is NOT a prime number.

For the same reason, we also can say that any number calculated by evaluating 2^(10^n) -1 also are NOT primes, as long as n is greater than 1.

It so happens that we can use a similar but slightly more complicated scheme to determine what the next-most-least-significant digit (NMLSD) of a power of 2 is.  I won't go into much of it here except to say that the sequence has a length of 20.  The NMLSD of 2^1,000,000 is a seven.

After that the sequences become ever-longer so the approach becomes less and less viable.  If nothing else, it becomes necessary to accurately calculate some pretty large numbers, just to examine their smallest parts.

Friday, May 13, 2022

Touch Sensor Update

In some ways it's been a rough year, what with Covid and a rental-rehab project we found ourselves saddled with.  Supply-chain and contractor issues caused problems; and in many cases we found that the most expedient way to move forward with the project was to do the work ourselves.  We did a lot of research before embarking on any of the major projects we had to do.  Anyway, all that delayed work on my touch sensor -- but now that we've got the rental fixed up (and rented), I've had time to work on some long-delayed personal projects.  That includes the touch sensor that I designed a PCB for.  I did have time to order the PCB and assemble one, but that's about as far as it got until recently.  I finally was able to hook up my 4-point sensor connectors and test the thing:  and, what a surprise -- it worked, right off the bat.  

The wires connecting the modified battery-charger clips to the circuits are a mess, since I used individual wires but I have some cable management stuff I can wrap around them to make it all a little less like an octopus waiting to snare me when I pass by.

Now I'm working on a really sad antique dresser we bought a few years back.  When we bought it we didn't realize what bad shape it was in, so it needs some work -- to put it mildly.  I think a child may have used some of the drawers as a ladder and stepped through the bottoms.  The dovetails on the lowermost drawers were loose, and the rabbets on several of the side pieces (the ones that hold the bottom piece in place) were split or just plain broken off.  I also had to reinforce the sides for a couple of them.  It has water damage, too -- the oak veneer on one side of the case has delaminated.  I'm not going to try to repair that for now -- it basically was purchased to put in a guest room so visitors should just appreciate having a dresser, however it looks (as long as it is usable, anyway).  The feet are a mess, too -- three have the remnants of some sort of steel foot, and there's nothing at all on one of them.  The steel will be pretty bad for scratching our wood floors so there's some work to do there before the dresser is put into service.  I learned a lot during our rental rehab w/regard to doing stuff like trim work so that will come in handy for this project.

Friday, May 6, 2022

Oxygen, the master vampire element

 As a preface to this entry, I'm going to write about my first real experience with what I now call the master vampire element, oxygen.  At the time, I was working on a different approach to etching gold.  Since gold is a relatively inert element, it takes some doing to etch it -- basically, turning the metal into a salt of some kind.  I was thinking about gold chloride.  Aqua Regia is a commonly-used etchant for gold, made by mixing nitric acid and hydrochloric acid.  Thing is, the mixture is unstable because the two acids react to form something called Nitrosyl Chloride -- and it quickly decomposes.  It also takes some time for NOCl (its chemical formula) to form so you're running a race between getting the etchant working and then using it before it decomposes.  There also are a number of different ratios given for the ingredients, probably because they come in a number of different concentrations.  So I had some interest in coming up with something that was more stable and more reproducible.  I had concentrated hydrochloric acid available, the same with 30% hydrogen peroxide, so I had the thought of combining the two to see how that would work.  The idea was that the peroxide would oxidize the gold and then the acid would react with the oxide to form its chloride.

Well, my new etchant sort of worked but it turned out to be even more unstable than aqua regia.  The REALLY interesting part was that my mixture quickly decomposed by releasing a green-yellow gas:  chlorine.  Well now, what was that about?  It didn't take long for me to realize that the hydrogen peroxide had done it, using its extra oxygen atom to grab two hydrogen atoms from two molecules of hydrochloric acid (HCl), forming one molecule of water and one molecule of Cl2.  Up to that point, I had thought that chlorine was a pretty strong oxidizer and was pretty safe from being affected by oxygen:  but my little experiment blew that notion right out of the water.  BTW I performed my experiment with just a small quantity of the two materials, under a fume hood so no harm done.

Now I want to talk a little about the idea of "valence".  Fundamentally, it means how many electrons an element in a compound has either gained or lost:  or wants to gain or lose.  Many reactions are all about electrons.  For instance, in the water molecule we have two atoms of hydrogen and one atom of oxygen.  Oxygen has a valence of 2, because it "wants" two additional electrons to fill its outer shell (and each hydrogen atom only has one to provide, so it takes two to form a stable molecule).  And oxygen REALLY wants those electrons, as shown by my little experiment.

It gets even more interesting though.  Looking at chlorine (Cl), it has a valence of 1 when it combines with things like sodium to form sodium chloride, table salt.  In that case chlorine is the oxidizer and sodium is the reducing agent.  But oxygen is such a powerful oxidizer that it can actually wrest electrons _away_ from chlorine, which in itself is no slouch as an oxidizer.  In fact, oxygen is so powerful that it can abduct SEVEN electrons from chlorine, forming perchlorate compounds.  They are used to make explosives in fireworks.  Perchlorate compounds themselves are extremely powerful oxidizing agents, so if mixed with things like charcoal and sulfur they are more than ready to go boom.  Perchlorates are not the only ones that are infected by the bite of oxygen.  Chromium trioxide (CrO3) is notable because it is in a +6 oxidiation state (3 * oxygen's valence-of-2 = 6).  Squirting acetone on a pile of dry chromium trioxide powder will instantly cause the acetone to burst into flame because it's just ripped apart by the combination of hexavalent chromium and oxygen.  Another good one:  the permanganate ion.  In that one, manganese is in a +7 oxidiation state.  By now it  shouldn't be much of a surprise that it also is an extremely powerful oxidizer.   It will react with a sugar solution at room temperature and turn it into black sludge in very short time.  When bitten by oxygen nitrogen suffers a similar fate and as a result becomes usable for things like explosives (think nitroglycerine) and rocket fuel.

In these instances, the base elements -- chlorine, chromium and manganese -- range from being a fairly powerful oxidizer to "not in my wheelhouse" -- but oxygen bites 'em and they turn into vampires themselves.  That's why I call oxygen the master vampire, because it can affect otherwise innocent elements and turn them into monsters, too.


Sunday, February 13, 2022

Touch sensor for lathe and mill setup

 Some time ago I learned about a machining web site created by Rick Sparber:  right here.  He has a number of interesting articles about DIY machine accessories and improvements, but one in particular caught my attention -- a simple touch sensor that can be used to set up a metal lathe or mill for machining metal.  

The design can detect a small change in already-low resistance.  The basic idea is to measure the resistance between the cutting tool and workpiece being machined.  When the cutting tool is NOT in contact with the work, the current path is through the machine -- the spindle bearings being the major source of resistance compared to the body of the machine.  When the tool comes in contact with the work, that is a lower-resistance path -- and that is the basis of the touch detector.

 It looked pretty good, but being an electronics kind of fellow, I thought there might be some room for improvement.  The idea was to change the design to allow 4-terminal or Kelvin sensing.  Rick's design uses the same wires to force current through the lathe/mill AND sense the voltage change when the tool touches the workpiece.  This means that the design is sensitive to contact resistance at the tool and workholder ends.  The 4-terminal approach avoids this problem by separating the force and sense connections.  A good article regarding Kelvin sensing can be found here .  I hasten to add that Rick has some more-refined designs that DO implement 4-terminal sensing, and interested readers should look into them, particularly if wanting a good milliohmmeter or CNC-compatible touch sensor.  But for various reasons I think my design is a worthy alternative to his simplest design, and I offer it here.

My design schematic:


The design is quite similar to Rick's, including the automatic power-up scheme implemented by Q1.  The major difference is how the inputs to U1-1 and U1-2 are connected.  They are routed to separate sense lines (although my design does permit simpler 2-wire use if that works OK on a particular machine).  Rick's original design used a couple of spade connectors and super-magnets to attach the touch sensor to the cutting tool and workholder, but that's not compatible with the 4-terminal approach.  One of his other touch sensor designs uses two miniature battery charger clips with the sense connections brought in via an insulated contact, and that's what I'm using with my design.  I drilled a hole in the jaw of each clip large enough to accommodate a 1/4" nylon screw, then chucked the screw in my lathe and drilled and tapped a #4-40 hole down the center of it.  A #4-40 brass screw was threaded into the nylon screw, then the nylon screw was attached to the jaw with a nylon nut.  The outside end of the brass screw has a nut to attach a spade connector for the sense line.  If it's not clear from my explanation, the brass screw head forms a Sense contact.  Experimenting with different-sized end mills suggested that it would work better if I added a washer underneath the brass screw, so I also did that.

I haven't had a chance to debug the design yet, but once that's done my plan is to make it open source.  More on that later....