这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » tsy040501 ARM DIY进程贴(LCD刷屏和显示字母代码)

共79条 4/8 |‹ 2 3 4 5 6 7 ›| 跳转至
助工
2012-05-10 18:46:06     打赏
31楼
利用DAC输出正弦波和三角波,各种百度(话说:从实验室抬了台数字示波器回来,没想到这家伙很沉,累死我了)

三角波图片!



正弦波图片

助工
2012-05-10 19:40:43     打赏
32楼

正弦波关键代码:(DAC用的是单通道)

TIM_InitStruct.TIM_Period = 0x19;
 TIM_InitStruct.TIM_Prescaler = 0x0;
 TIM_InitStruct.TIM_ClockDivision = 0x0;
 TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;

 TIM_TimeBaseInit(TIM2 , &TIM_InitStruct);
 /*TIM_PrescalerConfig(TIM6, 0xF, TIM_PSCReloadMode_Update);
   TIM_SetAutoreload(TIM6, 0xFF);
    TIM6 TRGO selection */
   //TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);

 TIM_SelectOutputTrigger(TIM2 , TIM_TRGOSource_Update);

 /* DAC 构造 */
 DAC_InitStruct.DAC_Trigger = DAC_Trigger_T2_TRGO;
 DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_None;
 DAC_InitStruct.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047;
 DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Disable;

 DAC_Init(DAC_Channel_1 , &DAC_InitStruct);

 for(Idx=0;Idx<256;Idx++)
 {
  SigSine12bit[Idx] = (0xffff0000 << 16) + (Sine12bit[Idx]);
 }/**/

 /* DMA 构造 */
 DMA_InitStruct.DMA_PeripheralBaseAddr = 0x40007408;
 DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)&SigSine12bit;
 DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralDST;
 DMA_InitStruct.DMA_BufferSize = 256;
 DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
 DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
 DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
 DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
 DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
 DMA_InitStruct.DMA_Priority = DMA_Priority_High;
 DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;

 DMA_Init(DMA2_Channel3 , &DMA_InitStruct);//要用DMA2

 DMA_Cmd(DMA2_Channel3 , ENABLE);//使能DMA2

 DAC_Cmd(DAC_Channel_1 , ENABLE);//使能DAC通道1
 DAC_DMACmd(DAC_Channel_1 , ENABLE);

 TIM_Cmd(TIM2 , ENABLE);


高工
2012-05-10 21:07:12     打赏
33楼

助工
2012-05-12 12:13:07     打赏
34楼

 三角波关键代码:

 TIM_InitStruct.TIM_Period = 0x19;
 TIM_InitStruct.TIM_Prescaler = 0x0;
 TIM_InitStruct.TIM_ClockDivision = 0x0;
 TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM2 , &TIM_InitStruct);

 TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);

/* Set GPIO_DAC */
 GPIOA_InitStruct.GPIO_Pin = GPIO_Pin_4;
 GPIOA_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
 GPIOA_InitStruct.GPIO_Mode = GPIO_Mode_AIN;

 GPIO_Init(DAC_GPIOA , &GPIOA_InitStruct);

/* Set DAC */
 //DAC_Cmd(DAC_Channel_1,ENABLE);

 DAC_InitStruct.DAC_Trigger = DAC_Trigger_T2_TRGO;
 DAC_InitStruct.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047;
 DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
 DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_Triangle;//三角波触发方式

 DAC_Init(DAC_Channel_1 , &DAC_InitStruct);

 DAC_Cmd(DAC_Channel_1, ENABLE);//使能DAC通道1

 DAC_SetChannel1Data(DAC_Align_12b_R , 0x000);

 TIM_Cmd(TIM2 , ENABLE);


助工
2012-05-12 12:24:20     打赏
35楼

谢谢你的鼓励~


院士
2012-05-12 22:28:13     打赏
36楼
收下了。
回头我亲自验证一下……

高工
2012-05-13 00:07:59     打赏
37楼
出差,示波器带不过来。想玩玩dac也没的玩了。。。

助工
2012-05-13 13:41:44     打赏
38楼
学校的数字示波器~很沉啊~您老抗去出差,那有多辛苦啊!

助工
2012-05-15 09:54:00     打赏
39楼

TIM定时器的定时时间计算:
摘自百度文库(可能有点模糊,海涵啦~)


助工
2012-05-15 16:54:33     打赏
40楼

定时器定时和中断先附上代码(没有相机,要找别人借,这得天天麻烦别人囧)
/* 结构体 */
 TIM_TimeBaseInitTypeDef TIM_BaseInitStruct;
 NVIC_InitTypeDef NVIC_InitStruct;
 //TIM_OCInitTypeDef TIM_OCInitStruct;

 /* 构造基本定时单元TIM2 */
 TIM_BaseInitStruct.TIM_Prescaler = 9999;
 TIM_BaseInitStruct.TIM_Period = 7199;
 TIM_BaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_BaseInitStruct.TIM_ClockDivision = 0x0;
 TIM_TimeBaseInit(TIM2 , &TIM_BaseInitStruct);

 /*TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_Timing;
 TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStruct.TIM_OutputNState = TIM_OutputNState_Enable;
 TIM_OCInitStruct.TIM_Pulse = 0x0;
 TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
 TIM_OCInitStruct.TIM_OCNPolarity = TIM_OCNPolarity_High;
 TIM_OCInitStruct.TIM_OCIdleState = TIM_OCIdleState_Set;
 TIM_OCInitStruct.TIM_OCNIdleState = TIM_OCIdleState_Reset;
 TIM_OC1Init(TIM2 , &TIM_OCInitStruct);*/

 /* 构造嵌套向量中断控制 */
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
 NVIC_InitStruct.NVIC_IRQChannel = TIM2_IRQn;
 NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStruct.NVIC_IRQChannelSubPriority = 4;
 NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStruct);

 /* 开启时钟中断 */
 TIM_ITConfig(TIM2 , TIM_IT_Update , ENABLE);
 
 /* 使能定时器2 */
 TIM_Cmd(TIM2 , ENABLE);

自己手上的固件库使用手册不是最新版的,而固件库是最新版的,不搭!结果悲剧,NVIC让我搞半天,NVIC头文件是misc.h旧版的却是stm32f10x_nvic.h!


共79条 4/8 |‹ 2 3 4 5 6 7 ›| 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]