关于输出正弦波的问题

maxipeiz   2009-7-29 18:17 楼主
以下是我的一个输出正弦波的函数,输出了一个100hz的正弦波
我的项目需要输出一个幅值由0.5V逐渐增长的正弦信号。
各位有什么好的建议请多多指教。
另外,要求幅值的变化是每隔十个周期一次,并且要在2048点进行变化。
void TopFrequency_Measure(void)
{
  u32 DualSine12bit[120];
  u32 Idx = 0;
  //120个数的正弦表
  u16 DAC2_Value[] = {2048,2155,2262,2368,2474,2578,2681,2782,2881,2977,3072,
                       3163,3251,3336,3418,3495,3569,3639,3704,3765,3821,3872,
                       3918,3959,3995,4025,4050,4070,4084,4092,4095,4092,4084,
                       4070,4050,4025,3995,3959,3918,3872,3821,3765,3704,3639,
                       3569,3495,3418,3336,3251,3163,3071,2977,2881,2782,2681,
                       2578,2474,2368,2262,2155,2047,1940,1833,1727,1621,1517,
                       1414,1313,1214,1118,1023,932,844,759,677,600,526,456,
                       391,330,274,223,177,136,100,70,45,25,11,3,0,3,11,25,45,
                       70,100,136,177,223,274,330,391,456,526,600,677,759,844,
                       932,1024,1118,1214,1313,1414,1517,1621,1727,1833,1940};


  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); //100hz精确的时钟
  TIM_TimeBaseStructure.TIM_Period = 6000;         
  TIM_TimeBaseStructure.TIM_Prescaler = 0;      
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);

  /* TIM8 TRGO selection */
  TIM_SelectOutputTrigger(TIM8, TIM_TRGOSource_Update);

  /* DAC channel1 Configuration */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T8_TRGO;
  DAC_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; Idx<120; Idx++)
  {
    DualSine12bit[Idx] = (DAC2_Value[Idx] << 16) + (DAC2_Value[Idx]);
  }

  /* DMA2 channel4 configuration */
  DMA_DeInit(DMA2_Channel4);
  DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DualSine12bit;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  DMA_InitStructure.DMA_BufferSize =120;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA2_Channel4, &DMA_InitStructure);

  /* Enable DMA2 Channel4 */
  DMA_Cmd(DMA2_Channel4, ENABLE);

  /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
     automatically connected to the DAC converter. */
  DAC_Cmd(DAC_Channel_1, ENABLE);
  /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
     automatically connected to the DAC converter. */
  DAC_Cmd(DAC_Channel_2, ENABLE);

  /* Enable DMA for DAC Channel2 */
  DAC_DMACmd(DAC_Channel_2, ENABLE);

  /* TIM8 enable counter */
  TIM_Cmd(TIM8, ENABLE);

  while (1)
  {
  }
}

回复评论 (1)

1。正弦表定义十六进制数,方便调试。
2。最后的无限循环,最好加看门狗。
点赞  2009-7-29 18:34
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复