daiki hiraoka
/
EMG
筋電センサプログラム
筋電
Diff: main.cpp
- Revision:
- 0:42ab58db8182
- Child:
- 1:91d6b2ee7a2e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jan 21 06:18:59 2017 +0000 @@ -0,0 +1,65 @@ +/*** Include ***/ +#include "mbed.h" +#include "rtos.h" + +#include "typedef.h" + +/*** Define ***/ +#define ON (1) +#define OFF (0) + +#define SAMPLING_RATE (0.001) /* A/D sampling rate (1kHz) */ +#define MAINCYCLE 200 /* [ms] */ + +/*** Global Variable ***/ +DigitalOut myled(LED1); /* 起動確認用 */ +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; + +/*** Functions ***/ +/* A/D変換割り込み */ +void ad_sampling(){ + INT32 i = 0; + i++; + + /* A/D変換完了後送信 */ + g_sendFlg = 1; +} + + +INT32 main() { + INT32 i = 0; + DBL64 st = 0; + DBL64 et = 0; + myled = 1; + + /* Start interval timer */ + sampling.attach(&ad_sampling, SAMPLING_RATE); + + while(1) { + /* timer read */ + st = timer.read_ms(); + + /* メイン処理 */ + myled = !myled; + i++; + + /* データ送信判定 */ + if(g_sendFlg == 1) { + /* データ送信 */ + i++; + + /* フラグリセット */ + g_sendFlg = 0; + } + + /* timer read */ + et = timer.read_ms(); + /* 制御周期まで待機 */ + Thread::wait((uint32_t)(MAINCYCLE - (et - st))); + } +}