![]() |
Forum Index : Microcontroller and PC projects : Audio waveform & frequency in MMBasic
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Please view the video ![]() Cycle time is 180mSec and it is running a 1024 point FFT on each channel each cycle as well as playing a WAV file, running the ADC at 10KHz per channel and updating the display !!!!! ![]() Only on the Armmite H7 of course. ' ' OPTION LCDPANEL SSD1963_5_BUFF,RL ' OPTION SDCARD 110,87 ' Option explicit Option default none Option VCC 3.308 Const SAMPLESPERSEC = 10000 Const NSAMPLES = 1024 Const PLOTFREQ = NSAMPLES\512 Option autorefresh off Dim integer i, j, imax, imax1, toggle Dim float a(NSAMPLES-1) , b(NSAMPLES-1), a1(NSAMPLES-1), b1(NSAMPLES-1) Dim integer c%(179), d%(179) Dim float m(NSAMPLES-1) , mmax , m1(NSAMPLES-1), mmax1 CLS ' ' First set up some signals using the onboard DAC playing music ' connect pin 40 to pin 49 and pin 41 to pin 22 ' ' start the DAC ' Play wav "future" 'Leonard Cohen ' ' convert the signals ' toggle=1 ADC open SAMPLESPERSEC, 49, 22,, adc_done ADC start a(), b() Text 10,40,"Channel 1",,3 Text 10,150,"Frequency 1",,3 Text 10,320,"Channel 2",,3 Text 10,430,"Frequency 2",,3 Do Do Loop While j=0 j=0 If toggle Then ADC start a1(),b1() toggle=0 Else ADC start a(),b() toggle=1 EndIf ' ' frequency analyse the signals ' If toggle Then FFT magnitude b1(),m() FFT magnitude a1(),m1() Else FFT magnitude b(),m() FFT magnitude a(),m1() EndIf Box 194,0,MM.HRes-287,MM.VRes,1,&HFFFFFF,0 ' ' find the maximum magnitude of the frequencies ' mmax=0 mmax1=0 For i=1 To NSAMPLES\2-1 If m(i)>mmax Then mmax=m(i) imax=i EndIf If m1(i)>mmax1 Then mmax1=m1(i) imax1=i EndIf Next i ' ' plot the samples ' For i=1 To 255 If toggle Then Line i*2+194, 130 - a1(i-1)*40, i*2+195, 130 - a1(i)*40, 1, RGB(magenta) Line i*2+194, 410 - b1(i-1)*50, i*2+195, 410 - b1(i)*50, 1, RGB(green) Else Line i*2+194, 130 - a(i-1)*40, i*2+195, 130 - a(i)*40, 1, RGB(magenta) Line i*2+194, 410 - b(i-1)*50, i*2+195, 410 - b(i)*50, 1, RGB(green) EndIf Next i ' ' plot the frequency analyses ' For i=2 To 255 Line i*2+193,470-m((i-1)*PLOTFREQ/2)/mmax*100 ,i*2+194, 470 - m(i*PLOTFREQ/ 2)/mmax*100 , 1, RGB(yellow) Line i*2+193,190-m1((i-1)*PLOTFREQ/2)/mmax1*100, i*2+194, 190 - m1(i*PLOTFR EQ/2)/mmax1*100, 1, RGB(yellow) Next i Refresh Loop ' End Sub adc_done j=1 End Sub |
||||
2001cpx![]() Regular Member ![]() Joined: 03/10/2013 Location: CanadaPosts: 59 |
Hi, Great Work! Very Impressive!!! a bandpass Filter Using ADC and Dac can be Possible? Very Interesting!! Thanks! "Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2" |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1114 |
Fantastic work Peter, very impressive. Is the FFT function part of the H7 MMBasic or something you are working on including? panky ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
@panky It's in the latest firmware for the H7 Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
My first attempt with an MPU-6050 gyro measuring a tremor. Most of the code is Peter's audio example with my bit filling the array with motion data from the gyro. The readings were taken at 10mS intervals. ![]() I saved the screen as an image after drawing it. It takes a long time to transfer a 800x480 BMP with xmodem! The measured 5.47 Hz is right in the expected range. VK7JH MMedit |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Jim I'm delighted its working for you. Attached updated version of my program that uses a drawing optimisation that I'd forgotten about - significantly improves cycle time. The change should be obvious. ' ' OPTION LCDPANEL SSD1963_5_BUFF,RL ' OPTION SDCARD 110,87 ' Option explicit Option default none Option VCC 3.308 Const SAMPLESPERSEC = 10000 Const NSAMPLES = 512 Const PLOTFREQ = NSAMPLES/1024 Option autorefresh off Dim integer i, j, imax, imax1, toggle Dim float a(NSAMPLES-1) , b(NSAMPLES-1), a1(NSAMPLES-1), b1(NSAMPLES-1) Dim integer c%(179), d%(179), x1(255),x2(255),y1(255), y2(255), y3(255), y4(255) Dim float m(NSAMPLES-1) , mmax , m1(NSAMPLES-1), mmax1 CLS For i=0 To 255 x1(i)= i*2+194 x2(i)= i*2+195 Next i ' ' First set up some signals using the onboard DAC playing music ' connect pin 40 to pin 49 and pin 41 to pin 22 ' ' start the DAC ' Play wav "future" ' ' convert the signals ' toggle=1 ADC open SAMPLESPERSEC, 49, 22,, adc_done ADC start a(), b() Text 10,40,"Channel 1",,3 Text 10,150,"Frequency 1",,3 Text 10,320,"Channel 2",,3 Text 10,430,"Frequency 2",,3 Do Do Loop While j=0 j=0 If toggle Then ADC start a1(),b1() toggle=0 Else ADC start a(),b() toggle=1 EndIf ' ' frequency analyse the signals ' If toggle Then FFT magnitude b1(),m() FFT magnitude a1(),m1() Else FFT magnitude b(),m() FFT magnitude a(),m1() EndIf Box 194,0,MM.HRes-287,MM.VRes,1,&HFFFFFF,0 ' ' find the maximum magnitude of the frequencies ' mmax=0 mmax1=0 For i=1 To NSAMPLES\2-1 If m(i)>mmax Then mmax=m(i) imax=i EndIf If m1(i)>mmax1 Then mmax1=m1(i) imax1=i EndIf Next i mmax=mmax / 100 mmax1=mmax1 /100 ' ' plot the samples ' For i=1 To 255 If toggle Then y1(i)=130 - a1(i-1)*40 y2(i)=130 - a1(i)*40 y3(i)=410 - b1(i-1)*40 y4(i)=410 - b1(i)*40 Else y1(i)=130 - a(i-1)*40 y2(i)=130 - a(i)*40 y3(i)=410 - b(i-1)*40 y4(i)=410 - b(i)*40 EndIf Next i Line x1(),y1(),x2(),y2(),1,RGB(magenta) Line x1(),y3(),x2(),y4(),1,RGB(green) ' ' plot the frequency analyses ' For i=2 To 255 y1(i)=470-m((i-1)*PLOTFREQ)/mmax y2(i)=470 - m(i*PLOTFREQ)/mmax y3(i)=190-m1((i-1)*PLOTFREQ)/mmax1 y4(i)=190 - m1(i*PLOTFREQ)/mmax1 Next i Line x1(),y1(),x2(),y2(),1,RGB(yellow) Line x1(),y3(),x2(),y4(),1,RGB(yellow) Refresh Loop ' End Sub adc_done j=1 End Sub |
||||
Gray Newbie ![]() Joined: 26/08/2017 Location: AustraliaPosts: 1 |
Wow that's awesome work matherp. A MM Spectrum Analyser would make a fantastic project. What would the minimum and maximum frequency range be? Graham ![]() |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Maximum sample rate of ADC is 500KHz, slowest - very |
||||
KeepIS![]() Guru ![]() Joined: 13/10/2014 Location: AustraliaPosts: 1882 |
Hi matherp, the option for SSD1963 with buffer will only allow 5" or 7" not 8" OPTION LCDPANEL SSD1963_n_BUFF, orientation Selects 16-bit bus operation of the 5” and 7” SSD1963 displays using a memory framebuffer for improved performance. This uses 400K of memory leaving 98K for user programs. Apart from oversight with so many thing going on (all great BTW), is there any reason why SSD1963_8_BUFF cannot be added to that option? Mike. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
KeepIS![]() Guru ![]() Joined: 13/10/2014 Location: AustraliaPosts: 1882 |
Thanks for the updated buffer option, for anyone new reading this thread, the latest update is at Updated firmware and manual for H7 NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |