Tuesday, January 25, 2011

Hyperthreading and CFD

So I just performed a little experiment testing effect of Intel's "hyperthreading" (HT) technology on CFD solver speed. HT, or as some have called it, "hype threading", increases multitasking performance by trying to more efficiently allocate processor resources. One HT core is seen as two cores by the computer.

So I would expect that CFD solver speed would not benefit from HT, as opposed to disabling HT. My computer contains an i7 2600, a four-core processor. I decomposed the HT off case into four domains (one for each core), and of course I decomposed the HT On case into eight domains (one for each virtual core). The usage of all of the processors at 100% and that the right number of cores was perceived by the OS was verified by checking Ubuntu's System Monitor application. HT was enabled and disabled in BIOS.

In OpenFOAM, running the same exact case, the run times for HT on and off were:
HT On (8 virtual cores): 0.0692875 simulation seconds in 6213 real-life seconds.
HT Off (4 cores): 0.0692822 simulation seconds in 5154 real-life seconds.

So, as expected, HT does not give performance gain, but in fact imparts performance loss. We should expect similar performance because it is the same hardware, and computational efficiency usually decreases on a per-core basis with more cores (time is wasted in inter-core communication, etc.). Also, we see that the processor performs as expected (as four normal cores) with HT disabled.

Of course, I am not saying anything about HT's usefulness for multitasking, which is what it was designed for.

Thursday, January 20, 2011

PIC servo control with ADC Input

I have not used PIC in a long while, as it has been replaced by the Arduino. The reasons are that I have to program the PIC at a lower level of abstraction, the PIC does not have all of the built-in convenient functionality of the Arduino, and the PIC is harder to debug.

Even so, I have programmed a servo controller with a PIC that takes in an analog value from the Arduino (via PWM, a rectifier capacitor can be placed), and translates this to a 50 Hz PWM servo signal with pulse widths ranging from 0.6 ms to 2.4 ms for the control of a HS-311 servo. If your servo requires different pulse lengths it is easy to change in the code.

The reasons for making a PIC servo controller are two:
-The PIC is much cheaper. Ordering from Microchip I can get the PIC16F690 for less than $2 a piece.
-The Arduino servo library control gets messed up when you change the timer settings. On the same Arduino I wanted to control the servos, I changed the timers so that the PWM operates at above 30 kHz.

I programmed a PIC16F690 using PicKit 2 (there is now a newer PicKit 3) and the free MPLAB IDE using the also-free HITECH compiler.

The software utilizes Timer 0 for the 50 Hz signal refresh rate and Timer 1 for the pulse length. This was done because a higher resolution of pulse width was achieved with Timer 1. Several very useful calculators for finding the Timer offset value settings to correspond to the desired times can be found by Google searching 'PIC timer calculator'. I have one that I got a few years back, but I cannot seem to find it now; maybe it updated.

Friday, January 7, 2011

The manual wire wrap tool: a microelectronics hobbyist's best friend for solderless connections

Tired of soldering? Tired of breathing in potentially toxic fumes? Then the wire wrap is just for you. Look it up on Google for pics and how to use it (and where to buy!). It's awesome. I just discovered it. It allows you to effortlessly strip and coil thin wire (I was using 30 gauge, for PIC pin outputs) tightly around a thicker pin (DIP extensions, those common square-cross-sectioned headers, etc.). Surprisingly (to me) strong in tension; could not pull it off without breaking whatever it was attached to first. If you venture away from PCB boards, this is a must have, especially since it is a simple and cheap tool.

Thursday, January 6, 2011

For those who want to start CFD (Computational Fluid Dynamics) simulations...

I started CFD in OpenFOAM with no prior experience in CFD. I did not even have the Navier-Stokes equations memorized or anything. Do not write it off as impossible without even trying, as I had.

A quick and useful introduction to CFD in general is available here.

Once you have some grasp of what CFD is about, you can move onto installing and using CFD programs. A great resource for all steps of the whole simulation process is CFD-online. This website was essential for enabling me to run my own simulations.

I would love to elaborate on whatever you cannot find in the two resources I described above. Please comment if you have any questions at all, and I will be sure to reply in a short time.

Wednesday, January 5, 2011

Correctly using PIC in a device disconnected from the PicKit/computer

So I was trying to switch transistors with outputs from the PIC pins, for a project I will post probably tomorrow. The output voltage (digital I/O) was like .6 V when the PIC was running on a 4.5 V source. All that was needed was to tie the MCLR pin high (I used a 15k Ohm resistor). The pin voltage then went to 2.8 V, which was sufficiently high to finally bias the transistor base. I do not know why it is not equal to 4.5 V, but I do not really care presently (EDIT: Ah, it was just a software error). So for basic functionality for a PIC used on a standalone circuit (i.e. taking it off a PicKit dev board), you just need a .1uF capacitor across power supply anode and cathode and the MCLR pin tied high.

Of course, you could just disable MCLR. However my c code compiler for PIC (PICC Lite) does not recognize the bit as MCLRE, or the CONFIG register. So... if you know put it in the comments please.