Tuesday, September 9, 2014

NETMF 4.2 - Reading a TMP36 sensor

Reading TMP36 from AnalogDevices

Product page: http://www.analog.com/en/mems-sensors/digital-temperature-sensors/tmp36/products/product.html
 

Using AnalogPin 0 on a GHI Cerbuino Bee. The flashing LED indicates alternating read cycles.



Cerbuino product page: https://www.ghielectronics.com/catalog/product/351
Cerbuino schematic: http://www.ghielectronics.com/downloads/schematic/FEZ_Cerbuino_Bee_SCH.PDF

AnalogInput ain = new AnalogInput((Cpu.AnalogChannel)10);
ain.Scale = 3.3;
OutputPort LED;
LED = new OutputPort(cerb.Pin.PB2, true);
double temp, temperatureF;
bool last = false; while (true)
{
    last = !last;
    LED.Write(last);
    temp = (ain.Read() - 0.5) * 100;
    Debug.Print("TempC: " + temp);
    temperatureF = (temp * 9.0 / 5.0) + 32.0;
    Debug.Print("TempF: " + temperatureF);
    Thread.Sleep(1500);
}
It's that simple!



Tuesday, September 2, 2014

NPN calculations

In an attempt to keep these calculations organized, here's the maths for NPNs.

(From: https://www.youtube.com/watch?v=ZEDdFjvnAAo)
Suppose you had a 5v/2A source and wanted to power a 5v 1A motor via mCu board (which can only source 5v/0.5A). What would the resistor need to be on the Base of the NPN?



If you have a hRE 100 NPN transistor here's the formula:

Ic = Collector current
Ib = Base current

Solving for Ib
hFE = Ic / Ib
or
100 = 1 / Ib (substitute known values)
or
100 * Ib = 1 (move the Ib over to the left)
or
Ib = 0.01A (move the 100 to the right)

Now solving for resistor needed with Ohms Law:
V=IR
or
(5 - 0.8) = 0.01 * R (substitute known values - factoring loss via transistor)
or
4.2 = 0.01 R (simplify V)
or
420 = R (move 0.01 to the left)

Viola! You need a 420 ohm resistor connected between the base and mCu pin.

To see in action: Falstad.com Circuit Simulator (A word of caution: need Java to run)

With a 420 ohm resistor:


With a 1k ohm resistor (for comparison). Notice Ie is only 431.5mA.