stm32的DAC输出正弦波.doc

上传人:scccc 文档编号:14712193 上传时间:2022-02-16 格式:DOC 页数:11 大小:16.59KB
返回 下载 相关 举报
stm32的DAC输出正弦波.doc_第1页
第1页 / 共11页
stm32的DAC输出正弦波.doc_第2页
第2页 / 共11页
stm32的DAC输出正弦波.doc_第3页
第3页 / 共11页
stm32的DAC输出正弦波.doc_第4页
第4页 / 共11页
stm32的DAC输出正弦波.doc_第5页
第5页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《stm32的DAC输出正弦波.doc》由会员分享,可在线阅读,更多相关《stm32的DAC输出正弦波.doc(11页珍藏版)》请在三一文库上搜索。

1、 1 / 11 自己用的片子是stm32的100,用的DAC通道是: DAC_Channel_1 DMA通道是: DMA1_Channel3 定时器用的是: TIM6 注: 直接用例程没有出现预期的波形,主要是应为我用的片子为100,所对应的dac,dma,以及tim与103的对应有所不同,如:100的dac通道1,与dma1的通道3及tim6是捆在一块的。大家具体调试过程中,要按照自己的芯片型号的参考手册把这几块给对应起来即可。 /* Includes -*/ #include stm32f10x_lib.h /* Private typedef -*/ /* Private define

2、-*/ #define DAC1_DHR8R1_Address 0x /* Init Structure definition */ DAC_InitTypeDef DAC_InitStructure; DMA_InitTypeDef DMA_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* Private macro -*/ /* Private variables -*/ 2 / 11 ErrorStatus HSEStartUpStatus; uc16 Sine12bit32 = 2047, 2447, 28

3、31, 3185, 3498, 3750, 39, 4056, 4095, 4056, 39, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647; u32 DualSine12bit32; u8 Idx = 0; /* Private function protypes -*/ void RCC_Configuration(void); void GPIO_Configuration(void); void NVIC_Conf

4、iguration(void); void Delay(vu32 nCount); /* Private functions -*/ /* * Function Name : main * Description : Main program. * Input : None * Output : None 3 / 11 * Return : None */ int main(void)#ifdef DEBUG debug(); #endif /* System Clocks Configuration */ RCC_Configuration(); /* GPIO configuration

5、*/ GPIO_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* TIM8 Configuration */ /* Time base configuration */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0x19; TIM_TimeBaseStructure.TIM_Prescaler = 0x00; TIM_TimeBaseStructure.TIM_ClockDivision

6、= TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); /* TIM8 TRGO selection */ 4 / 11 TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; DAC

7、_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* DAC channel2 Configuration DAC_Init(DAC_Channel_2, &DAC_InitStructure); */ /* Fill Sine32bit table */ for (Idx= 0; Idx32; Idx+)D

8、ualSine12bitIdx = (Sine12bitIdx 16) + (Sine12bitIdx);/* DMA2 channel4 configuration */ DMA_DeInit(DMA1_Channel3); /将dma的通道寄存器设为默认值 DMA_InitStructure.DMA_PeripheralBaseAddr = DAC1_DHR8R1_Address; /定义dma外设基地址 DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DualSine12bit; DMA_InitStructure.DMA_DIR = DMA_D

9、IR_PeripheralDST; /外设作为数据传输的目的地DMA_InitStructure.DMA_BufferSize = 32; /dma缓存大小 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; /外设地址寄存器不变DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;/内存地址寄存器递增DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; /外设数据宽度 D

10、MA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;/工作在循环缓存模式,数据传输数目为0时,自动恢复配置初值 5 / 11 DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;/通道未被设置成内存到内存模式,与循环模式相对 DMA_Init(DMA1_Channel3, &DMA_Init

11、Structure);/将DMA_InitStructure中指定的参数初始化dma的通道寄存器 /* Enable DMA2 Channel4 */ DMA_Cmd(DMA1_Channel3, ENABLE); /使能通道 /* Enable DAC Channel1 */ DAC_Cmd(DAC_Channel_1, ENABLE); /* Enable DAC Channel2 */ DAC_Cmd(DAC_Channel_1, ENABLE); /* Enable DMA for DAC Channel2 */ DAC_DMACmd(DAC_Channel_1, ENABLE); /

12、* TIM8 enable counter */ TIM_Cmd(TIM6, ENABLE); while (1)GPIO_ResetBits(GPIOA , GPIO_Pin_10); /* * Function Name : RCC_Configuration * Description : 6 / 11 Configures the different system clocks. * Input : None * Output : None * Return : None */ void RCC_Configuration(void)/* RCC system reset(for de

13、bug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus = SUCCESS)/* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state */ FLASH_SetLatenc

14、y(FLASH_Latency_2); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ 7 / 11 RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_3); /* Enable PLL */ RCC_PLLCmd(EN

15、ABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) = RESET) /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08)/* Enable peripheral clocks -*/ /* DMA clock

16、 enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); /* AFIO and GPIOA Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);/* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* TIM8 Periph clock enable */ 8 / 11 RC

17、C_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);/* * Function Name : GPIO_Configuration * Description : Configures the different GPIO ports. * Input : None * Output : None * Return : None */ void GPIO_Configuration(void)GPIO_InitTypeDef GPIO_InitStructure; /* Configure DAC channe1 and DAC channel2

18、 outputs pins */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5|GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure);/* 9 / 11 * Function Name : NVIC_Configuration * Description : Configures Vecto

19、r Table base location. * Input : None * Output : None * Return : None */ void NVIC_Configuration(void)#ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000 */ NVI

20、C_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif/* * Function Name : Delay 10 / 11 * Description : Inserts a delay time. * Input : nCount: specifies the delay time length. * Output : None * Return : None */ void Delay(vu32 nCount)for(; nCount != 0; nCount-);#ifdef DEBUG /* * Function Name : assert_

21、failed * Description : Reports the name of the source file and the source line number * where the assert_param error has occurred. * Input : - file: pointer to the source file name 11 / 11 * - line: assert_param error line source number * Output : None * Return : None */ void assert_failed(u8* file, u32 line)/* User can add his own implementation to report the file name and line number, ex: printf(Wrong parameters value: file %s on line %drn, file, line) */ /* Infinite loop */ while (1)#endif

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1