It has been briefly discussed before , According to my personal novice understanding and understanding , Review the previous knowledge :

DMA: My understanding is a channel , Or a bridge . From static memory to static memory , Or a communication channel between peripherals and static memory . The advantage of building this channel is : You can get rid of CPU, Not occupy CPU Resources for , Use the contents of this memory directly , It's going to speed up .

DAC:STM32F103 There are two DAC, Can be used at the same time .DAC Its function is to convert digital quantity into analog quantity ( voltage ), I won't explain too much here .

TIMER: Timer . No explanation .

So for the use of DMA+DAC+TIMER The principle or process of producing a sine wave , I have such a simple understanding :

First, save a data table that can generate sine wave in static memory , And then in DAC And this memory is used in the middle DMA Build a channel , After the above steps ,DAC Modules can be accessed through DAM Channel takes the data that can generate sine wave in static memory , Take the data , And then through digital to analog conversion , In the pin output, you can get a sine wave . Well, of course. , It's very fast , If there is no delay , Then the estimation is a fast changing analog quantity . So this time you need to use a timer TIMER 了 .DAC At initialization time , Can be set to use timer trigger , That means , When the timer is full , It will trigger DAC Work . thus , You can change the period of the sine wave by changing the timing time of the timer .

The above is my simple understanding , There should be a lot of inaccuracies , After all, he's a rookie , The above opinions are also convenient for self-study , I will also continue to learn to supplement nutrition . Here is an example for analysis :

1、 Initialization waveform table and output pin

/******** Sine wave output table ***********/
void SineWave_Data( u16 cycle ,u16 *D)
{
u16 i;
for( i=0;i<cycle;i++)
{
D[i]=(u16)((Um*sin(( 1.0*i/(cycle-1))*2*PI)+Um)*4095/3.3);
}
} /****************** Sine wave meter ***********************/
#ifdef Sine_WaveOutput_Enable
u16 SineWave_Value[256]; // Encapsulate... With functions
#endif /******DAC Register address declaration *******/
#define DAC_DHR12R1 (u32)&(DAC->DHR12R1) //DAC passageway 1 Output address
#define DAC_DHR12R2 (u32)&(DAC->DHR12R2) //DAC passageway 2 Output address /**************** Initialization pin ******************/
void SineWave_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // Turn on the clock
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push pull output mode
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Output rate
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ; // Select pins
GPIO_SetBits(GPIOA,GPIO_Pin_5) ; // Pull up the output
GPIO_Init(GPIOA, &GPIO_InitStructure); // initialization
}

2、 initialization DAC

/******************DAC initialization ¯*************************/
void SineWave_DAC_Config( void)
{
DAC_InitTypeDef DAC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);// open DAC The clock /**************DAC Structure initialization *******************/
DAC_StructInit(&DAC_InitStructure);
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;// No waveform
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; // Do not enable output caching
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;//DAC Trigger for timer 2 Trigger
DAC_Init(DAC_Channel_1, &DAC_InitStructure);// initialization
DAC_Cmd(DAC_Channel_1, ENABLE); // Can make DAC The passage of 1
DAC_DMACmd(DAC_Channel_1, ENABLE); // Can make DAC passageway 1 Of DMA
}

3、 Timer configuration

/********* Timer initialization ************/
void SineWave_TIM_Config(u32 Wave1_Fre)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);// Turn on the clock
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // No prescaler
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; // Regardless of the frequency
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;// Count up
TIM_TimeBaseStructure.TIM_Period = Wave1_Fre;// Set the output frequency
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);// Set up TIME The output trigger is in update mode
}

4、DMA To configure

/*********DMA To configure ***********/
void SineWave_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);// Turn on DMA2 The clock DMA_StructInit( &DMA_InitStructure); //DMA Structure initialization
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;// Read data from register
DMA_InitStructure.DMA_BufferSize = 256;// Register size
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;// The peripheral address is not incremented
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Memory address increment
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;// The width is half a word
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;// The width is half a word
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;/ The priority is very high
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;// Turn off memory to memory mode
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;// Circular transmission mode

DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1;// The peripheral address is DAC passageway 1 The address of
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SineWave_Value;// Waveform data table memory address

DMA_Init(DMA2_Channel3, &DMA_InitStructure);// initialization
DMA_Cmd(DMA2_Channel3, ENABLE); // Can make DMA passageway 3 

}

5、 Sine initialization

void SineWave_Init(u16 Wave1_Fre)
{
u16 f1=(u16)(72000000/sizeof(SineWave_Value)*2/Wave1_Fre);// Calculate the frequency
SineWave_Data( 256 ,SineWave_Value); // Generate waveform table of output sine wave
SineWave_GPIO_Config(); // initialization io
SineWave_TIM_Config(f1); // Initialize the timer
SineWave_DAC_Config(); // To configure DAC
SineWave_DMA_Config(); // To configure DMA
TIM_Cmd(TIM2, ENABLE); // Turn on timer
}

After the above simple configuration , It can make 32 Board output sin The waveform is .

STM32 Use DMA+DAC+TIMER Output sine wave more related articles

  1. STM32 The base DMA Of DAC Waveform generator

    DAC yes STM32 A basic peripheral of the series , You can convert digital signals into analog signals , This time I will use DAC To output a specific waveform . First, determine the working method , Because the simple oscillograph I'm doing now needs to display the input signal while outputting the waveform , So it can't take ...

  2. 【STM32】PWM DAC The basic principle ( experiment :PWM Realization DAC)

    although STM32F103ZET6 It has internal DAC, But there are only two DAC passageway , also STM32 There are many other models that don't have DAC Of . Usually , Use a dedicated D/A Chip , But that will increase the cost . however S ...

  3. STM32 And DMA+ADC

    Borrow the classic of little turtle : Dear netizens of the Internet . Good morning, noon and evening ..( Make a little advertisement , Because the video of little turtle is really good ). Every time I watch the video of little turtle, self-study is more relaxed and happy .. I was thinking , If the little turtle comes out STM32 In the video , I'll do an episode No ...

  4. STM32 Of GPIO Port output, open drain output and push-pull output

    This article is from cairang45 The blog of , Tells the story of STM32 Of GPIO Port output, open drain output and push-pull output , The author blog :http://blog.ednchina.com/cairang45 This article is from : University automation network (Ww ...

  5. STM32 And DMA

    One .DMA brief introduction 1.DMA brief introduction DMA(Direct Memory Access: Direct memory access ) It's a way to greatly reduce CPU Data transfer mode of workload . CPU There is transfer data . Calculation . Control program transfer and many other functions , But it turns out ...

  6. STM32:TIMER Output comparison mode -PWM

    Transplant on your own little board PWM It's time to learn again , Add two points :1, Learning various output comparison patterns :2, Add interrupt when output mode Write the function first : //TIM4 PWM Partial initialization //PWM Output initialization //period: Output ...

  7. STM32 Of DMA

    What is? DMA? Its full name is :Direct Memory Access: according to ST Information provided by the company ,DMA yes STM32 An independent and Cortex-M3 Modules in the kernel , It's a bit like ADC.PWM.TIMER Equal module : Lord ...

  8. 【iCore1S Dual core plate _ARM】 Routine nine :DAC experiment —— Output DC voltage

    Experimental principle : STM32 Internal integration 12 position DAC, It can be configured as 12 Bit or 8 position ,DAC It has two independent conversion channels , In double DAC In mode ,DA The transformation can be configured in stand-alone mode or working mode ,iCore1S in DAC The reference voltage is 2.5V. Ben ...

  9. STM32 UART DMA Receiving unknown data length

    Serial communication is a common function , stay STM32 in UART have DMA function , And it can be used to send and receive DMA, Use DMA Basically, you won't encounter any problems , Because I'll tell you when I send it DMA Length of data sent ,DMA According to the length of the transmission directly ...

Random recommendation

  1. Front end modular tools -webpack

    Explain front end modular tools -webpack webpack It's a module bundler, Put aside the broad and profound problem of Chinese characters , Let's call him ' Module management tool '. With js More and more things can be done , browser . The server ,js There seems to be everywhere ...

  2. “HTTPS” Where is safety ?

    background Recently, based on the study of interest HTTPS Relevant knowledge , Record the learning experience here . In the process of getting information online , The most information encryption transmission mode we contact is HTTPS 了 . Every time you visit a site , A green image appears in the address bar of the browser ...

  3. Condition The advantages of

    Then introduce the protagonist of this article ,Condition,Condition take Object Monitor method (wait.notify and notifyAll) Break down into distinct objects , So that by associating these objects with any Lock Realization ...

  4. Activity Life cycle learning and Logcat Use

    http://android.blog.51cto.com/268543/322518/  Activities By Activity stack Managed . When a new Activity Be activated , It will be in st ...

  5. Python Data analysis process

    One . The steps of data analysis : 1. Look at the data and ask questions 2. Data cleaning 3. Code writing , Extract the result data , And analyze whether there is abnormal data , Modify the code 4. Choose the right chart to display according to the data 5. According to the chart, group discussion and communication can get the final result Two ...

  6. Linux Process practice (4) --wait Avoid zombie process

    Wait The background of When the subprocess exits , The kernel sends... To the parent process SIGCHLD The signal , The exit of a child process is an asynchronous event ( The child process can terminate at any time when the parent process is running ) When a subprocess exits , The kernel puts child processes in zombie state , This process is called a zombie process ...

  7. Start at one and separate the front and back ends [ vue + .netcore Make up ] Thirty-one ║ Nuxt Final part : be based on Vuex Permission verification exploration

    origin Hello, everyone , It's Thursday , The landlord will have a formal holiday tomorrow , Here I wish you a happy holiday , I hope I can continue to study something at home , What about today nuxt The last one of , It is mainly about the research of permission login , This is when we talked about the first project ...

  8. CountDownLatch/CyclicBarrie Usage record

    stay jdk1.5 in ,java Provides a lot of tool classes to help us with concurrent programming , Among them CountDownLatch and CyclicBarrie 1.CountDownLatch Usage of CountDownLatch position ...

  9. redis-sentinel Master slave replication is highly available

    Redis-Sentinel Redis-Sentinel yes redis Officially recommended high availability solutions , When used redis do master-slave High availability of , If master Self downtime ,redis Itself or the client ...

  10. CH5701 Travel by car

    The question 5701 Travel by car 0x50「 Dynamic programming 」 Example describe Small A And small B Decided to take a vacation to travel , They will want to go to the city from 1 To N Number , And the cities with smaller numbers are to the west of the cities with larger numbers , It is known that the altitude of each city is different , On the city ...