出力計の為に作成した。50ms毎に経過時間を取得して1000ms経過したらそれらの値をsdに保存する。しかし現状として6000ms経過するとプログラムが停止する。
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@2:f8284afcee36, 2017-09-03 (annotated)
- Committer:
- Joeatsumi
- Date:
- Sun Sep 03 01:40:21 2017 +0000
- Revision:
- 2:f8284afcee36
- Parent:
- 0:bdbd3d6fc5d5
- Child:
- 3:e7f77ec41f33
?????50ms???????????????????????????6000ms???????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
mbed_official | 0:bdbd3d6fc5d5 | 3 | |
Joeatsumi | 2:f8284afcee36 | 4 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
Joeatsumi | 2:f8284afcee36 | 5 | SDFileSystem sd(dp2,dp1,dp6,dp13,"sd"); |
Joeatsumi | 2:f8284afcee36 | 6 | Serial pc(dp16,dp15); |
Joeatsumi | 2:f8284afcee36 | 7 | Timer Time ; |
Joeatsumi | 2:f8284afcee36 | 8 | Ticker sd_write ; |
Joeatsumi | 2:f8284afcee36 | 9 | DigitalOut myled1(LED1); |
Joeatsumi | 2:f8284afcee36 | 10 | //Serial pc(dp16,dp15); |
Joeatsumi | 2:f8284afcee36 | 11 | |
Joeatsumi | 2:f8284afcee36 | 12 | |
Joeatsumi | 2:f8284afcee36 | 13 | int count =0;//最初はTimeLog[0]から始まる |
Joeatsumi | 2:f8284afcee36 | 14 | |
Joeatsumi | 2:f8284afcee36 | 15 | static unsigned long TimeLog[20];//20個の要素を「箱」を用意する |
Joeatsumi | 2:f8284afcee36 | 16 | unsigned long nowTime = 0; |
Joeatsumi | 2:f8284afcee36 | 17 | |
Joeatsumi | 2:f8284afcee36 | 18 | void SD(){//この関数を0.05秒ごとに呼び出して、その度に経過時間をTimeLog[]に代入する。 |
Joeatsumi | 2:f8284afcee36 | 19 | //つまり、50ms毎の時間が配列に保存される。 |
Joeatsumi | 2:f8284afcee36 | 20 | //1000ms経過するとそれらの値をまとめてsdカードに保存する。 |
Joeatsumi | 2:f8284afcee36 | 21 | |
Joeatsumi | 2:f8284afcee36 | 22 | __disable_irq();//この関数を最優先に割り込みする。 |
Joeatsumi | 2:f8284afcee36 | 23 | myled1 = 0 ; |
Joeatsumi | 2:f8284afcee36 | 24 | |
Joeatsumi | 2:f8284afcee36 | 25 | if(count<19){ |
Joeatsumi | 2:f8284afcee36 | 26 | |
Joeatsumi | 2:f8284afcee36 | 27 | TimeLog[count]=nowTime; |
Joeatsumi | 2:f8284afcee36 | 28 | count++; |
Joeatsumi | 2:f8284afcee36 | 29 | |
Joeatsumi | 2:f8284afcee36 | 30 | }else{ |
Joeatsumi | 2:f8284afcee36 | 31 | |
Joeatsumi | 2:f8284afcee36 | 32 | TimeLog[19]=nowTime; |
Joeatsumi | 2:f8284afcee36 | 33 | |
Joeatsumi | 2:f8284afcee36 | 34 | pc.printf("Hello World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 35 | |
Joeatsumi | 2:f8284afcee36 | 36 | mkdir("/sd/mydir", 0777); |
mbed_official | 0:bdbd3d6fc5d5 | 37 | |
Joeatsumi | 2:f8284afcee36 | 38 | FILE *fp = fopen("/sd/mydir/sdtest_kai.csv", "a"); |
Joeatsumi | 2:f8284afcee36 | 39 | if(fp == NULL) { |
mbed_official | 0:bdbd3d6fc5d5 | 40 | error("Could not open file for write\n"); |
Joeatsumi | 2:f8284afcee36 | 41 | } |
Joeatsumi | 2:f8284afcee36 | 42 | fprintf(fp, "%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n",TimeLog[0],TimeLog[1],TimeLog[2],TimeLog[3],TimeLog[4],TimeLog[5],TimeLog[6],TimeLog[7],TimeLog[8],TimeLog[9],TimeLog[10],TimeLog[11],TimeLog[12],TimeLog[13],TimeLog[14],TimeLog[15],TimeLog[16],TimeLog[17],TimeLog[18],TimeLog[19]); |
Joeatsumi | 2:f8284afcee36 | 43 | myled1 = 1 ; |
Joeatsumi | 2:f8284afcee36 | 44 | fclose(fp); |
Joeatsumi | 2:f8284afcee36 | 45 | free(fp); |
Joeatsumi | 2:f8284afcee36 | 46 | |
Joeatsumi | 2:f8284afcee36 | 47 | pc.printf("Goodbye World!\n"); |
Joeatsumi | 2:f8284afcee36 | 48 | |
Joeatsumi | 2:f8284afcee36 | 49 | count=0;//カウントをリセットする |
Joeatsumi | 2:f8284afcee36 | 50 | |
Joeatsumi | 2:f8284afcee36 | 51 | }//if end |
Joeatsumi | 2:f8284afcee36 | 52 | |
Joeatsumi | 2:f8284afcee36 | 53 | __enable_irq(); |
Joeatsumi | 2:f8284afcee36 | 54 | } |
mbed_official | 0:bdbd3d6fc5d5 | 55 | |
Joeatsumi | 2:f8284afcee36 | 56 | |
Joeatsumi | 2:f8284afcee36 | 57 | int main(){ |
Joeatsumi | 2:f8284afcee36 | 58 | Time.start(); |
Joeatsumi | 2:f8284afcee36 | 59 | sd_write.attach(&SD,0.05);//0.05秒ごとにSDという関数を発動し、割り込みする。 |
Joeatsumi | 2:f8284afcee36 | 60 | |
Joeatsumi | 2:f8284afcee36 | 61 | while(1){ |
Joeatsumi | 2:f8284afcee36 | 62 | nowTime = Time.read_ms(); |
Joeatsumi | 2:f8284afcee36 | 63 | } |
Joeatsumi | 2:f8284afcee36 | 64 | } |