2678 views|1 replies

1

Posts

0

Resources
The OP
 

Xu Qi, Li Dong: MCU Music Spectrum [Copy link]

 
Abstract
With the progress of the times, electronic information technology has been widely used in all aspects of life, and people pay more and more attention to the enjoyment of vision, hearing and sound quality. The music signal spectrum has many advantages and is now widely used in many fields.
The music spectrum display can directly observe the input status of the signal to be displayed, and can also give people visual enjoyment and give music dynamic beauty. The circuit designed this time can be divided into three parts: they are filtering circuit, audio input circuit, and LED lamp driving circuit. The music signal is transmitted to the single-chip microcomputer through the audio input circuit. The audio signal sampled by A/D is obtained by FFT operation to obtain the frequency component required at a certain moment to drive the display of the LED lamp.
Through the production of this music spectrum, our welding technology and drawing ability have been improved. At the same time, we cooperated with our companions to complete the work together, which improved our teamwork ability. More importantly, I learned a lot of relevant knowledge, and my personal ability has been exercised, laying a foundation for future course learning.
Abstract
Along with the progress of the era, the electricity information technology dominated almost the whole of the development of the electronics industry, people pay more and more attention to the enjoyment of visual, and audio sound quality. Audio signal spectrum displaybecause of its many advantages, has been widely used in many fields areinvolved in at the moment. an audio input circuit, filter circuit and LEDdriver circuit. Music signal after the A/D sampling of audio signal by audioinput circuit for sometime after FFT computation to the frequency of thecomponent, LED display driver.
Through the spectrum of music making, improve welding technology, drawing ability, at the same time, we work with partners, finish the works together, improve theteam cooperation ability .More importantly, I learn a lot about it, Personalability is even more exercised, It lays the foundation for future courses. Introduction to microcontroller
This system uses STC12C5A60S2 series microcontroller. STC12C5A60S2 series microcontroller is a single clock, machine cycle (1T) microcontroller produced by Hongjing Technology. It is a new generation of 8051 microcontroller with high speed, low power consumption and super anti-interference. The instruction code is fully compatible with the traditional 8051, but the speed is 8-12 times faster. It integrates MAX810 dedicated reset circuit, 2-way PWM, 8-way high-speed 10-bit A/D conversion (250K/S), for motor control and strong interference occasions.
2.2 Product Advantages
Among the numerous 51series of MCUs, the 1Tenhanced series of STC, a domestic company, is more competitive, because it not only The instructions and pins of 8051 are fully compatible, and the chip has a large-capacity program memory and is made of FLASH technology. For example, the STC12C5A60S2 microcontroller has a built-in high-capacity memory.0pt]60K FLASHROM,This kind of memory can be erased and rewritten instantly by electricity. Moreover,STCseries microcontrollers support serial port program burning. Obviously, this kind of microcontroller has very low requirements for development equipment and greatly shortens the development time. The program written into the microcontroller can also be encrypted, which protects the labor results well.
III. Overall design
3.1 System circuit design
The system can be divided into the following three parts in terms of function:
1. The audio data acquisition circuit realizes the acquisition of analog audio signals, converts the acquired analog signals into digital signals and processes them quantitatively, including the audio acquisition circuit and the AD conversion circuit. 2. The spectrum display circuit realizes the segmented display of the analog audio signal spectrum. It divides the audio signal spectrum into 11 segments, and each segment is quantized at 11 levels to drive the LED for display. 3. The main controller uses the STC12C5A60S2 single-chip microcomputer. Under the condition of completing other control tasks of the system, it makes full use of the remaining resources of the single-chip microcomputer, uses the optimized FFT algorithm to calculate the audio signal spectrum, and inputs the calculation result into the spectrum display circuit. 3.2 Music Spectrum Performance 1. Since the frequency range of the audio signal is 300Hz-3400Hz or 20Hz-20kHz, according to the sampling theorem, in order to ensure that the information is not distorted, the sampling frequency of the system is determined to be 8kHz or 96kHz. 2. Combined with the processing speed of the STC12C5A60S2 microcontroller and the signal sampling frequency requirements of the system, the STC12C5A60S2 microcontroller is used as the A/D conversion module of the system.
3. Determine the system's peripheral interface method based on the above technical indicators
3.3Main principle
The working principle of this system is that the P0 port receives the input of the voltage signal, the audio signal is transmitted to the STC12C5A60S2 microcontroller through the audio line, the input audio signal is AD converted, the filtering in the circuit and the FFT transformation program in the microcontroller are called to analyze the audio digital signal, the microcontroller quantifies the signal amplitude and drives the LED display.
Fourth, algorithm analysis and design
4.1Core algorithmFFT
The method of using FFT in production is: First, we use ADC to sample an analog signal and convert it into a digital signal. Secondly, the sampled digital signal is sent to FFT for transformation processing. Usually, if we take N sampling points, after FFT operation, we can get the FFT results of N points. Assume Fs is the sampling frequency of ADC, N is the number of Fourier transform points, then the minimum resolution frequency f=Fs/N, so the lowest frequency displayed by the spectrum is fHZ.
4 .2 Single-chip microcomputer implementation FFT
The core of the program is to use the FFT algorithm to process the AD data read from the collected audio signal, and then process it through the FFT formula, and then take out the amplitude value of the frequency, quantize these values into the corresponding number of LED lights and display them, which is the main application of this algorithm.
4.3 Automatic gain control
In order to avoid the problem of not displaying when the sound is too small and displaying the full screen when the sound is too large, an automatic gain program is added to the program, which can adjust the spectrum display amplitude according to the sound size.
V. Circuit design
5.1 Filter module
The power supply uses +5V voltage, and a 220uf capacitor is added to the positive and negative poles of the power supply to make the audio output more stable. 5.2 MCU Processing Module The STC12C5A60S2 MCU performs AD conversion and FFT (Fast Fourier Transform) to process the signal, so that the audio signal is converted, processed, and output to the display module. 5.3 Audio Input Module The audio input module mainly completes the sampling of the input audio signal and performs A/D conversion, voice sampling encoding and decoding, and filtering on the collected sound signal. The audio spectrum is worth calculating using the Fast Fourier Algorithm FFT. The working principle of this module is: the audio signal is transmitted to the STC12C5A60S2 MCU through the audio line, the input audio signal is converted into AD, and the filtering in the circuit and the FFT transformation program in the MCU are called to analyze the audio digital signal. 4.4 LED Music Spectrum Display Module The display part is arranged in 5*11, with 11 LEDs in 5 colors, a total of 55 LED lights. All lights are connected in parallel. When the audio interface has music input and the power supply module is normal, the music column of the music player can be simulated. VI. System Debugging and Testing 6.1 System Debugging 1. Check the schematic diagram of the circuit design to make sure that the line connection is consistent with the schematic diagram. 2. Check whether there is a circuit break. Use a digital multimeter to set the appropriate gear to test whether the corresponding points of each line are connected. 3. Check whether the equipment is intact and the 5V DC power supply output is normal. All light-emitting diodes can emit light normally, and all resistors and capacitors are normal. When the audio jack is plugged in and music is played, the LED lights can jump normally with the music.
After the circuit is connected, the test phenomena are normal and the debugging is successful.
6.2System test
Connect the USB port, connect the audio interface, and play music. The effect is as shown in the figure:
6.3Problems encountered in debugging and testing
Because the filter module was not added to the circuit during the first debugging, the LED light could not light up. After adding a 220uf capacitor to the positive and negative poles respectively, the LED light can jump normally with the music.
Attachment: Main program
#includeCheck whether the equipment is intact and the 5V DC power supply output is normal. All the LEDs can emit light normally, and the resistors and capacitors are all normal. When the audio jack is plugged in and music is played, the LED light can jump normally with the music.
After the circuit is connected, the test phenomena are normal and the debugging is successful.
6.2System test
Connect the USB port, connect the audio interface, and play music. The effect is as shown in the figure:
6.3Problems encountered in debugging and testing
Because the filter module was not added to the circuit during the first debugging, the LED light could not light up. After adding a 220uf capacitor to the positive and negative poles respectively, the LED light can jump normally with the music.
Attachment: Main program
#includeCheck whether the equipment is intact and the 5V DC power supply output is normal. All the LEDs can emit light normally, and the resistors and capacitors are all normal. When the audio jack is plugged in and music is played, the LED light can jump normally with the music.
After the circuit is connected, the test phenomena are normal and the debugging is successful.
6.2System test
Connect the USB port, connect the audio interface, and play music. The effect is as shown in the figure:
6.3Problems encountered in debugging and testing
Because the filter module was not added to the circuit during the first debugging, the LED light could not light up. After adding a 220uf capacitor to the positive and negative poles respectively, the LED light can jump normally with the music.
Attachment: Main program
#include//"stc12c5620ad.h"
#include
#define LongToBin(n) (((n>>21)&0x80)|((n>>18)&0x40)|((n>>15)&0x20)|((n>>12)&0x10)|((n>>9)&0 x08)|((n>>6)&0x04)|((n>>3)&0x02)|((n)&0x01))
#define BIN(n) LongToBin(0x##n##)
#define uchar unsigned char
#define uint unsigned int
#define SAMPLE_NUM 64
#define NUM_2_LOG 6
#define FFT_OUT_MIN 3
uchar code BRTable[SAMPLE_NUM] ={ 0, 32,16, 48, 8, 40, 24, 56,4, 36 , 20, 52, 12, 44, 28, 60, 2, 34, 18, 50, 10, 42, 26,58, 6, 38, 22, 54, 14, 46, 30, 62, 1, 33, 17, 49, 9, 41, 25, 57,5, 37, 21, 53, 13, 45, 29, 61,3, 35, 19, 51, 11, 43, 27, 59,7, 39, 23, 55, 15, 47, 31, 63};
char code sin_tabb[SAMPLE_NUM] = { 0 ,12,25 ,37 ,49 ,60 , 71,81,90,98,106,112,117 ,122 ,125 ,126 ,127 ,126 ,125,122 ,117 ,112 ,106 ,98 ,90 ,81 ,71 ,60 ,49 ,37 ,25 ,12 ,0 ,-12 ,-25 ,-37 ,-49 ,-60 ,-71 ,-81 ,-90 ,-98 ,-106 ,-112 ,-117 ,-122 ,-125 ,-126 ,-127 ,-126 ,-125,-122 ,-117 ,-112 ,-106 ,-98 ,-90 ,- 81,-71,-60,-49,-37 ,-25 ,-12 };
char code cos_tabb[SAMPLE_NUM] = {127 ,126,125 ,122 ,117 ,112 ,106 ,98 ,90 , 81,71,60,49,37,25,12 ,0 ,-12 ,-25 ,-37,-49 ,-60 ,-71 ,-81 ,-90 ,-98 ,-106 ,-112 ,-117 ,-122 ,-125 ,-126 ,-127 ,-126,-125 ,- 122,-117,-112,-106,-98 ,-90 ,-81 ,-71 ,-60 ,-49 ,-37 ,-25 ,-12 ,0,12 ,25 ,37 ,49 ,60 ,71 ,81 ,90 ,98 ,106 ,112 ,117 ,122 ,125 ,126 };
uchar a[21];ucharkeep,keepnum,anum,timernum,timernum2,lednum3,Ltime;//used for separation ]/*Add array to display the corresponding number of LED lights*/
ucharlednum[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//0 -7 display array P2 group control
int xdata FftReal [SAMPLE_NUM];
int xdata FftImage [SAMPLE_NUM];
sbit p30=P3^0; //define p3_0 as the first bit of port p3 p31=P3^1;
sbit p32=P3^2;
sbit p33=P3^3;
sbit p34= P3^4;
sbit p35=P3^5;//9-11 led control
sbit p36=P3^6;
[align =left]sbit p37=P3^7;
void timerinit()//timer initialization function
{[/ TMOD=0x01; //Set timer 0 to working mode 1 TH0=(65536-6000)/256; //Install the initial value of 11.0592M crystal oscillator timing 50ms number is 6000
TL0=(65536-6000)%256;
EA=1; //Open the general interrupt ET0=1; //Open timer 0 interrupt TR0=1; //Start timer 0 void disp(){ timernum++; if (timernum == 6) timernum =1;
P2=0;//Close before display
P3=P3&0x1f;
switch(timernum)[/ case1:anum=a[0];p34=0;p33=1;p32=1;p31=1;p30=1;break;
case2:anum=a[1];p34=1 ;p33=0;p32=1;p31=1;p30=1;break;
case3:anum=a[2];p34=1;p33=1;p32=0;p31=1;p30=1;break;
case4:anum=a[3];p34 =1;p33=1;p32=1;p31=0;p30=1;break;
case5:anum=a[4];p34=1;p33=1;p32=1;p31=1;p30=0;break; } //anum=a[10];/*Modify to change the light column height (anum value is divided into several parts and displayed separately by timer) (increment in a[]) */
if( anum<=8){P2=lednum[anum];P3=P3&0xff;}//Shield the upper three bits 1f
//else{P2=0xff;P3=lednum2[anum-9]; if(anum==9){P2=0xff;p35=1;p36=0;p37=0;} if(anum==10){P2=0xff;p35=1;p36=1;p37=0;}
if(anum==11){P2=0xff;p35=1; p36=1;p37=1;}
}
uchar STC_ADC() //! ! Write an ad reading function according to the data sheet
{
uchar i;
ADC_RES = 0;
[align =left] ADC_RESL = 0;
ADC_CONTR = BIN(10001000);
i=3;
while(i--);
while (1)
{
if (ADC_CONTR & BIN(10000)) [/ align]
{
break;
}
}
ADC_CONTR = BIN(10000000);
return( ADC_RESL<<2) ;
}
short sqrt_16( unsigned long M)
{
unsigned int N, i;
unsigned long tmp,ttp;
if( M == 0 )
return 0;
N= 0;
tmp = ( M >> 30 );
M<<= 2;
[align =left] if( tmp > 1 )
{
N ++;
tmp -= N;
}
for( i=15; i>0; i-- )
{[/ align]
N <<= 1;
tmp <<= 2;
tmp += (M >> 30);
ttp = N;
[align= left] ttp = (ttp<<1)+1;
M <<= 2;
if( tmp > = ttp )
{
tmp -= ttp;
N ++;
}
}
return N;
}
void FFT()
{
register uchar i,bb,j,k,p,max;
register short TR,TI,temp;
unsigned long ulReal;
[align=left ] unsigned long ulImage;
for(i=0; i" else="" elseif((2="0;
" fftreal[brtable]="STC_ADC()<<keep;//使显示保持在一定范围内
" fftreal[k]="FftReal[k]" for(="" i="1;" i++)="" i<="NUM_2_LOG;" if((7
" j="0;" j++)="" j<="bb-1;" k="j;" k" p="1;
" temp="FftReal[k+bb];
" ti="FftImage[k];" tr="FftReal[k];" {="" {[="" {keep="2;}
" }="" 此处可以加入自动增益[="">>7) +((FftImage[k+bb]*sin_tabb[p])>>7);
                FftImage[k] = FftImage[k] -((FftReal[k+bb]*sin_tabb[p])>>7) +((FftImage[k+bb]*cos_tabb[p])>>7);
                FftReal[k+bb] = TR -((FftReal[k+bb]*cos_tabb[p])>>7) -((FftImage[k+bb]*sin_tabb[p])>>7);
                FftImage[k+bb] = TI +((temp*sin_tabb[p])>>7) - ((FftImage[k+bb]*cos_tabb[p])>>7);
               
                FftReal[k]  >>= 1;            
                FftImage[k]  >>= 1;
                FftReal[k+bb]  >>= 1;                 
                FftImage[k+bb]  >>= 1;
                                                                              
           }  
       }
    }
   max=0;
   for( i=0; i<5; i++)//5
   {  
       ulReal = FftReal[i+1];
       ulReal *= ulReal;
       ulImage = FftImage[i+1];
       ulImage *= ulImage;
      
       a = sqrt_16( ulReal + ulImage );  //修改
                        
       if( a < FFT_OUT_MIN )     
           a = 0;//修改
       else
         a = a-FFT_OUT_MIN;
       if( a >max)
            max =a;
                  //disp();                     
    }
   if(max>11) //11
    {
      max/=11;  
       for( i=0; i<5; i++) //输出a的5个分离数值
       {      
            a/=max;
           
       }  
    }
}            
void main()
{
   P2M0=0xff;//  BIN(11111111);//P2组设置为推挽输出
   P2M1=0;         
   P3M0=0xe0;//  BIN(11111111);
   P3M1=0;
   P1M0=0x00;
   P1M1=0x01;
  P1ASF =1;        //设置P1.0为AD口
   AUXR1 =BIN(100);
   keep=0;
   keepnum=0;
   timerinit();//定时器初始化
   timernum=3;//从3开始
   timernum2=0;
   while(1)
    {
              FFT();
    }
}
void timer0() interrupt 1
{
   TH0=(65536-6000)/256;    //6000
   TL0=(65536-6000)%256;
   disp();
}

         


This post is from Innovation Lab

Latest reply

Well written, the effect of the work is quite good, and you need to work harder in the future; Pay attention to the style of the code, and don't forget to write comments after each line of code; There are not enough pictures that can show the effect of the work  Details Published on 2018-9-1 15:46
 
 

693

Posts

7

Resources
2
 
Well written, the effect of the work is quite good, and you need to work harder in the future; Pay attention to the style of the code, and don't forget to write comments after each line of code; There are not enough pictures that can show the effect of the work
This post is from Innovation Lab
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list