AD変換をしている(DMA)

Dependencies:   ADC SD mbed

Files at this revision

API Documentation at this revision

Comitter:
k0050288
Date:
Tue Jul 17 04:52:19 2018 +0000
Commit message:
AD??(DMA)

Changed in this revision

ADC.lib Show annotated file Show diff for this revision Revisions of this file
SD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
readme.txt Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC.lib	Tue Jul 17 04:52:19 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/1529561000/code/ADC/#c5f50c994173
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SD.lib	Tue Jul 17 04:52:19 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/1529561000/code/SD/#8023ba647c93
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 17 04:52:19 2018 +0000
@@ -0,0 +1,48 @@
+// F446RE ADC with DMA
+// ADC read shifted to 16 bits, our readn is only 12 bits
+// messy, TODO need ADC channel from pin number
+
+#include "mbed.h"
+#include "adc.h"
+#include "SD.h"
+
+adc gadc;
+SD  gSD;
+
+DigitalIn btn(USER_BUTTON);  // User button
+PwmOut OSILO_PWM(PC_7);
+Serial pc(USBTX, USBRX); // tx, rx
+
+void user_system_create()
+{
+    gadc.init();
+    gSD.init();
+
+    // PWM出力の初期化処理 <PWM出力開始>
+    OSILO_PWM.period_ms(1);     // PWM周波数は1kHz(周期:1ms)
+    OSILO_PWM.write(0.5f);      // Duty比:50%
+}
+
+int main()
+{
+    /* init */
+    user_system_create();
+
+    pc.printf("PUSH USER BUTTON\n");
+    while(btn); // Wait user button
+
+    /* Start ADC with DMA */
+    pc.printf("Start ADC\n");
+    gadc.read(gadc.ADCVal, sizeof(gadc.ADCVal));
+
+    for(int i = 0; i < ADC_TIMES; i++) {
+        pc.printf("%d,%d\n",i,gadc.ADCVal[i]);
+    }
+
+    for(int i = 0; i < ADC_TIMES; i++) {
+        gSD.setData(i, gadc.ADCVal[i]);
+        gSD.write();
+    }
+    
+    gSD.finish();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jul 17 04:52:19 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/readme.txt	Tue Jul 17 04:52:19 2018 +0000
@@ -0,0 +1,14 @@
+DMAでAD変換をするプログラム
+
+AD変換した値をSDカードにcsvで保存しています.
+
+問題点(2018/07/13現在)
+adc.cppの74行目
+
+hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH;
+
+DMA_PRIORITY_HIGH を DMA_PRIORITY_VERY_HIGH
+にしてしまうとAD変換が行われない問題がある.
+
+DMA_PRIORITY_VERY_HIGH にすると変換速度が上がると思うけど…
+DMA_PRIORITY_HIGH だと1.5MHzの変換速度を達成している.
\ No newline at end of file