Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- dhpt
- Date:
- 2017-01-21
- Revision:
- 1:91d6b2ee7a2e
- Parent:
- 0:42ab58db8182
- Child:
- 2:9a7f77850970
File content as of revision 1:91d6b2ee7a2e:
/*** Include ***/ #include "mbed.h" #include "rtos.h" #include "typedef.h" /*** Define ***/ #define ON (1) #define OFF (0) #define SAMPLING_RATE (1) /* A/D sampling rate (1kHz) */ #define MAINCYCLE 200 /* [ms] */ #define DEBUG /*** Global Variable ***/ DigitalOut myled1(LED1); /* 起動確認用 */ DigitalOut myled2(LED2); /* 割り込み確認用 */ DigitalOut myled3(LED3); /* 休止状態確認用 */ Ticker sampling; /* Interval timer for A/D sampling */ AnalogIn wave_in(p20); /* Waveform input */ Serial pc(USBTX, USBRX); /* tx, rx */ Timer timer; UINT32 g_sendFlg; FLT32 g_wave; UINT32 g_adCnt; /*** Functions ***/ /* A/D変換割り込み */ void ad_sampling(){ static INT32 i = 0; /* 割り込み中点灯 */ myled2 = 1; g_adCnt++; g_wave = wave_in.read() * 3.3; /*[V] */ #ifdef DEBUG_ i++; pc.printf("attach: %d,%d\r\n", i, g_adCnt); g_wave = i / 100 * 3.3; g_wave = g_adCnt * 3.3; if(i > 100) i = 0; #endif wait(0.01); /* A/D変換完了後送信 */ g_sendFlg = 1; myled2 = 0; } INT32 main() { INT32 i = 0; DBL64 st = 0; DBL64 et = 0; myled1 = 1; /* A/D変換対タイマ割り込み開始 */ myled2 = 1; /* Start interval timer */ sampling.attach(&ad_sampling, SAMPLING_RATE); myled2 = 0; while(1) { /* timer read */ st = timer.read_ms(); myled3 = 0; /* メイン処理 */ myled1 = !myled1; i++; /* データ送信判定 */ if(g_sendFlg == 1) { /* データ送信 */ i++; #ifdef DEBUG pc.printf("cnt: %d, ad cnt: %d, wave: %f\r\n", i, g_adCnt, g_wave); #endif /* フラグリセット */ g_sendFlg = 0; } /* timer read */ et = timer.read_ms(); /* 制御周期まで待機 */ Thread::wait((uint32_t)(MAINCYCLE - (et - st))); } }