本帖最后由 yangwc 于 2017-5-10 11:56 编辑
STM32L152的DAC_Channel1采用DMA传输方式生成正弦信号,DAC触发源为TIM6,生成的正弦信号幅度与预期一致,频率比计算的频率略低(估计原因为AHB总线带宽受限所致,DMA传输时最多只能占用一半的AHB带宽)。问题在于此时若将PA0(ADC_IN0)配置为Analog Mode, DAC生成的正弦信号频率变得非常低(比如正常时,正弦信号频率为10KHz,PA0(ADC_IN0)配置为Analog Mode后,DAC输出正弦信号的频率只有120Hz,幅度不变;若正常时,正弦信号频率为2.5KHz,PA0(ADC_IN0)配置为Analog Mode后,DAC几乎没有信号输出)。
void DAC_Port_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure PA4 (DAC1_OUT1) in analog mode --*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void DAC_Config(void)
{
DAC_InitTypeDef DAC_InitStruct;
/* DAC1 channel1 Configuration */
DAC_InitStruct.DAC_Trigger = DAC_Trigger_T6_TRGO;
DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStruct.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStruct);
/* Enable DAC1 Channel1 */
DAC_Cmd(DAC_Channel_1, ENABLE);
DAC_DMACmd(DAC_Channel_1,ENABLE);
}
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_StructInit(&DMA_InitStructure);
/* Config the DMA1 channel 2 */
DMA_DeInit(DMA1_Channel2);
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&sin_amp;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 100;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
/* Enable DMA1 Channel2 */
DMA_Cmd(DMA1_Channel2, ENABLE);
}
void TIM6_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_DeInit(TIM6);
TIM_TimeBaseStructure.TIM_Period = 0x09; // 12M/0x09 :1300KHz
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM6,ENABLE);
TIM6->SR = 0;
TIM_Cmd(TIM6, ENABLE);
TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
}
按照上面的配置,可以正常生成正弦信号。若将PA0配置为Analog mode:
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure PA0 (ADC1_IN0) in analog mode --*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
就不能正常生成正弦信号。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
你这是经验之谈啊,谢谢。
请问,这颗片子,在低功耗模式下,能够接收250K的脉冲捕获吗?能发送出去1M的脉冲吗?
低功耗模式有好几种模式:
1. 低功耗运行模式:时钟不受影响。可以满足要求。
2. 睡眠模式/低功耗睡眠模式:外设时钟关闭。不能满足要求。
3. 停止模式/待机模式:HSI/MSI/HSE都关闭了。不能满足要求。
一周热门 更多>