12.28.2009

地磁

注意事項:
  • 雖然是 1 bytes,但是只有 12 bit 的解析度,high bits (MSB) 都是 0 -- 也就是說,data 都是正值囉。
這一篇 有說,磁棒的形狀細長的話,雙極的磁力比較強。
以下是copy他的說明:

When doing measurements with a gaussmeter, please note that the actual field at the surface of a magnet is at most one half of the rated residual magnetism for that magnetic material. If a rare-earth magnet is rated at 14,000 gauss for example, a bar magnet made from that material will have an actual field of at most 7000 gauss at the north pole and -7000 gauss at the south pole. The readings may be even less than 7000 gauss. If the bar magnet is thin (that is, its length is at least 10 times its diameter) then the field will be close to 7000 gauss. If the bar magnet旧 length is less than 10 times its diameter, the field at either pole will be weaker. For example, if the magnet is in the shape of a cube, the surface field will be 4500 gauss or less. The full 14,000 gauss field can only be created if two bar magnets are in a gap configuration. This means that the magnets are held close together so that one south pole of one magnet is held very close to one north pole of the other. The distance between the magnets (the gap width) must be small compared to the magnet diameters, and each magnet旧 length must be at least 10 times its diameter. Then the field in the gap will be approximately the full value of the magnetic material旧 residual magnetism, which is 14,000 gauss in this example. Magnets that are flat (like a pancake) have a very low surface field. The magnetic pull force between equal magnets or between a magnet and a steel or iron block can be calculated from field strength. This force is approximately [Force in grams] = 0.00016 x [Field on the magnet face in gauss]2 x [Magnet face area in square cm].)
另外這一篇有說,現在地磁的強度,在地球北極(磁南極)是 0.7G (gauss),地球南極是 0.6G。地磁最小的地方是南回歸線,約 0.25G。

  • rang 是 +- 2G,分成 12 bit,所以resolution (sensitivity) 是 1/512 G。
  • 資料寫得非常不清楚,但是由 offset distribution 來看,offset 值是 2048,所以應該都是正的值,0 G 在 2048。
這個網站( http://www.ngdc.noaa.gov/geomagmodels/IGRFWMM.jsp) 可以查世界各城市的磁場強度和傾角。

查到台北地區的資料是:
Lat: 25° 1' 48''
Lon: 121° 30'
Elev: 0.00 m
Declination
+ East - West
Inclination
+ Down - Up
Horizontal Intensity
North Component
+ North - South
East Component
+ East - West
Vertical Component
+ Down - Up
Total Field
12/27/09 - 3° 57' 36° 16' 36,292.4 nT 36,206.2 nT -2500.3 nT 26,633.1 nT 45,016.2 nT
Change per year - 4' per year 0' per year -7.9 nT/year -10.7 nT/year -40.3 nT/year -3.6 nT/year -8.5 nT/year


單位:Wiki說,1 Tesla = 104Gauss

所以Taipei 的地磁通量是 0.45G。

  • 所以 量起來應該是 +- 230
  • Horizontal : 0.36G = 184
  • Vertical : 0.26G = 133



地磁量測 Sensor 通常是利用 AMR (Anisotropoc Magnetorresistive) Sensor:
ref: http://archives.sensorsmag.com/articles/0399/0399_18/main.shtml

大概是利用有磁力的鐵棒,當外部磁力影響,鐵棒變形,電阻改變,所以量測電阻就可以知道外部磁力的大小。

有因為這個鐵棒的磁力會減弱或受大外力作用而改變,所以常常需要重新加磁。

Sensor 也要內建這樣的功能。ref 是說,利用外加線圈在這些鐵棒上,通電產生磁廠就可以。
同時,控制通電的方向,可以變更鐵棒的磁極方向。
  • 這樣的動作叫 SET/RESET - 就是通電


實際量測:
  • X: 23 ~ 263 , rang: 240
  • Y:50 ~ 270, rang: 220
  • Z:

12.18.2009

Change Disk Volume Id

問題:要用 VolumeId改某外接mass storage 的 VolumeId,結果該裝置 report error。

查了一下,發現該裝置的 sector size 是 4096,所以VolumeId request read 512 bytes時,就 fail了。

所以,寫了一個這個:


Change Disk Volume ID
support Disk sector size up to 4k.
For FAT32 only,
ref :MSDN:How FATWorks


/ VolumeId4k.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>

char _toHex(wchar_t High,wchar_t Low)
{
char rc;
if(High>='A')
rc = High-'A'+10;
else
rc = High-'0';

rc <<= 4;

if(Low>='A')
rc |= Low-'A'+10;
else
rc |= Low-'0';

return rc;
}


int _tmain(int argc, _TCHAR* argv[])
{

if( argc < 3){
wprintf(L"Command : VolumeId4k G: 1111-1111\n");
return 1;
}

// convert Driver letter to driver index
TCHAR DriverLetter=argv[1][0];
if(DriverLetter>'Z')
DriverLetter-='a'-'A';
wprintf(L"Driver : %c\n",DriverLetter);

wchar_t _devicename[] = L"\\\\.\\A:";
_devicename[4] += DriverLetter-'A';


// Creating a handle to disk drive using CreateFile () function ..
HANDLE hDevice ;

hDevice = CreateFile(_devicename,
GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE){
wprintf(L"Open Driver %s Failed!\n",argv[1]);
return 1;
}

// Read first sector
char buffer[4096];
DWORD bytesrw;

SetFilePointer (hDevice, 0, NULL, FILE_BEGIN);
if (!ReadFile (hDevice, buffer, 4096, &bytesrw, NULL) ){
wprintf(L"Read 0 sector failed!\n");
goto _exit;
}


// modify the volumeid field - only valid for FAT32
buffer[0x43]=_toHex(argv[2][7],argv[2][8]);
buffer[0x44]=_toHex(argv[2][5],argv[2][6]);
buffer[0x45]=_toHex(argv[2][2],argv[2][3]);
buffer[0x46]=_toHex(argv[2][0],argv[2][1]);


// write back
SetFilePointer (hDevice, 0, NULL, FILE_BEGIN);
if (!WriteFile (hDevice, buffer, 4096, &bytesrw, NULL) ){
wprintf(L"Write Sectpr Faile!\n");
goto _exit;
}


wprintf(L"Success!\n");


_exit:
if(hDevice)
CloseHandle(hDevice);

return 0;
}


* CreateFile 的 devicename 在 windows 和 CE 不一樣,在 CE 下 是:http://realchecko.blogspot.com/2009/04/openstore-is-createfile.html

12.02.2009

又來:SD 的 driver architecture

標準的 SD driver 分為三部份:
  • SDHC : SD Host Controller - depend on hardware
  • SDBUS : 在 SDHC 的上層,負責操控SDHC,做出統一的 SDBUS interface
  • SD Client : SDBUS 依照偵測到的 SD 至,load 進來的 SD 裝置 Driver,一般有 SDMEMORY,SDWIFI..
SDHC 負責 收interrupt,用 "Slot" 來管理physical SD Slot。

SDHC.DLL 在 DllEntry( ) call SDInitializeCardLib( ) 將 SDBUS.DLL export 的 function pointer 放在 g_SDHostFuncs.

然後所有的 exportfunction name 加上 SDHC,變成 SD

12.01.2009

  • Identification Mode : Power ON 後就待在這個Mode, 一直到收到 CMD3(SET_RCA)
  • Interrupt Mode : 允許 card 送出 interrupt service request
  • Data Transfer Mode : Card 收到 CMD3 (SET_RCA) 後,進入這個Mode
CSD Register 內容用來設定 eMMC 的工作模式,但是只有幾個 register 可以設定 (writable)。
設定的方式是要用 CMD6 (SWITCH_COMMAND)。