GWのガイガーカウンタ自作チャレンジ(2台目) バッテリ駆動版(11)
だめ押しのsleep関数 による省電力化と、内蔵タイマーによる1秒未満のパルス間隔への対応をしてみた。結果、消費電流は、実測で、50mAになった(sleep適用前は、55mA)。また、タイマーで、msecの値でパルス間隔時間を測定するように変更してみた。下グラグは、タイマー使用したときの測定値のグラフ。ラジュウム温泉素の接近時に、1.76倍のパスルが発生している結果になった。
変更後のmbedのソースコードは、、、、
変更後のmbedのソースコードは、、、、
#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; Timer myTimer; Ticker myTicker; void handler_intrQ04 (void); void handler_swAdjust (void); void handler_swEject (void); void handler_ticker (void); int statDetect; int statEject; int statAdjust; #define USR_POWERDOWN (0x104) int semihost_powerdown() { uint32_t arg; return __semihost(USR_POWERDOWN, &arg); } void updateLEDs(void) { if (statDetect || statEject || statAdjust ) { ledActive = 1; } else { ledActive = 0; } if (statEject) { ledEject = 1; } else { ledEject = 0; } } int main() { statDetect = 0; statEject = 0; statAdjust = 0; updateLEDs(); need_mark = 0; setSystemFrequency( 0x3, 0x1, 6, 1 ); // need a change to 4800bps 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 ); semihost_powerdown(); seconds_prev = time(NULL); intrQ04.fall( handler_intrQ04 ); myTimer.reset(); myTimer.start(); swAdjust.fall( handler_swAdjust ); swEject.fall( handler_swEject ); pc.printf( "\rBegin Geiger Couter!\n" ); myTicker.attach( &handler_ticker, 60.0); while(1) { Sleep(); } } void handler_ticker (void) { time_t seconds = time(NULL); struct tm *tc = localtime( &seconds ); int 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; struct tm *tc; int myYear, myMon, myDay; int myHour, myMin, mySec; char fName[256]; int diff_msec; statDetect = 1; diff_msec = myTimer.read_ms(); myTimer.reset(); seconds = time(NULL); 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_msec, (16*60*1000*10)/(diff_msec) ); fclose( fp ); pc.printf( "\r%04d/%02d/%02d %02d:%02d:%02d, %d, %d, %d ", myYear+1900, myMon+1, myDay, myHour, myMin, mySec, seconds, diff_msec, (16*60*1000*10)/(diff_msec) ); } 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_msec, (16*60*1000*10)/(diff_msec) ); } 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台目) バッテリ駆動版(11)
このブログ記事に対するトラックバックURL: http://the.nerd.jp/blogs/cgi-bin/mt-tb.cgi/4656