multithreading example

Dependencies:   FastAnalogIn

Files at this revision

API Documentation at this revision

Comitter:
candre97
Date:
Tue Dec 03 22:39:22 2019 +0000
Parent:
112:a0fd359ec3a6
Commit message:
yutong, look here

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a0fd359ec3a6 -r 233a2fac1911 main.cpp
--- a/main.cpp	Mon Dec 02 06:12:17 2019 +0000
+++ b/main.cpp	Tue Dec 03 22:39:22 2019 +0000
@@ -28,7 +28,7 @@
 #define WINDOW_SIZE         DEF_WINLENGTH - DEF_FRAMESHIFT
 #define ARRAY_SIZE          800
  
-#define BUFFSIZE                    1760 // size of buffer = sampling_time * sampling_rate * size(float)
+#define BUFFSIZE                    11100 // size of buffer = sampling_time * sampling_rate * size(float)
 //DigitalOut led1(LED1);
 //DigitalOut led2(LED2);
 Thread thread_adc;
@@ -115,33 +115,33 @@
     buff.clear();
     printf("library read val: %u\n", mic.read_u16());
     
-    /* Setup and initialize ADC converter   https://www.davidkebo.com/microcontroller-interfacing */
-    RCC->APB2RSTR |=  1 <<  9;             /* Enable ADC1 clock                  */
-    GPIOA->CRL   &= 0xFFF0FFFF;           /* Configure PC4 as ADC.14 input      */
-    ADC1->SQR1    = 0x00000000;           /* Regular channel 1 conversion       */
-    ADC1->SQR2    = 0x00000000;           /* Clear register                     */
-    ADC1->SQR3    = 14 <<  0;             /* SQ1 = channel 14                   */
-    ADC1->SMPR1   =  5 << 12;             /* Channel 14 sample time is 55.5 cyc */
-    ADC1->SMPR2   = 0x00000000;           /* Clear register                     */
-    ADC1->CR1     =  1 <<  8;             /* Scan mode on                       */
-    ADC1->CR2     = (1 << 20) |           /* Enable external trigger            */
-                  (7 << 17) |           /* EXTSEL = SWSTART                   */
-                  (1 <<  1) |           /* Continuous conversion              */
-                  (1 <<  0) ;           /* ADC enable                         */
-    ADC1->CR2    |=  1 <<  3;             /* Initialize calibration registers   */
-    while (ADC1->CR2 & (1 << 3));         /* Wait for initialization to finish  */
-    ADC1->CR2    |=  1 <<  2;             /* Start calibration                  */
-    while (ADC1->CR2 & (1 << 2));         /* Wait for calibration to finish     */
-    ADC1->CR2    |=  1 << 22;             /* Start first conversion  */
-    
-    for (;;) {                            /* Loop forever                       */
-        if (ADC1->SR & (1 << 1)) {          /* If conversion has finished         */
-          raw_adc = ADC1->DR & 0x0FFF;       /* Read AD converted value            */
-          ADC1->CR2 |= 1 << 22;             /* Start new conversion               */ 
-        }
-        printf("register read val: %u\n", raw_adc);
-        thread_sleep_for(2000);
-    }
+//    /* Setup and initialize ADC converter   https://www.davidkebo.com/microcontroller-interfacing */
+//    RCC->APB2RSTR |=  1 <<  9;             /* Enable ADC1 clock                  */
+//    GPIOA->ARL   &= 0xFFF0FFFF;           /* Configure PC4 as ADC.14 input      */
+//    ADC1->SQR1    = 0x00000000;           /* Regular channel 1 conversion       */
+//    ADC1->SQR2    = 0x00000000;           /* Clear register                     */
+//    ADC1->SQR3    = 14 <<  0;             /* SQ1 = channel 14                   */
+//    ADC1->SMPR1   =  5 << 12;             /* Channel 14 sample time is 55.5 cyc */
+//    ADC1->SMPR2   = 0x00000000;           /* Clear register                     */
+//    ADC1->CR1     =  1 <<  8;             /* Scan mode on                       */
+//    ADC1->CR2     = (1 << 20) |           /* Enable external trigger            */
+//                  (7 << 17) |           /* EXTSEL = SWSTART                   */
+//                  (1 <<  1) |           /* Continuous conversion              */
+//                  (1 <<  0) ;           /* ADC enable                         */
+//    ADC1->CR2    |=  1 <<  3;             /* Initialize calibration registers   */
+//    while (ADC1->CR2 & (1 << 3));         /* Wait for initialization to finish  */
+//    ADC1->CR2    |=  1 <<  2;             /* Start calibration                  */
+//    while (ADC1->CR2 & (1 << 2));         /* Wait for calibration to finish     */
+//    ADC1->CR2    |=  1 << 22;             /* Start first conversion  */
+//    
+//    for (;;) {                            /* Loop forever                       */
+//        if (ADC1->SR & (1 << 1)) {          /* If conversion has finished         */
+//          raw_adc = ADC1->DR & 0x0FFF;       /* Read AD converted value            */
+//          ADC1->CR2 |= 1 << 22;             /* Start new conversion               */ 
+//        }
+//        printf("register read val: %u\n", raw_adc);
+//        thread_sleep_for(2000);
+//    }