出力計の為に作成した。50ms毎に経過時間を取得して1000ms経過したらそれらの値をsdに保存する。これは何故か正常に作動する。

Dependencies:   SDFileSystem mbed

Fork of Power_meter_kai_TP by Atsumi Toda

Committer:
Joeatsumi
Date:
Mon Sep 04 06:41:39 2017 +0000
Revision:
3:e7f77ec41f33
Parent:
2:f8284afcee36
???????????50ms???????????1000ms???????????sd????????????????????

Who changed what in which revision?

UserRevisionLine numberNew 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 3:e7f77ec41f33 15 //static unsigned long TimeLog[20];//20個の要素を「箱」を用意する
Joeatsumi 3:e7f77ec41f33 16 static unsigned long TimeLog[20];//10個の要素を「箱」を用意する
Joeatsumi 2:f8284afcee36 17 unsigned long nowTime = 0;
Joeatsumi 2:f8284afcee36 18
Joeatsumi 2:f8284afcee36 19 void SD(){//この関数を0.05秒ごとに呼び出して、その度に経過時間をTimeLog[]に代入する。
Joeatsumi 2:f8284afcee36 20 //つまり、50ms毎の時間が配列に保存される。
Joeatsumi 2:f8284afcee36 21 //1000ms経過するとそれらの値をまとめてsdカードに保存する。
Joeatsumi 2:f8284afcee36 22
Joeatsumi 2:f8284afcee36 23 __disable_irq();//この関数を最優先に割り込みする。
Joeatsumi 2:f8284afcee36 24 myled1 = 0 ;
Joeatsumi 2:f8284afcee36 25
Joeatsumi 2:f8284afcee36 26 if(count<19){
Joeatsumi 2:f8284afcee36 27
Joeatsumi 2:f8284afcee36 28 TimeLog[count]=nowTime;
Joeatsumi 2:f8284afcee36 29 count++;
Joeatsumi 2:f8284afcee36 30
Joeatsumi 2:f8284afcee36 31 }else{
Joeatsumi 2:f8284afcee36 32
Joeatsumi 2:f8284afcee36 33 TimeLog[19]=nowTime;
Joeatsumi 2:f8284afcee36 34
Joeatsumi 2:f8284afcee36 35 pc.printf("Hello World!\n");
mbed_official 0:bdbd3d6fc5d5 36
Joeatsumi 2:f8284afcee36 37 mkdir("/sd/mydir", 0777);
mbed_official 0:bdbd3d6fc5d5 38
Joeatsumi 2:f8284afcee36 39 FILE *fp = fopen("/sd/mydir/sdtest_kai.csv", "a");
Joeatsumi 2:f8284afcee36 40 if(fp == NULL) {
mbed_official 0:bdbd3d6fc5d5 41 error("Could not open file for write\n");
Joeatsumi 2:f8284afcee36 42 }
Joeatsumi 3:e7f77ec41f33 43 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]
Joeatsumi 3:e7f77ec41f33 44 ,TimeLog[10],TimeLog[11],TimeLog[12],TimeLog[13],TimeLog[14],TimeLog[15],TimeLog[16],TimeLog[17],TimeLog[18],TimeLog[19]);
Joeatsumi 2:f8284afcee36 45 myled1 = 1 ;
Joeatsumi 2:f8284afcee36 46 fclose(fp);
Joeatsumi 2:f8284afcee36 47 free(fp);
Joeatsumi 2:f8284afcee36 48
Joeatsumi 2:f8284afcee36 49 pc.printf("Goodbye World!\n");
Joeatsumi 2:f8284afcee36 50
Joeatsumi 2:f8284afcee36 51 count=0;//カウントをリセットする
Joeatsumi 2:f8284afcee36 52
Joeatsumi 2:f8284afcee36 53 }//if end
Joeatsumi 2:f8284afcee36 54
Joeatsumi 2:f8284afcee36 55 __enable_irq();
Joeatsumi 2:f8284afcee36 56 }
mbed_official 0:bdbd3d6fc5d5 57
Joeatsumi 2:f8284afcee36 58
Joeatsumi 2:f8284afcee36 59 int main(){
Joeatsumi 2:f8284afcee36 60 Time.start();
Joeatsumi 2:f8284afcee36 61 sd_write.attach(&SD,0.05);//0.05秒ごとにSDという関数を発動し、割り込みする。
Joeatsumi 3:e7f77ec41f33 62
Joeatsumi 2:f8284afcee36 63 while(1){
Joeatsumi 2:f8284afcee36 64 nowTime = Time.read_ms();
Joeatsumi 2:f8284afcee36 65 }
Joeatsumi 2:f8284afcee36 66 }