SB Demon!

What is SB Demon?

SB Demon, a very confusing name indeed. Some of you may think it as a cousin of Maxwell’s demon. Some of you may even go further by thinking it as a demon of Stefan-Boltzmann (if Maxwell would have a demon, then, what’s wrong with Boltzmann?), a new discovery from some unreleased papers or some secret letters!

Let me clarify it: It’s NOT so royal thing. SB Demon stands for Stefan-Boltzmann Law Demonstrator device.  It’s just a special purpose datalogging system with a built-in USB interface. An amateur’s experimental device to have some adventure  with Stefan-Boltzmann law, with a flashlight lamp (commonly called a torchlight bulb), a PIC microcontroller, some programming codes and some sort of electrical circuit. 


There are a number of techniques to support the Stefan-Boltzmann law experimentally and to measure the Stefan-Boltzmann constant apart from theoretical results (i.e. σ = (2*Pi^5*k^4)/(15*c^2*h^3) ). The simplest procedure is based on an incandescent lamp. The experiment is performed by the undergraduate students of almost all Indian universities. The temperature of the filament is measured by a direct (using an optical pyrometer) or an indirect process (measuring the resistance and comparing it with a reference resistance at known temperature), and the input power is controlled by a variable power supply. For a low power lamp, conduction loss through the leads and convection loss (for gas filled lamps) are ignored and all the input power approximately goes into the radiating channel. Reference-resistance-at-some-known-temperature method is preferred in undergraduate labs. An optical pyrometer or a monochromator with photodiode may be used for more precise temperature measurement but not used in (poor man’s) undergraduate labs.

The apparatus, used mostly, is just a simple variable power supply with an ammeter and voltmeter, packed in a big box. I tried to do the same using a microcontroller which would calculate the exponent and possibly the Stefan-Boltzmann constant with minimal human interaction. The heart of the device is a PIC microcontroller. A low-pass filtered PWM (Pulse Width Modulation, essentially a square wave) output from the microcontroller is passed through some transistors, which forms the variable power supply to drive the lamp. The potential difference across the lamp is sensed by the microcontroller’s onboard analog-to-digital converter (ADC), the current through the lamp is sensed by a shunt resistor, amplified by a high-side current sense amplifier and is fed to another ADC channel. We’ll get back to it in details later.

A look into the device

DSCN9735The device

Before going into the details, Here are the outlines first:

1: It saves the calibration data, either from the specified cold resistance or from the draper point as determined by the user.

2: The user enters the number of points to save.

3: The user increases the PWM duty cycle by pressing the INC button, so the power delivered to the lamp increases. The user may use the DEC button to decrease it.

4: Now the user presses the SAVE button to save the values.

5: The user repeats step 3 and 4 until the specified number of points are saved.

6: Finally the device shows the regression results, i.e. the value of the exponent of T and the value of A*ϵ*σ(surface area of the filament times the emissivity of the filament times the Stefan-Boltzmann constant).

Now, Let’s take a more closer look with the screenshots:

 ScreensLCD typescripts

After a quick splash screen (see SS1) the device asks for the mode of operation. Two modes are available (see SS2). In the first mode, DP or draper point, the user carefully sets the point where the lamp just begins to glow (i.e. the filament temperature is about 800K), so that the device get calibrated. In CR or cold resistance mode, the user specifies the of CR, which is the resistance of the filament at about 300K. So far, SB Demon can’t determine the CR by itself, the user must measure it by an accurate measuring device (essentially, a device capable of measuring low resistances like any digital meter specialized for this purpose or a bridge, general purpose multimeters are not capable of it). I didn’t measure the CR of the lamp because I don’t have enough precision instruments. Though, the CR mode with an accurately measured CR would produce more accurate results than the DP. Now the user presses the INC/DEC button to increase/decrease the voltage until the the draper point arrives (see SS3). At that point the user presses the OK button so that the point is saved.  For CR mode the user sets the cold resistance of the lamp (as measured by some external instrument) by the INC/DEC button.

In the next step it asks for the number of points to save (see SS5) . We can select 5 to 30 points, the default is 12.

Next, it shows the voltage, current, resistance and the estimated temperature values (see SS6). You can increase/decrease the voltage by pressing the INC/DEC button. By default the data acquisition occurs after a delay of 100ms whenever the INC/DEC button is pressed. The 100ms delay is to ensure that the data acquisition takes place in steady state only, and not in transient state. Though a continuous read mode can be enabled by pressing the OPTIONS button, in this mode data acquisition occurs at every 10mS. The user saves the desired values by pressing the SAVE button. And finally, after saving all the points, it shows the regression results (see SS7).

I’ll post a video of it later.

vlcsnap-2011-06-18-01h35m44s207False colour of thermal emission detected by CCD

This is not only a beautiful photograph, notice the blue tint of IR emission, the false colour, as detected by my digicam’s CCD sensor. Here’s another example.

 DSCN9400Another example of false colour detection

What’s inside?

Take a look at the schematic first:

Sch_low_res  The schematic (click to enlarge)

If you’re one from the newbie league, then I’m explaining a little for you. But if you are someone from the experts’ community, then please comment me your suggestion(s).

See there, the PWM duty cycle is varied (increases at INC and decreases at DEC) by the microcontroller firmware. And the PWM signal is filtered by a second order low pass filter. Then an NPN transistors inverts the filtered signal and sends it to a PNP power transistor. Which powers up the lamp through a 100 milliohm current-sense resistor (R4). The small potential drop across the resistor is amplified by a high side current sense amplifier (called a high side CSA) MAX4372. And the voltage across the lamp is divided one-third by a resistive voltage divider (R2, R3). Both of them goes to two ADC channels of the microcontroller. MAX873T provides 2.5V reference voltage to the ADC module through the VREF+ pin for accurate ADC results.

DSCN9709Inner view of the box

This looks messy, I know, cluttered with wires and hot glue! But anyway it’s working. That surprises me how this mess closes a full path for the free electrons to walk, run, twist, spin through the wires and finally die at GND!!! I soldered-desoldered-resoldered the perfboard, for more than 20 times at some places. MAX4372 and MAX873 are SMD components, I made a small PCB (see the above image, Ref/CSA PCB) to solder them. A single PCB would clear up the mess to a beautiful electronic landscape. 





Photograph of some pre-prototype.

Programming the PIC microcontroller

So far, in my 3 years of PIC programming career, I’ve used many compilers for writing codes. I’ve used Microchip’s C along with their MPLAB IDE, MikroElektronika’s MikroC and MikroBasic, PICC compiler, Proton IDE, Swordfish Basic etc. C has the most powerful and compact instruction set, I swear, but for writing such a long and complex code like this, I chose Swordfish Basic because of its highly structured and modular nature. It’s a fairly long code, consuming 770 lines in the IDE and filling 65.45% of the PIC’s program memory (i.e. ~20.9KB out of 32KB). Previously I’ve written many codes for PICs (the most interesting among them was my first line following robot), but I’ve never written such a long code like it. After many faults, compilation errors, culprit LCD scripts (mainly the custom symbols like Ω), PWM issues, unrecognized USB device error due to incorrect interrupt and PLL settings and many other known-unknown hassles (some of them are still unknown to me, trial-n-error based on a little guess-work was the only option to tackle them), finally I came up with the final code after working patiently for more than four months, programming-reprogramming the microcontroller over 500 times! The hardware was fairly complex for any simulation software (like Proteus VSM) to handle efficiently and in near-real-time. I tried them; they worked great for simple codes with simple hardware setup but for this device, the simulations were painfully slow on my old Pentium 4 based PC. So I quitted simulation and started with a breadboard and some passives from the junk-boxes.

swordfishScreenshot of the Swordfish IDE

I’m not going into detailed discussion on the code here, if you know the basic syntaxes of Swordfish IDE, you could mean the code patiently. If you are not a PIC geek, just skip this coding part and continue.

IMG_0260See the DIY PICKit2 programmer

I used my DIY PICKit2 programmer to program the microcontroller. PICKit2 is a standard tool from Microchip. But I built it myself (with so much memories of my class xi days embedded in it!)

The USB functionality – For more adventure

First thing  to mention that the SB Demon is a USB device of HID (Human Interface Device) class, it’s not a CDC (Communication Device Class) device. CDC is simple to manipulate in a microcontroller based system (or using a very popular FT232 to create a CDC interface from basic USART), also needs little or no PC side programming, as it renders itself as a virtual serial (or COM) port. It is generally interfaced via any terminal application (like the Hyperterminal on Windows XP). It’s easy to use but not so reliable and strongly outdated. Even Windows Vista and 7 don’t have inbuilt driver for CDC devices.  So, I chose the HID. Which needs a sophisticated programming on both sides. I played a lot with the codes for it, and finally succeeded. Now, I’ve a fully working USB HID datalogging system. This special purpose datalogger can be modified to suit with all datalogging applications.


InterfaceFocused   A closer look to the interface

Here is a closer look to the interface software. My goal was to setup a USB HID class host software and to integrate with Wolfram Mathematica, my most favourite computational software. I wrote this in Microsoft Visual Basic 2010 using an USB HID template. The interface is mostly self explanatory. The + and – buttons are to increase/ decrease the PWM duty cycle. The end button turns the lamp off and ends data logging. The ‘Save Log’ button exports the log in .txt format. The ‘To Mathematica’ button exports the data in a mathematica notebook (.nb) file. Which opens a new room for analysis of the data. Undoubtedly, this is the most interesting part of the project to bring a real world data directly to a computational software.  We’ll take a part-by-part look towards it.

The exported mathematica file contains 5 matrices containing the saved values of voltage, power, current, resistance and temperature (V, P, I, R, T).   MAT1

For Stefan-Boltzmann law, we’re interested in T and P. Now we’ll construct two matrices. One with P and T (TP) for non linear regression and another one with logP and logT (lTP) for linear regression.


Performing the linear regression first:


Then the nonlinear regression: note that without the MaxIteration –> 200 (the default is 100) option, the NonLinearModelFit will fail to converge to the required accuracy. It’ll generate an error “NonlinearModelFit::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations.”.


See the PDF file for the complete notebook.

Fullscreen capture 10312011 24514 PM.bmpThe .txt log file in notepad

The above image is a cropped screenshot of my desktop showing the log text file in notepad. You probably have recognized the brilliant face of Anne Frank right next to the notepad window. I wonder did she ever dream that her letters to Kitty would be so celebrated worldwide, when she was killed in a 1945 Nazi concentration camp? She logged her days and nights, which now stands as an immortal description of that days of the boys in the striped pajamas. Find the full image here

Problems and improvement options

However, there are some problems (mainly with the power supply) associated with the design, which I uncovered later.

The PWM scheme used here might be good enough for controlling brightness of an array of LEDs to create stunning lighting effects or to generate a thousand of colours using a RGB LED. But it is not enough for precision measurement. An NPN transistor inverts the filtered PWM signal (it’s a dc, not actually a signal) and then passes it to the lamp through a PNP pass transistor BD140. I’d liked to use a P-channel MOSFET instead, but a logic level MOSFET was not available in my area. The device is neither a true constant voltage source nor a true constant current source. As the lamp glows on the voltage slowly increases as the resistance of the lamp decreases. Though, the deviation is so small that it can almost be neglected. But truly, this is an unwanted effect.

ltspiceLTSpice simulation of the PSU (Note that this is not the real scenario where filament resistance R_Load increases as the voltage increases, in that case the transistor stays active from 10% to 60% duty cycle, i.e. nearly 0.6V to 3V.)

However, this effect might have a little negative impact on the overall performance, but this is a major design fault of the power supply section, which I uncovered later. I liked to use a MOSFET which is easier to design, has better efficiency (than BJTs). Modern power MOSFETs have very low on resistance RDS(ON) that reduces the voltage dropouts. But I was forced to use a power transistor instead of it because of availability. At that time (about a year ago from now), I didn’t know the mathematics behind biasing of a transistor (now I know how simple it is). Hence, the transistor in the design is not biased properly to stay in active region throughout the entire range of the PWM duty cycle. The transistor stays in active region in between 16% to 63% duty cycle. Beyond of which the transistor gets cut-off or saturated. Though the BD140 can handle a maximum collector current of 1.5A, but even at 500mA it becomes very hot (almost impossible to touch, maybe a better heatsink was needed), tends to shift up the operating point and gets saturated at 63% duty cycle. . This faulty biasing effectively reduces the voltage resolution… Another unwanted issue! But truly I wanted a MOSFET, so badly a MOSFET!

After investigating into the power supply for more faults, I found the output gets noisy while the duty cycle is changed. As a remedy, I used a second order low pass filter instead of a first order one and increased the PWM base frequency to 48KHz from 10KHz. Now, there is no audible noise, the output dc remains enough clean, though I didn’t check it with an oscilloscope, so I can’t tell you how clean it is!

But all the problems have a very simple solution. To replace the whole power supply section with a voltage controlled current source (VCCS). The VCCS would operate in two modes. In first mode, it’ll give a full range output current of 0-50 uA, to determine the cold resistance of the filament accurately (it is not possible with PWM + pass transistor). In the second mode, it’d give a full range current of 0-2A. The maximum current depends on the MOSFET (see the schematic below) and the power supply voltage. In the quick simulation, I’ve used a 20V power supply to the VCSS, just enough to power up a 12V automotive lamp.

VCSS in MultisimRough simulation of a VCSS in NI Multisim

The control voltage of the VCCS would be controlled by a digital potentiometer. We all have used a rotary potentiometer. Digital potentiometer is simply a digital version of it where the knob is rotated by some digital signals (SPI or I2C) from the microcontroller instead of our fingers. Through which more precision control over the power supply would be achieved.

If I had a hammer

If I had a hammer/ I’d hammer in the morning/ I’d hammer in the evening/ All over this land /I’d hammer out danger/ I’d hammer out a warning/ I’d hammer out love between my brothers and my sisters/ All over this land…

A great song by Pete Seeger. Here I’m going to tell you I could do better if I had some more instruments (i.e. some hammers) and access to some electronics and scientific stores.

  • The local electronics stores are awful, really awful. They don’t stock any components other than passives and some very basic transistors and ICs. Probably they never heard of PIC microcontrollers. SMDs are not available. Precision resistors (5% or 1% tolerance) are not available. My BOM (bill of materials) was always a bomb to them!
  • Though some of the greatest Indian electronics stores are there at online. Like element14 (formerly Farnell), onlineTPS, rhydolabz, kitsnspares etc. But I don’t have any credit card or netbanking facility to buy from them. Check/DDs are outdated and many of the stores don’t accept it. And who accepts, takes more than one and half months to proceed due to banking lags. So online stores are not worthy to me for now.
  • Maxim semiconductors provided me some samples of MAX4372 and MAX873. Oh! thanks a lot.
  • Now professionals will laugh aloud: I used five pieces of 1 ohm resistor (10% tolerance) in parallel to make an equivalent resistor of 100 milliohm current sense resistor. This had to be precise enough for accurate results. Unfortunately, it isn’t. Resistors specially made for current sensing have very low tolerance values, like 0.1% or 0.01%. A real current sense resistor will greatly improve the overall accuracy.
  • I don’t have access to an oscilloscope so that I couldn’t analyze some part of the circuit (e.g. the low pass filter characteristics). I used a tiny speaker to listen to the waveform! A dc sounds a little transient bump and any other waveform sounds a humming. So, I could at least distinguish between a dc and some wavy variations. It was fine when the PWM base frequency was 10KHz. Later I changed it to 48KHz. Phew… ain’t no bat to listen to ultrasonics! Disappointed smile
  • I had an idea to use a IR photodiode to measure the filament temperature from its IR emission. Well, sounds nice. I tried using a standard IR photodiode with various bias levels to cover the entire 300K to 2500K temperature range. Obviously failed every time. After some tryouts, I understood, I’m actually going to make an optical pyrometer from scratch! Later I studied the details of a pyrometer and figured how foolish I was. It would need very complex mechanism; collimator, optical chopping, sensitive pyro element, precision amplifier etc etc. So I abandoned my idea soon.
  • Pasco scientific ltd, a leading scientific instrument maker from US, has a so called ‘Stefan-Boltzmann Lamp’. They claim that it closely resembles a blackbody characteristics. I liked to do some experiment with it. But unfortunately Pasco don’t have any reseller/distributor in India.

         SBLamp The Stefan-Boltzmann Lamp 

Helping hands

The list of helping hands is not too long. This is not because people are unhelpful. Actually, I didn’t sought help from anybody. How would you expect to get others’ hand without spreading out your own?

Probably you have guessed that it’s a completely DIY project and what I’ve learned so far in electronics and programming are all in do-it-yourself way. But, the first one I should mention as a helping hand is Partha Chakraborti. I learnt numerous things from him, from PCB etching to C# code snippets! Also happily burnt our times in gossiping from so-hated-politics to so-beloved-love-stories! Interestingly, he is my net-friend, not anyone from the world of reality. I swear, whenever my DIY world fell into an abyss, I always got his virtual hands. And most likely, without it, I couldn’t have become what now I am.

My two priceless friends from real world, Anjan and Prantik, did help me too. Anjan brought me some components and I had a long discussion about various properties of linear and non linear regression with Prantik.


PIC Programming

Note that, I didn’t learn PIC programming from any real person, but the followings are not less than a real person anyway (what would philosophers call it: postmodern revolution!).

Journal articles

Here are the journal articles which I followed.

This is not a complete list though. I went through almost all the search results.

My files

  • The PDF export of the Mathematica notebook file: log6.pdf
  • The .bas file from Swordfish IDE: sb_demon -bas. doc (change the extension to .bas )
  • If you are curious about something more, then you can ask me for some more files (e. g. Swordfish libraries, compiled hex file, USB interface installation files, its source files or any other file). WordPress doesn’t allow this type of files to be attached. But feel free to ask me for them, I’ll mail it to you.

The last thing on my mind…

Are you going away with no word of farewell?/ Will there be not a trace left behind?/ Well, I could have loved you better, /Didn’t mean to be unkind./ You know that was the last thing on my mind…

Another great song by Tom Paxton. After more than 8 years with DIY electronics, microcontrollers, bucketful of junk electronic lilliputs and programming codes; with failures, sudden victories and helplessness… Don’t know why I’ve become so romantic, so addicted  about DIY stuffs. I’ve done so much for it; explored a lot, neglected my academic studies, skipped from being an academic scholar to a casual 80 percenter.

Now I’m an undergraduate student of physics. I’ve seen a few real teachers who tries to uncover the facts rather than throwing them into a mess of equations. Physics is all about nature, and it’s beautiful. And it becomes easy/simple when the aesthetic is well understood. The simplicity is often neglected in academic studies. As a bookworm of popular science books (namely, started off with Parthasarathi Chakraborti, Shyamal Chakraborti and authors from Mir publication of former USSR; later introduced to Feynman, George Gamow, John Gribbin, Roger Penrose, Paul J Nahin, Michio Kaku, G. Venkataraman, Jayanta Basu, John A Adam and lot more), I found the world of mystery beauty and surprises, lot more surprises, which I rarely found in texts (I swear, there are a few textbooks which explores the topic, revealing the beauty in it). At this point, I should mention my parents, specially my father, who is an art-critic. His livelong passion is to collect and read books. I’ve over five thousand books (and counting!) mostly on art and literature in my very cluttered house. We often have discussions how to relate arts and sciences just like an unification.

So far, the greatest DIY people, I know, is Michio Kaku. The whole world knows him as a leading theoretical physicist in the field of string field theory. Since, at least for now,  I don’t have not enough courage to venture into this, he is a God of DIY-ing to me. He made a particle accelerator (betatron) at home! Can you believe it, a school-going-kid makes a  particle accelerator at his parent’s garage for a science fair project!!! Is not it like dreaming? Also, the book, Hyperspace, where he told it, is one of my very best read. Here is a glimpses of the dream (for you who missed it, page no 6-7):

Hyperspace: a scientific odyssey through parallel universes, time warps, and … By Michio Kaku

And the very last thing is Prof. Walter Lewin, who changed my understanding of physics (specially electromagnetism) through his lectures, now available to everyone through MIT OpenCourseWare. This is a classic lecture series, I admire his interactive and demonstrative method of teaching. I’m eagerly waiting for his book, For the Love of Physics to become available in India. If you have considered reading so far, then I’d recommend you to watch this 5:46 min course introduction video, you’ll never forget it (specially the last part, from 2:44 min), I’m sure.

Course Introduction | MIT 8.02 Electricity and Magnetism, Spring 2002

And that’s all, the last thing on my mind…

Posted in Main Article | Tagged , , , , , , , | 7 Comments