打印

STM32 TIM8不能触发DAC1

[复制链接]
5144|16
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
selina1983|  楼主 | 2011-1-19 23:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
为什么我用的STMF103ZE的TIM8不能触发DAC1,输出正弦波,但是我程序修改为TIM6就可以触发输出正弦波。香斑竹帮我看看
    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
    TIM_TimeBaseStructure.TIM_Period = 0x19;         
    TIM_TimeBaseStructure.TIM_Prescaler = 0x0;      
    TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
    TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

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

    /* DAC channel1 Configuration */
        DAC_StructInit(&DAC_InitStructure);
    DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_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<32; Idx++)
    {
      DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
    }

    /* DMA2 channel3 configuration */
    DMA_DeInit(DMA2_Channel3);
    DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DualSine12bit;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
    DMA_InitStructure.DMA_BufferSize = 32;
    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_Channel3, &DMA_InitStructure);

    /* Enable DMA2 Channel3 */
    DMA_Cmd(DMA2_Channel3, 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 Channel1 */
    DAC_DMACmd(DAC_Channel_1, ENABLE);

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

        while (1)
    {

    }
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
这个是TIM6  可以触发DAC1输出正弦波,示波器看到 PA0.4

   TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
    TIM_TimeBaseStructure.TIM_Period = 0x19;         
    TIM_TimeBaseStructure.TIM_Prescaler = 0x0;      
    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_StructInit(&DAC_InitStructure);
    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<32; Idx++)
    {
      DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
    }

    /* DMA2 channel3 configuration */
    DMA_DeInit(DMA2_Channel3);
    DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DualSine12bit;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
    DMA_InitStructure.DMA_BufferSize = 32;
    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_Channel3, &DMA_InitStructure);

    /* Enable DMA2 Channel3 */
    DMA_Cmd(DMA2_Channel3, 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 Channel1 */
    DAC_DMACmd(DAC_Channel_1, ENABLE);

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

        while (1)
    {

    }
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM8, ENABLE);
为什么我改成TIM8触发就不行了  PA0.4一点反映也没有
沙发
selina1983|  楼主 | 2011-1-19 23:08 | 只看该作者
谁帮我看看什么原因啊

使用特权

评论回复
板凳
selina1983|  楼主 | 2011-1-19 23:08 | 只看该作者
板凳了。。。。。。。。。。。。。

使用特权

评论回复
地板
selina1983|  楼主 | 2011-1-20 11:33 | 只看该作者
香斑竹呢  帮我看看啊

使用特权

评论回复
5
香水城| | 2011-1-20 11:39 | 只看该作者
为什么你要在初始化完TIM,才打开它的时钟,这样怎么能正确地配置定时器?

使用特权

评论回复
6
selina1983|  楼主 | 2011-1-20 14:56 | 只看该作者
不是啊  我是初始完 才打开的  代码没有全部上传

使用特权

评论回复
7
selina1983|  楼主 | 2011-1-20 15:03 | 只看该作者
香斑竹看看呢,我上传了完整代码

使用特权

评论回复
8
香水城| | 2011-1-20 15:38 | 只看该作者
不是啊  我是初始完 才打开的  代码没有全部上传
selina1983 发表于 2011-1-20 14:56


错了,你需要先打开定时器的时钟,再对定时器初始化。

使用特权

评论回复
9
selina1983|  楼主 | 2011-1-20 18:00 | 只看该作者
我当然先是RCC吗  然后初始化的啊

使用特权

评论回复
10
selina1983|  楼主 | 2011-1-20 18:06 | 只看该作者
是不是STMF103ZE的没有TIM8触发

1.jpg (66.29 KB )

1.jpg

使用特权

评论回复
11
selina1983|  楼主 | 2011-1-20 18:07 | 只看该作者
还是没有想明白

使用特权

评论回复
12
selina1983|  楼主 | 2011-1-20 18:09 | 只看该作者
是不是TIM8触发DMA2的4通道,不能触发DMA2的3通道啊   我看看固件库3.3是这样的

使用特权

评论回复
13
香水城| | 2011-1-20 18:18 | 只看该作者
为什么要把这句话放在最后?
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM8, ENABLE);

使用特权

评论回复
14
selina1983|  楼主 | 2011-1-20 18:24 | 只看该作者
int main(void)
{
#ifdef DEBUG
    debug();
#endif
   
    /* System clocks configuration ---------------------------------------------*/
    RCC_Configuration();
   
    /* NVIC configuration ------------------------------------------------------*/
    NVIC_Configuration();
   
    /* GPIO configuration ------------------------------------------------------*/
    GPIO_Configuration();
   
    /* Configure the USART1 */
//    USART_Configuration1();
   
//    printf("\r\n USART1 print AD_value -------------------------- \r\n");



    /* TIM8 Configuration */
    /* Time base configuration */
//        TIM_DeInit(TIM6);
    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
    TIM_TimeBaseStructure.TIM_Period = 0x19;         
    TIM_TimeBaseStructure.TIM_Prescaler = 0x0;      
    TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
    TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

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

    /* DAC channel1 Configuration */
        DAC_StructInit(&DAC_InitStructure);
    DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_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<32; Idx++)
    {
      DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
    }

    /* DMA2 channel3 configuration */
    DMA_DeInit(DMA2_Channel3);
    DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DualSine12bit;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
    DMA_InitStructure.DMA_BufferSize = 32;
    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_Channel3, &DMA_InitStructure);

    /* Enable DMA2 Channel3 */
    DMA_Cmd(DMA2_Channel3, 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 Channel1 */
    DAC_DMACmd(DAC_Channel_1, ENABLE);

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

        while (1)
    {

    }

   
    /* DMA channel1 configuration ----------------------------------------------/
    DMA_DeInit(DMA1_Channel1);
    DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;      // 外设地址
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; // 内存地址
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;               // DMA 传输方向单向
    DMA_InitStructure.DMA_BufferSize = 1;                            // 设置DMA在传输时缓冲区的长度 word
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // 设置DMA的外设递增模式,一个外设
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;         // 设置DMA的内存递增模式
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;  // 外设数据字长
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;          // 内存数据字长
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;     // 设置DMA的传输模式:连续不断的循环模式
    DMA_InitStructure.DMA_Priority = DMA_Priority_High; // 设置DMA的优先级别
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;        // 设置DMA的2个memory中的变量互相访问
    DMA_Init(DMA1_Channel1, &DMA_InitStructure);
   
    / Enable DMA channel1 /
    DMA_Cmd(DMA1_Channel1, ENABLE);
     
    / ADC1 configuration ------------------------------------------------------/
    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;   // 独立工作模式
    ADC_InitStructure.ADC_ScanConvMode = ENABLE;         // 扫描方式
    ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;   // 连续转换
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; // 外部触发禁止
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;              // 数据右对齐
    ADC_InitStructure.ADC_NbrOfChannel = 1;              // 用于转换的通道数
    ADC_Init(ADC1, &ADC_InitStructure);
   
    / ADC1 regular channel14 configuration /
    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_55Cycles5);
   
    / Enable ADC1 DMA /
    ADC_DMACmd(ADC1, ENABLE);
   
    / Enable ADC1 /
    ADC_Cmd(ADC1, ENABLE);
   
    / Enable ADC1 reset calibaration register /   
    ADC_ResetCalibration(ADC1);
    / Check the end of ADC1 reset calibration register /
    while(ADC_GetResetCalibrationStatus(ADC1));
   
    / Start ADC1 calibaration /
    ADC_StartCalibration(ADC1);
    / Check the end of ADC1 calibration /
    while(ADC_GetCalibrationStatus(ADC1));
     
    / Start ADC1 Software Conversion /
    ADC_SoftwareStartConvCmd(ADC1, ENABLE);
   
    while(1)
    {
        AD_value = ADC_GetConversionValue(ADC1);
        if (ticks++ >= 900000) {                  / Set Clock1s to 1 every 1 second    /
            ticks   = 0;
            Clock1s = 1;
        }
   
        / Printf message with AD value to serial port every 1 second             /
        if (Clock1s) {
            Clock1s = 0;
            printf("The current AD value = 0x%04X \r\n", AD_value);
        }
   
    }           */
}

main()函数中RCC配置好了

void RCC_Configuration(void)
{
  /* RCC system reset(for debug 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_SetLatency(FLASH_Latency_2);

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
  
    /* PCLK2 = HCLK */
    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_9);

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* 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 DMA clock */
//  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  /* Enable ADC1 and GPIOC clock */
//  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOA, ENABLE);

  /* Enable USART1 and GPIOA clock */
//  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);

  /* Enable peripheral clocks --------------------------------------------------*/
  /* DMA clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, 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);
  /* TIM6 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
}


程序是这样的   上面只是我这样写的

使用特权

评论回复
15
selina1983|  楼主 | 2011-1-20 18:25 | 只看该作者
但是把TIM6改成TIM8就是不行

使用特权

评论回复
16
香水城| | 2011-1-20 18:48 | 只看该作者
先说说你的编程思路,DAC、DMA、TIM等之间是什么关系?

使用特权

评论回复
17
selina1983|  楼主 | 2011-1-24 09:18 | 只看该作者
TIM触发DAC,然后DAC自动进行DMA中断处理吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

19

主题

168

帖子

1

粉丝