Skip to main content
nechi
Associate II
August 25, 2015
Question

input capture _ DMA request

  • August 25, 2015
  • 5 replies
  • 987 views
Posted on August 25, 2015 at 15:59

Hi,

Please i have to capture an input signal  and read it's frequency value with a DMA request but i can't find any ressources.

I know the other solution with interreupt but i insist on this method with DMA, i need it.

i did the configuration required but the buffer of destination shows always value=0 !

here is my code:

uint32_t TIM1CapturedValue_u32[2];

void CaptureDMA(void)

{

  DMA_DeInit(DMA1_Channel2);                                            //    Time1_ch1<-->DMA1_ch2          

  

  DMA_InitStructure.DMA_PeripheralBaseAddr = TIM_DMABase_CCR1;          //    Time1-->CCR1        

  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)TIM1CapturedValue_u32[0];

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

  DMA_InitStructure.DMA_BufferSize =2;

  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_High;

  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

  

  DMA_Init(DMA1_Channel2, &DMA_InitStructure);

  

  //Enable DMA1 channel2 

  DMA_Cmd(DMA1_Channel2, ENABLE);  

  

  

   TIM_TimeBaseStructure.TIM_Prescaler = 0; // Counter Clk = 72M

   TIM_TimeBaseStructure.TIM_Period = 0XFFFF;

   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

    

   TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

   TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

   TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; 

   TIM_ICInitStructure.TIM_ICFilter = 0x00;

   TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; 

   TIM_ICInit(TIM1, &TIM_ICInitStructure); 

    

   /* Enable the TIMER CAPTURE DMA requests */

TIM_SelectCCDMA(TIM1, ENABLE);

TIM_DMACmd(TIM1, TIM_DMA_CC1, ENABLE);   

    

    // TIM1 enable counter 

    TIM_Cmd(TIM1,ENABLE); 

}
    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    August 25, 2015
    Posted on August 25, 2015 at 16:33

    You're using what processor?

    u32 is NOT a HalfWord

    You want the Address of the Array, not the content

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    nechi
    nechiAuthor
    Associate II
    August 25, 2015
    Posted on August 25, 2015 at 20:07

    Hi Clive,

    i'm using Timer 16 bits. Here is what i have understood: when the capture occurs, the DMA will be requested to transfer the value of the CCR1 and store it into the buffer so i need the content of the buffer i think . I can't find where is the mistake or if there is code missing  

    nechi
    nechiAuthor
    Associate II
    August 25, 2015
    Posted on August 25, 2015 at 20:08

    ok i'll change it to u16. i'm using STM32F103

    Tesla DeLorean
    Guru
    August 25, 2015
    Posted on August 25, 2015 at 20:24

    // Loading the DMA Address with random content, perhaps zero.

    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)TIM1CapturedValue_u32[0];

    // Loading the DMA Address with the address of the first array element

    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&TIM1CapturedValue_u16[0];

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    nechi
    nechiAuthor
    Associate II
    August 27, 2015
    Posted on August 27, 2015 at 14:49

    Thank you very much Clive 1 it works now.