GWのガイガーカウンタ自作チャレンジ(2台目) バッテリ駆動版(10)
まだ、現在、自作中のガイガーカウンタ(2号機タイプ0Rev.0)は、バッテリ駆動としては、消費電流が、100mAと、だいぶん大きいが、取り敢えず、持ち歩けるように、もう少し大きめの入れものに入れてみた。
こんな感じ。中の回路図等は、今まで、掲載しているが、
|
|
|
【ガイガーカウンタ全体】

【GM管周辺回路】

【GM管駆動用DC400V出力DCDCコンバータ部】
こんな感じ。機能としては、地味で、SDメモリへ記録して行くだけね。mbedのプログラム最終版は、後日、公開する予定だが、テストプログラムは下記。
【GM管周辺回路】
【GM管駆動用DC400V出力DCDCコンバータ部】
// Geiger Counter firmware for mbed NXP LPC 1768
// AS-IS is freeware, non-supported and non-warranty, (C) 2011, digiponta
//
#include "mbed.h"
#include "string.h"
#include "SDFileSystem.h"
#include "PowerControl/PowerControl.h"
#include "EthernetPowerControl.h"
#include "ClockControl.h"
DigitalOut ledActive(p27);
DigitalOut cntRst(p15);
DigitalOut pw400V(p16);
DigitalOut ledEject(p18);
InterruptIn intrQ01(p11);
InterruptIn intrQ04(p12);
InterruptIn intrQ08(p13);
InterruptIn intrQ12(p14);
InterruptIn swAdjust(p28);
InterruptIn swEject(p17);
DigitalIn swSd(p29);
Serial pc(USBTX, USBRX); // tx, rx
SDFileSystem sd(p5,p6,p7,p8, "gm");
time_t seconds_prev;
int need_mark = 0;
void handler_intrQ04 (void);
void handler_swAdjust (void);
void handler_swEject (void);
int statDetect;
int statEject;
int statAdjust;
void updateLEDs(void) {
if (statDetect || statEject || statAdjust ) {
ledActive = 1;
} else {
ledActive = 0;
}
if (statEject) {
ledEject = 1;
} else {
ledEject = 0;
}
}
int main() {
struct tm *tc;
int min;
time_t seconds;
statDetect = 0;
statEject = 0;
statAdjust = 0;
updateLEDs();
need_mark = 0;
// setSystemFrequency( 0x3, 0x1, 6, 1 );
PHY_PowerDown();
Peripheral_PowerDown(
LPC1768_PCONP_PCADC |
LPC1768_PCONP_PCCAN1 |
LPC1768_PCONP_PCCAN2 |
LPC1768_PCONP_PCENET |
LPC1768_PCONP_PCUSB |
// LPC1768_PCONP_PCI2C0 |
LPC1768_PCONP_PCI2C1 |
LPC1768_PCONP_PCI2C2 |
LPC1768_PCONP_PCPWM1 |
LPC1768_PCONP_PCMCPWM
);
seconds_prev = time(NULL);
intrQ04.fall( handler_intrQ04 );
swAdjust.fall( handler_swAdjust );
swEject.fall( handler_swEject );
pc.printf( "\rBegin Geiger Couter!\n" );
while(1) {
wait( 60 );
seconds = time(NULL);
tc = localtime( &seconds );
min = tc->tm_min;
pc.printf( "\r--- %d --- \n", min );
if ( (min % 10) == 0 ) {
need_mark = 1;
}
}
}
void handler_intrQ04 (void) {
FILE *fp;
time_t seconds;
int diff;
struct tm *tc;
int myYear, myMon, myDay;
int myHour, myMin, mySec;
char fName[256];
statDetect = 1;
seconds = time(NULL);
diff = seconds - seconds_prev;
seconds_prev = seconds;
tc = localtime( &seconds );
myYear = tc->tm_year;
myMon = tc->tm_mon;
myDay = tc->tm_mday;
myHour = tc->tm_hour;
myMin = tc->tm_min;
mySec = tc->tm_sec;
updateLEDs();
if (1)
// if (need_mark == 1)
{
need_mark = 0;
if ( (swSd == 0) && (statEject == 0) ) {
SDFileSystem sd(p5,p6,p7,p8, "gm");
sprintf( fName, "/gm/%04d%02d%02d.csv", myYear+1900, myMon+1, myDay );
fp = fopen ( fName, "a" );
if (fp != NULL ){
fprintf( fp , "%04d/%02d/%02d %02d:%02d:%02d, %d, %d, %d\n",
myYear+1900, myMon+1, myDay, myHour, myMin, mySec,
seconds, diff, (16*600)/(diff) );
fclose( fp );
pc.printf( "\r%04d/%02d/%02d %02d:%02d:%02d, %d, %d, %d ",
myYear+1900, myMon+1, myDay, myHour, myMin, mySec,
seconds, diff, (16*600)/(diff) );
} else {
pc.printf( "\rcan't open sd " );
}
} else {
pc.printf( "\rnone of sd or skip writeing it " );
if ( (swSd != 0) && (statEject != 0) ) statEject = 0;
}
} else {
pc.printf( "\rskip - %04d/%02d/%02d %02d:%02d:%02d, %d, %d, %d ",
myYear+1900, myMon+1, myDay, myHour, myMin, mySec,
seconds, diff, (16*600)/(diff) );
}
if ( statAdjust != 0 ) {
pc.printf( "- sw H - " );
} else {
pc.printf( "- sw L - " );
}
if ( statEject != 0 ) {
pc.printf( "- ej H - " );
} else {
pc.printf( "- ej L - " );
}
if ( swSd != 0 ) {
pc.printf( "- sd H - \n" );
} else {
pc.printf( "- sd L - \n" );
}
statDetect = 0;
updateLEDs();
}
void handler_swAdjust (void) {
char cc;
int val;
struct tm t;
statAdjust = 1;
updateLEDs();
pc.printf( "\rPlease, set date and time.\n" );
while(1) {
val = 0;
pc.printf( "\rYear: " );
if (scanf( "%d", &val ) < 1) {
goto MY_EXIT;
}
pc.printf( "Year = %d\n", val );
t.tm_year = val - 1900;
pc.printf( "\rMonth: " );
if (scanf( "%d", &val ) < 1) {
goto MY_EXIT;
}
pc.printf( "Month = %d\n", val );
t.tm_mon = val - 1;
pc.printf( "\rDay: " );
if (scanf( "%d", &val ) < 1) {
goto MY_EXIT;
}
pc.printf( "Day = %d\n", val );
t.tm_mday = val;
pc.printf( "\rHour: " );
if (scanf( "%d", &val ) < 1) {
goto MY_EXIT;
}
pc.printf( "Hour = %d\n", val );
t.tm_hour = val;
pc.printf( "\rMin: " );
if (scanf( "%d", &val ) < 1) {
goto MY_EXIT;
}
pc.printf( "Min = %d\n", val );
t.tm_min = val;
t.tm_sec = 0;
pc.printf( "\rSet %04d/%02d/%02d %02d:%02d:00 to RTC? (y/n/c)\n",
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
t.tm_hour,
t.tm_min
);
while(1) {
if ( scanf( "%c", &cc ) < 1 ) {
goto MY_EXIT;
}
if ( cc == 'y' ) {
time_t seconds = mktime( &t );
pc.printf( "\rseconds = %d \n" , seconds );
set_time ( seconds );
goto MY_EXIT;
}
if ( cc == 'c' ) {
goto MY_EXIT;
}
if ( cc == 'n' ) break;
}
}
MY_EXIT:
statAdjust = 0;
updateLEDs();
}
void handler_swEject (void) {
if (statEject == 1) {
statEject = 0;
} else {
statEject = 1;
}
updateLEDs();
}
こんな感じ。
トラックバック(0)
このブログ記事を参照しているブログ一覧: GWのガイガーカウンタ自作チャレンジ(2台目) バッテリ駆動版(10)
このブログ記事に対するトラックバックURL: http://the.nerd.jp/blogs/cgi-bin/mt-tb.cgi/4653









setSystemFrequency( 0x3, 0x1, 6, 1 );のクロック周波数ダウン(2分の1)を有効にした場合は、mbedとパソコンのシリアル通信設定を、9600bpsから4800bpsへ変更する必要がある。変更しないと、文字化けする。このクロックダウンにより、消費電流は、85mA前後になるようだ。これで、多分、エネループ・モバイルブースタで、24h前後、もつようになる。
ファームウェアmbedMicrocontroller_ExperimentalPowerdown.ifを適用して、
semihost_powerdownで、プログラミング用USBの電源を落とすと、消費電流は、55mA前後になった。SDメモリへのデータの書き込みも正常動作しているようだ。これで、エネループ・モバイルブースタで、36h(3日間)もつようになるかな?
mbedのsleepを使用するように、プログラム修正すると、55mAの消費電流が、50mAまで下がった。sleepは、任意の割り込みで戻ってくるので、whileループで囲っておく必要がある。例: while(1) { sleep() ); } あと、全ての処理は、割り込みかタイマーベースの処理へ変える必要がある。