Log measurements on SD card added on DISCO-L476VG board acceleration, omega, compass & 5 Analog values
Dependencies: BSP_DISCO_L476VG COMPASS_DISCO_L476VG ConfigFile GYRO_DISCO_L476VG SDFileSystem mbed
DefinitionIO.h@2:f53340e49cc0, 2016-02-13 (annotated)
- Committer:
- flowh
- Date:
- Sat Feb 13 14:48:40 2016 +0000
- Revision:
- 2:f53340e49cc0
- Parent:
- 1:e1f3b4b8b99b
Save on SD Card at up to at least 100Hz Acceleration, rotation velocity, compass and 5 AI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
flowh | 0:0861bf46efe4 | 1 | #include "mbed.h" |
flowh | 0:0861bf46efe4 | 2 | #include "DataFile.h" |
flowh | 0:0861bf46efe4 | 3 | |
flowh | 0:0861bf46efe4 | 4 | #include "SDFileSystem.h" |
flowh | 0:0861bf46efe4 | 5 | #include "COMPASS_DISCO_L476VG.h" |
flowh | 1:e1f3b4b8b99b | 6 | #include "GYRO_DISCO_L476VG.h" |
flowh | 1:e1f3b4b8b99b | 7 | #define NbDAC 5 |
flowh | 0:0861bf46efe4 | 8 | |
flowh | 1:e1f3b4b8b99b | 9 | #define SavePeriod 0.1 // 1/frequency of log : default 0.1 (tested OK at 0.01 (100Hz)) |
flowh | 0:0861bf46efe4 | 10 | |
flowh | 0:0861bf46efe4 | 11 | DigitalOut LedEnreg(LED1); |
flowh | 0:0861bf46efe4 | 12 | DigitalIn InterEnreg(PD_0,PullDown); |
flowh | 1:e1f3b4b8b99b | 13 | Ticker TickUpdate; |
flowh | 1:e1f3b4b8b99b | 14 | COMPASS_DISCO_L476VG compass ; //declaration must be before SDFile system declaration |
flowh | 1:e1f3b4b8b99b | 15 | GYRO_DISCO_L476VG gyro; |
flowh | 0:0861bf46efe4 | 16 | |
flowh | 1:e1f3b4b8b99b | 17 | |
flowh | 1:e1f3b4b8b99b | 18 | |
flowh | 1:e1f3b4b8b99b | 19 | AnalogIn AIn0(PA_0); |
flowh | 1:e1f3b4b8b99b | 20 | AnalogIn AIn1(PA_1); |
flowh | 1:e1f3b4b8b99b | 21 | AnalogIn AIn2(PA_2); |
flowh | 1:e1f3b4b8b99b | 22 | AnalogIn AIn3(PA_3); |
flowh | 1:e1f3b4b8b99b | 23 | AnalogIn AIn4(PA_5); |
flowh | 1:e1f3b4b8b99b | 24 | |
flowh | 1:e1f3b4b8b99b | 25 | AnalogIn * TabpAIn[NbDAC]= {&AIn0,&AIn1,&AIn2,&AIn3,&AIn4}; |
flowh | 1:e1f3b4b8b99b | 26 | //AnalogIn * AIn [5]; |
flowh | 0:0861bf46efe4 | 27 | |
flowh | 0:0861bf46efe4 | 28 | //Create an SDFileSystem object |
flowh | 1:e1f3b4b8b99b | 29 | SDFileSystem sd(PE_15, PE_14, PE_13, PE_12, "sd"); |
flowh | 1:e1f3b4b8b99b | 30 | |
flowh | 0:0861bf46efe4 | 31 | |
flowh | 1:e1f3b4b8b99b | 32 | tDataFile DataFile; //used to manage data savings |
flowh | 1:e1f3b4b8b99b | 33 | bool EnregistrementEnCours; |
flowh | 0:0861bf46efe4 | 34 | |
flowh | 1:e1f3b4b8b99b | 35 | tMesure Mesures(&compass,&gyro,TabpAIn); |
flowh | 1:e1f3b4b8b99b | 36 | |
flowh | 0:0861bf46efe4 | 37 | |
flowh | 1:e1f3b4b8b99b | 38 | |
flowh | 1:e1f3b4b8b99b | 39 | //------------------------ |
flowh | 1:e1f3b4b8b99b | 40 | // manage log switch |
flowh | 0:0861bf46efe4 | 41 | void CheckEnreg() |
flowh | 0:0861bf46efe4 | 42 | { |
flowh | 0:0861bf46efe4 | 43 | if (InterEnreg.read()==1) |
flowh | 0:0861bf46efe4 | 44 | { |
flowh | 0:0861bf46efe4 | 45 | if (!EnregistrementEnCours) |
flowh | 0:0861bf46efe4 | 46 | { |
flowh | 0:0861bf46efe4 | 47 | EnregistrementEnCours=true; |
flowh | 0:0861bf46efe4 | 48 | DataFile.New(); |
flowh | 1:e1f3b4b8b99b | 49 | printf("log started\n\r"); |
flowh | 0:0861bf46efe4 | 50 | } |
flowh | 0:0861bf46efe4 | 51 | else |
flowh | 0:0861bf46efe4 | 52 | { |
flowh | 0:0861bf46efe4 | 53 | DataFile.SaveMesures(&Mesures); |
flowh | 0:0861bf46efe4 | 54 | } |
flowh | 0:0861bf46efe4 | 55 | LedEnreg=!LedEnreg; |
flowh | 0:0861bf46efe4 | 56 | |
flowh | 0:0861bf46efe4 | 57 | } |
flowh | 0:0861bf46efe4 | 58 | else |
flowh | 1:e1f3b4b8b99b | 59 | { |
flowh | 1:e1f3b4b8b99b | 60 | if (EnregistrementEnCours) |
flowh | 0:0861bf46efe4 | 61 | { |
flowh | 0:0861bf46efe4 | 62 | EnregistrementEnCours=false; |
flowh | 0:0861bf46efe4 | 63 | DataFile.Close(); |
flowh | 1:e1f3b4b8b99b | 64 | printf("Log stopped\n\r"); |
flowh | 0:0861bf46efe4 | 65 | } |
flowh | 0:0861bf46efe4 | 66 | LedEnreg=0; |
flowh | 0:0861bf46efe4 | 67 | } |
flowh | 1:e1f3b4b8b99b | 68 | } |
flowh | 1:e1f3b4b8b99b | 69 | |
flowh | 1:e1f3b4b8b99b | 70 | /*********************** |
flowh | 1:e1f3b4b8b99b | 71 | Main function in loop |
flowh | 1:e1f3b4b8b99b | 72 | ************************/ |
flowh | 1:e1f3b4b8b99b | 73 | void Update() |
flowh | 1:e1f3b4b8b99b | 74 | { |
flowh | 1:e1f3b4b8b99b | 75 | CheckEnreg(); |
flowh | 1:e1f3b4b8b99b | 76 | Mesures.Update(); |
flowh | 1:e1f3b4b8b99b | 77 | } |
flowh | 1:e1f3b4b8b99b | 78 | |
flowh | 1:e1f3b4b8b99b | 79 | //------------------------ |
flowh | 1:e1f3b4b8b99b | 80 | // initialization of logger |
flowh | 1:e1f3b4b8b99b | 81 | |
flowh | 1:e1f3b4b8b99b | 82 | void Init() |
flowh | 1:e1f3b4b8b99b | 83 | { |
flowh | 1:e1f3b4b8b99b | 84 | TickUpdate.attach(&Update, SavePeriod); //starting the infinit loop |
flowh | 1:e1f3b4b8b99b | 85 | printf("\n\r"); |
flowh | 2:f53340e49cc0 | 86 | printf("DISCO logger V2.0\n\r"); |
flowh | 1:e1f3b4b8b99b | 87 | printf("----------------\n\r\n\r"); |
flowh | 1:e1f3b4b8b99b | 88 | |
flowh | 1:e1f3b4b8b99b | 89 | EnregistrementEnCours=false; |
flowh | 1:e1f3b4b8b99b | 90 | LedEnreg=0; |
flowh | 1:e1f3b4b8b99b | 91 | |
flowh | 1:e1f3b4b8b99b | 92 | printf("sensors started\n\r"); |
flowh | 1:e1f3b4b8b99b | 93 | |
flowh | 1:e1f3b4b8b99b | 94 | //Mount the filesystem |
flowh | 1:e1f3b4b8b99b | 95 | sd.mount(); |
flowh | 1:e1f3b4b8b99b | 96 | printf("File system mounted\n\r"); |
flowh | 2:f53340e49cc0 | 97 | printf("Toggle switch to start recording\n\r"); |
flowh | 1:e1f3b4b8b99b | 98 | |
flowh | 1:e1f3b4b8b99b | 99 | /* AIn[0]=&AIn0; |
flowh | 1:e1f3b4b8b99b | 100 | AIn[1]=&AIn1; |
flowh | 1:e1f3b4b8b99b | 101 | AIn[2]=&AIn2; |
flowh | 1:e1f3b4b8b99b | 102 | AIn[3]=&AIn3; |
flowh | 1:e1f3b4b8b99b | 103 | AIn[4]=&AIn4;*/ |
flowh | 0:0861bf46efe4 | 104 | } |