{"id":1471,"date":"2017-12-16T23:20:22","date_gmt":"2017-12-16T22:20:22","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1471"},"modified":"2018-01-05T23:32:39","modified_gmt":"2018-01-05T22:32:39","slug":"12-f746-demo_frq_spectrum-stm32f746","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1471","title":{"rendered":"12-F746-Demo_Frq_Spectrum (STM32F746)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1469\" title=\"11-F746-Demo_HTTP_Server (STM32F746)\"><span class=\"meta-nav\">\u2190<\/span> 11-F746-Demo_HTTP_Server (STM32F746)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=578\" title=\"XMC2Go-Board\">XMC2Go-Board <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Mit diesem Demo-Projekt wird Mic\/Line Input und LCD\/FFT+EAR Output des STM32F746-Discovery-Board getestet.<\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 28.02.2016\r\n\/\/ Version  : 1.0\r\n\/\/ Autor    : UB\r\n\/\/ EMail    : mc-4u(@)t-online.de\r\n\/\/ Web      : www.mikrocontroller-4u.de\r\n\/\/ CPU      : STM32F746\r\n\/\/ Board    : STM32F746-Discovery-Board\r\n\/\/ IDE      : OpenSTM32\r\n\/\/ GCC      : 4.9 2015q2\r\n\/\/ Module   : CubeHAL\r\n\/\/ Funktion : Hauptprogramm\r\n\/\/--------------------------------------------------------------\r\n\r\n\r\n#include \"stm32_ub_system.h\"\r\n#include \"stm32_ub_lcd_480x272.h\"\r\n#include \"stm32_ub_graphic2d.h\"\r\n#include \"stm32_ub_uart.h\"\r\n#include \"stm32f7_audio.h\"\r\n\r\n\/\/ add global define : ARM_MATH_CM7\r\n\/\/ add global define : __FPU_PRESENT=1\r\n\r\n\r\n#include \"arm_math.h\"\r\n#include \"arm_const_structs.h\"\r\n\r\n\r\n#define FFT_DATA                    512  \/\/ n*(real+imaginary)  DON'T CHANGE !!\r\n#define FFT_SIZE                FFT_DATA \/ 2\r\nfloat32_t FFT_Input[FFT_DATA];\r\nfloat32_t FFT_Output[FFT_SIZE];\r\n#define FFT_LCD_DATA            FFT_SIZE \/ 2\r\nuint16_t FFT_LCD[FFT_LCD_DATA];\r\n\r\n\r\n#define AUDIO_BUFFER_SIZE  1024*2  \/\/ size in 16bit words (n * left+right)\r\nuint16_t audio_buffer[AUDIO_BUFFER_SIZE];\r\n\r\n\r\n#define AUDIO_WAVE_HEIGHT  130\r\n#define FFT_WAVE_HEIGHT    200\r\n\r\n\r\n\r\narm_cfft_radix4_instance_f32 S;\r\n\r\n\r\nvoid init_hardware(void)\r\n{\r\n  UB_LCD_Init();\r\n  UB_LCD_LayerInit_Fullscreen();\r\n  UB_LCD_SetLayer_2();\r\n  UB_LCD_FillLayer(RGB_COL_BLUE);\r\n  UB_LCD_Refresh();\r\n\r\n  UB_Uart_Init();\r\n  UB_Uart_SendString(COM1,\"Frq-Spectrum\",CRLF);\r\n}\r\n\r\nvoid init_audio(uint8_t mode)\r\n{\r\n  if(mode==0) {\r\n    \/\/ input = mic, output = ear\r\n    UB_AUDIO_IN_OUT_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2,OUTPUT_DEVICE_HEADPHONE,90,I2S_AUDIOFREQ_44K);\r\n    UB_AUDIO_IN_Record_Array(audio_buffer, AUDIO_BUFFER_SIZE);\r\n    UB_AUDIO_OUT_Play_Array(audio_buffer, AUDIO_BUFFER_SIZE*2);\r\n  }\r\n  else {\r\n    \/\/ input = line, output = none\r\n\tUB_AUDIO_IN_Init(INPUT_DEVICE_INPUT_LINE_1,90,I2S_AUDIOFREQ_44K);\r\n\tUB_AUDIO_IN_Record_Array(audio_buffer, AUDIO_BUFFER_SIZE);\r\n  }\r\n}\r\n\r\nvoid init_fft(void)\r\n{\r\n\tarm_cfft_radix4_init_f32(&amp;S, FFT_SIZE, 0, 1);\r\n}\r\n\r\nvoid fill_fft(void)\r\n{\r\n\tuint32_t n;\r\n\tint16_t wert;\r\n\tint16_t min=audio_buffer[0];\r\n\tint16_t max=audio_buffer[0];\r\n\tint16_t delta;\r\n\tfloat faktor;\r\n\r\n\t\/\/ seach min and max audio value\r\n\t\/\/ to range fft_input from +2.0 to -2.0\r\n\tfor(n=0;n&lt;AUDIO_BUFFER_SIZE;n+=2) { wert=audio_buffer[n]; if(wert&gt;max) max=wert;\r\n\t\tif(wert&lt;min) min=wert;\r\n\t}\r\n\tdelta=max-min;\r\n\tfaktor=delta\/4;\r\n\r\n\t\/\/ convert audio-data in real+imaginary\r\n\tfor(n=0;n&lt;FFT_DATA;n+=2) { wert=audio_buffer[n]; FFT_Input[n]=(float32_t)(wert\/faktor); \/\/ real (+2.0 ... -2.0) FFT_Input[n+1]=0.0; \/\/ imaginary alway zero } } void calc_fft(unsigned char mode) { uint32_t maxIndex,n; float32_t maxValue; float32_t wert; \/\/ calculate fft (FFT_Input --&gt; FFT_Output)\r\n\tarm_cfft_radix4_f32(&amp;S, FFT_Input);\r\n\tarm_cmplx_mag_f32(FFT_Input, FFT_Output, FFT_SIZE);\r\n\tif(mode==0) {\r\n\t  \/\/ set variable limit\r\n\t  arm_max_f32(FFT_Output, FFT_SIZE, &amp;maxValue, &amp;maxIndex);\r\n\t}\r\n\telse {\r\n\t  \/\/ set fix limit\r\n\t  maxValue=100.0;\r\n\t}\r\n\r\n\t\/\/ calculate lcd values\r\n\tfor(n=0;n&lt;FFT_LCD_DATA;n++) {\r\n\t\twert=FFT_Output[n];\r\n\t\tFFT_LCD[n]=(uint16_t)(wert\/maxValue*(float)(FFT_WAVE_HEIGHT));\r\n\t}\r\n}\r\n\r\n\r\n\r\nvoid draw_fft(void)\r\n{\r\n\tuint32_t n;\r\n\tuint16_t x,l;\r\n\r\n\tUB_Graphic2D_DrawStraightDMA(0,LCD_MAXY-1,FFT_SIZE,LCD_DIR_HORIZONTAL,RGB_COL_RED);\r\n\r\n\t\/\/ draw data on screen\r\n\tx=0;\r\n\tfor(n=0;n&lt;FFT_LCD_DATA;n++) {\r\n\t\tl=FFT_LCD[n];\r\n\t\t\/\/ draw two lines for each data value\r\n\t\tUB_Graphic2D_DrawStraightDMA(x,LCD_MAXY-l,l,LCD_DIR_VERTICAL,RGB_COL_RED);\r\n\t\tUB_Graphic2D_DrawStraightDMA(x+1,LCD_MAXY-l,l,LCD_DIR_VERTICAL,RGB_COL_RED);\r\n\t\tx+=2;\r\n\t}\r\n}\r\n\r\nvoid draw_audio(void)\r\n{\r\n\tuint32_t n;\r\n\tint16_t wert,delta;\r\n\tint16_t min;\r\n\tfloat faktor;\r\n\tuint16_t x1,y1,y2,start=0;\r\n\tuint8_t status=0;\r\n\r\n\tdelta=5000;\r\n\tmin=-2500;\r\n\tfaktor=(float)(AUDIO_WAVE_HEIGHT)\/delta;\r\n\r\n\t\/\/ search trigger start (rising edge)\r\n\tfor(n=0;n&lt;(AUDIO_BUFFER_SIZE-(LCD_MAXX*2));n+=2) {\r\n\t\twert=audio_buffer[n];\r\n\t\tif(status==0) {\r\n\t\t\tif(wert&lt;(-100)) status=1; } else if(status==1) { if(wert&gt;=0) {\r\n\t\t\t\tstart=n;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t\/\/ draw data on screen\r\n\tx1=0;\r\n\ty1=AUDIO_WAVE_HEIGHT\/2;\r\n\tfor(n=0;n&lt;(LCD_MAXX*2);n+=2) { wert=audio_buffer[n+start]; y2=((wert-min)*faktor); UB_Graphic2D_DrawLineNormal(x1,y1,x1+1,y2,RGB_COL_WHITE); y1=y2; x1++; } } \/\/ called by audio dma interrupt void update_lcd(void) { static uint16_t display_delay=0; display_delay++; if(display_delay&gt;2) {\r\n\t\tdisplay_delay=0;\r\n\t\tfill_fft();\r\n\t\tcalc_fft(0); \/\/ fft-height : 0=fix, 1=variable\r\n\t\tUB_Graphic2D_ClearSreenDMA(RGB_COL_BLUE);\r\n\t\tdraw_audio();\r\n\t\tdraw_fft();\r\n\t\tUB_LCD_Refresh();\r\n\t}\r\n}\r\n\r\nint main(void)\r\n{\r\n  \/\/ init vom System\r\n  UB_System_Init();\r\n\r\n\r\n  init_hardware();\r\n  init_audio(0); \/\/ input : 0=mic, 1=line\r\n  init_fft();\r\n\r\n\r\n  while(1) {\r\n\t  \/\/ nothing to do\r\n  }\r\n}\r\n<\/pre>\n<p>Hier der komplette OpenSTM32-Projektordner zum\u00a0Download :<\/p>\n<ul>\n<li><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2016\/03\/F746_Show_Frq_Spectrum.zip\">F746_Show_Frq_Spectrum<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Mit diesem Demo-Projekt wird Mic\/Line Input und LCD\/FFT+EAR Output des STM32F746-Discovery-Board getestet. \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; \/\/ File : main.c \/\/ Datum : 28.02.2016 \/\/ Version : 1.0 \/\/ Autor : UB \/\/ EMail : mc-4u(@)t-online.de \/\/ Web : www.mikrocontroller-4u.de \/\/ CPU : &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1471\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1444,"menu_order":12,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[289,130],"tags":[179,178,139,177,176,167,105],"class_list":["post-1471","page","type-page","status-publish","hentry","category-demo-projekte","category-stm32f746","tag-ear-output","tag-fft","tag-lcd","tag-line-input","tag-mic","tag-projekt","tag-stm32f746"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1471"}],"version-history":[{"count":3,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1471\/revisions"}],"predecessor-version":[{"id":1892,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1471\/revisions\/1892"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1444"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}