Friday, January 30, 2015

Wilson's Theorem, Prime Numbers, C++, and finding a livable IDE

So, every now and then I discover tidbits of academically interesting information that inspire me to accomplish something. More often than not I give it a valiant effort, and shelve the project at some random stage of completion, uncertain if it will ever be finished.

A few months ago I saw Numberphile's videos on Wilson's Theorem. This was such an event. Wilson's theorem basically states that you can determine if a number is prime by seeing if the factorial of one less than the suspected prime, plus one, is divisible by the suspected prime. The formula would look like: ((n-1)! + 1) % n = 0.

To give a simple example: n = 3.
3 - 1 = 2.
2! = 2.
2 + 1 = 3.
3 %  3 = 0.

x! is a way of writing "factorial of x". Factorial means to multiply up all the numbers prior to and including the number in question. 2! = 1 x 2. 3! = 1 x 2 x 3.

% is modulo, which means to find the remainder of. The extrapolation of this would be 3 / 3 = 1, so 0 remainder. 7 % 3 = 1. (3 goes into 7 twice, leaving a remainder of 1.)

Here's Numberphile's Videos on Wilson's Theorem:

I scribbled down the rearranged formula for Wilson's Theorem on a piece of paper when I saw the video. Then the next day I wrote up some pseudocode to give a general outline of the logic needed to process the formula. Then I put it on a shelf and left it, for months.

I came back to the piece of paper a few days ago and decided it sounded like something to look into since I would be programming again shortly (see Arduino Binary Clock projects, serial internal oscillator one finished, standalone upcoming at time of writing this). After a few hours of writing up the basics of the program in C++ (my preferred computer language) with VisualStudio2013 (my very much NOT preferred IDE) it became painfully apparent things weren't working well. Why was this? Well, Wilson's Theorem uses incredibly large numbers because of the factorial function. By incredibly large numbers I mean that simply doing 22!, which is needed to test if 23 is prime (it is) exceeds the intrinsic capacity of a 64bit computer. I realized that I would need a method of working with such large numbers, a guestimation of which is 2^2048, on a 64bit machine.

Lots and lots of searching, asking friends, and plugging away yielded that there are special libraries for this exact purpose. Mostly they're used in cryptography for encryption and data hashing. I found several libraries that looked like they would work, but only one of them had a downloadable file that was recognized by my Windows 8.1 system; BigInteger. Many more hours of tinkering and searching around I find that it is not precompiled and needs to be directly added to your project and compiled with it or compiled in your IDE or on a Unix computer for use. VisualStudio2013 was not letting me just add the files and then compile with my project, so thus began the hunt for a better IDE.

I asked my friends and asked online on one of the technology forums I am a veteran of. I settled on Orwell's Dev-C++ as it looked to be a good fit from both my own investigation and external recommendations. I had also tried out Code::Blocks and CodeLite, but they didn't seem as intuitive or pliant to my needs. A few more hours of getting myself accustomed to the new IDE and some exceptional pointers from my professional programmer buddy Jack and I was up and running.

Here's the grand result: Two executables for windows machines which use Wilson's Theorem.
1) Wilson's Theorem Primality Checker - this lets you enter a number up to 2,147,483,646 ((2^32)-1) [not recommended doing so though, haha] and it will tell you if what you entered is a prime number or not.
2) Wilson's Theorem++ - this lets you enter a number up to 2147483646 ((2^32)-1) and it will list off every prime between 1 and that number as it finds them.

I'd stick to values below 20,000 unless you want to leave your pc running a long time as values over 5000 take a bit to process. You'll be happy to know you can just "X" out of the command window if you're tired of waiting for it though. It also only uses a single core of your processor, so it shouldn't crash any modern multi-core system.

Download Links:

Sunday, January 25, 2015

Arduino Binary Clock - Serial Output

An upcoming project of mine is a standalone Numerical Sexagesimal Binary Clock that will run on Arduino, and use a high accuracy RealTimeClock to keep time. In the mean time I've worked out a simple program that uses the UNO's onboard 16MHz system clock (oscillator) to keep time. The resultant one Hz events are tallied sexagesimally and then converted to binary. Both binary and decimal outputs are sent to the serial line for viewing on the arduino compiler's serial monitor.

Nearly all, if not all currently made "Binary Clocks" use Binary Coded Decimals (BCD) to display time. BCD is when you use binary for each digit of a sexagesimal time. This is popular because it is much simpler to implement, most people can read easy since all the "binary" numbers are low values, and it adapts easily to graphical and LED display.

Here's an example of Binary Coded Decimals: 1's represent Lit LEDs, 0's represent Unlit LEDs


You read each vertical column as if it were a true binary number and then assemble the sexagesimal time code. So, the above timestamp is assembled from the binary numbers:

0000 or 0
0010 or 2
0011 or 3
0111 or 7
0000 or 0
1001 or 0

This is not how my binary clocks will work.

My clocks will output true binary time; 02:37:09 will be displayed as 0010:100101:001001.

So, check back in the future for the project post for my standalone arduino binary LCD clock. Until then, enjoy messing around with this bit of code!

NOTE: You set the time at point of compiling and uploading, but the arduino doesn't actually begin keeping time until the serial monitor is opened. So, set the time about 30sec ahead, upload, and then open the serial monitor just before it is the set time. On my system it takes about two seconds for the monitor to initialize and the arduino to sync up to it. I use for reference. You could also just set the time for the next minute and watch as it rolls over, then start the serial monitor; this would be less accurate by a few seconds + your response time.

BIGGER NOTE: The arduino's intrinsic time keeping ability is heavily limited by the accuracy of the 16MHz clock. Mine is slow by about 5 seconds per hour, or 2 minutes per day. I've added a few lines that wait for until the arduino has been running for 12 hours and the current minute is near the end of the hour, then it advances the minutes one minute to compensate. Depending on what time it was when you uploaded and started the serial monitor it may have to wait an extra hour until correction. So, this doesn't really fix the inaccuracy problem, but it lessens it greatly, from 2 minutes per day down to no more than ten seconds per day. Your mileage may vary. There's a reason this was just an exercise in getting the decimal to binary conversion working well.

Monday, January 5, 2015

The USSTCC: Universal SSTC Logic Controller

Sig's Universal SSTC Logic Controller - The USSTCC!

  • A universal solution to the question of "What driver should I use for my Solid State Tesla Coil's Half or Full Bridge Inverter?".
  • Smaller footprint than competitors yet can drive even the largest TO-264 Power Switching Devices.
  • Operates on either Secondary Base CT (current transformer) or antenna based feedback, for maximum flexibility.
  • Very High Noise Immunity - will operate fine even in "floating ground" implementations.
  • Greatly reduced parts count. This means it is inexpensive to build and has less points of failure!
  • Tested Frequency range of 100KHz to 1MHz! *Additional heatsinking may be required for very high frequencies.
  • Automatically locks on to the resonant frequency and drives the inverter in sync even under dynamic loads!
  • Features a powered Expansion Port so you can branch out and add additional functionality like Modulation!
  • Operates from 12VAC to 24VAC or 14VDC to 33VDC at 2 Amps input current. Power supply not included.
  • High Quality Professionally Made Printed Circuit Board with Gold-Plated Through-Holes and Solder Pads.
  • All Through-Hole construction and Clearly Labeled Silk-Screened Solder Mask for EASY SOLDERING!
  • High Quality Screw Terminal Input and Output connectors for easy assembly to or disassembly from your Tesla Coil.
  • Pre-Drilled Mounting holes on Printed Circuit Board.

The data file includes invaluable information, schematics, diagrams, and instructions related to building your very own Solid State Tesla Coil, even without the use of the USSTCC board.

The user is required to possess and exercise a working knowledge of proper soldering technique and understanding of basic electronics principles. The user will need to know how to identify components and their orientation markings. NO BOARDS COME ASSEMBLED.

No Tesla Resonators, heatsinks, mounting hardware, current transformers, basic tools, or wiring is included with any options. The User must provide all the necessary equipment and supplies for proper construction and installation.

Users must exercise caution and observe safe electrical guidelines and codes when wiring up the completed controller board and any inverter (half or full bridge). Buyer assumes all responsibility for the use, installation, and construction of the products featured here. Risk of injury and even death is always present when working with high voltages.

Return Policy:
Returns will only be given for unused, unsoldered, new, and undamaged boards and components.

These boards are still available for purchase at $15USD/board. Please send email to purchase. Payment by Paypal ONLY.

Click to Inquire about Purchasing a USSTCC Board

Video of USSTCC in operation:

Update - 2016-1-16
I wanted to copy the following text from my FAQ post and correspondence so there is zero ambiguity for anyone looking at this from the perspective of a new or potential user.
"Now let me understand some components, I have decided to use your logic board.
What exact piece of the puzzle does this include? What other components do I need to design and build myself. "

Okay, before listing off what it includes, let me state plainly what it and its associated files do NOT include, in other words things you need to source and build yourself:

1) Bridge Inverter. *
2) AC power cord for Bridge
3) AC power cord for USSTCC's step-down transformer
4) Secondary Resonator
5) Primary Coil
6) hookup wire
7) GDT; wire and core *
8) secondary topload (doesn't have to be fancy - salad bowl!)
*note I do have most of the suggested parts for these listed, things marked with asterisk have detailed instructions and parts lists.

What does the USSTCC Board include? It includes one bare USSTCC printed circuit board and all documentation required for proper construction of a working SSTC and lifetime Q&A help service.

Now, a better question; "What parts of the 'SSTC puzzle' does the completed USSTCC encompass?"

The USSTCC board takes care of the entire Low Voltage power supply supply, feedback processing circuitry, signal amplifier and splitter, add-on (interrupter & modulator) interfacing, and Gate Drive requirements of any SRSSTC operating in any mode. You add a bridge inverter, GDT, and completed resonator and have a fully working SSTC. All of the recommended parts for the bridge inverter and GDT are listed in the BOM files with their ordering numbers direct from reputable suppliers.

The only electrical components you need to pick and determine source of yourself are the AC power cords/plugs, GDT wire (22ga solid core, insulated (not enameled) to >300V, 2 or 3 colors), rosin core eutectic solder, and primary coil wire (10ga finely stranded copper, insulated to >300V - silicone if possible, cheap on eBay used for RC hobbies).

The physical components you'll need are coilforms, polyurethane, various mounting hardware (screws, nylon standoffs), etc.

Sigurthr's DRSSTC Calculator

This is a simple CLI (command line interface) calculator program to assist you in planning and designing your Doubly Resonant Solid State Tesla Coil. There is no installation process necessary; simply download the .rar, unpack it to a directory of your choosing, and run the .exe.  It is for Windows operating systems only.

Please note; only enter numerical characters when prompted for data. Entering letters or symbols will result in the calculator program crashing.

A README.txt file is provided in the .rar to explain the calculations behind the program and help the user get accustomed to its operation.

The program intakes simple parameters such as: DC Bus Voltage, Primary Inductance, Primary Capacitor Voltage Rating, Capacitor Derating Percentage, and Resonant Frequency. It then computes the Maximum Possible Peak Current and Voltage for the Primary Tank for the maximum usable Burst Length before the capacitor voltage is exceeded.

DRSSTC Calculator Download

Update: 24/2/2015 I'm pushing a new version of this up to the download repository because it was brought to my attention that some users are still experiencing the missing .dll error. If you had any troubles previously, please try redownloading the file and give it a go again. My apologies for the inconvenience!

SigurthrEnterprises Website is CLOSING, all files and data being moved to THIS BLOG!

Hey everyone!

2014 has been a rough year, filled with serious medical and financial problems, and more than its fair share of stress. 2015 is here now and I'm beginning to pick up the pieces and restructure my life where needed. Part of the process is saying goodbye to my less-than-successful .com website. Though it got the majority of the traffic of my online presence, I just can't justify the expense as it generated very, very little income (less than one month's coffee for many folks).

Out of appreciation for those who did visit it and have enjoyed my data files and postings, I'm moving all of that data to this blog for permanent backup and access. Everything on the site will be available here. I still have USSTCC boards available, and still have many projects in the works.

Thank you all.