INPUT CAPTURE using DMA || Measure High Frequencies and Low Width

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024
  • Purchase the Products shown in this video from :: controllerstec...
    ________________________________________________________________________________________
    Get the code from github.com/con...
    Check out more STM32 TIMERS Videos • STM32 TIMERS
    ________________________________________________________________________________________
    ****** SUPPORT US BY DONATING*****
    paypal.me/cont...
    ******Join the Membership******
    / @controllerstech
    Join the Discord Server / discord
    Join the Telegram Group t.me/controlle...
    Follow me on Instagram / controllerstech
    For more info, visit www.controller...

ความคิดเห็น • 49

  • @dmitrymarukh6857
    @dmitrymarukh6857 ปีที่แล้ว +5

    WOW! What a great example of not understanding what DMA is for! All you have to do is configure the timer in slave reset mode and two DMA channels with circular buffers. Two lines of code to start DMA and one line to take two captured values from the buffers and divide one by another. Only 3 lines of code, no IRQ and no scanning arrays to find somewhat useful data.

    • @sungjinkim7730
      @sungjinkim7730 ปีที่แล้ว +1

      THANK YOU;;;;;;;;;;;;;;;;;;;

    • @Gruftgrabbler
      @Gruftgrabbler 5 หลายเดือนก่อน

      Hello can you please explain your suggestions in a more clear way? I have trouble to understand it.

    • @dmitrymarukh6857
      @dmitrymarukh6857 5 หลายเดือนก่อน +5

      @@Gruftgrabbler I'll give you an example for STM32G051, but most STM32 timers can be configured this way. First, open Cube and go to Timers configuration. Select TIM1 and choose Slave Mode = Reset Mode and Trigger Source = TI1FP1, this will reset timer by signal on TIM1_CH1 pin. Select "Channel 1" = Input Capture direct mode, this will use TI1 as capture signal for CC1 channel. Select "Channel 2" = Input Capture indirect mode, this will also use TI1 for CC2 channel. Now, in configuration for Channel 1 select polarity = rising edge, for channel 2 = falling edge. In DMA settings add two DMA channels for TIM1_CH1 and TIM1_CH2. Configure both DMA in Circular mode with Data Width = Half Word.
      The way it works, is that rising edge of PWM signal on TIM1_CH1 pin captures PWM period in CC1 and resets timer to 0. The falling edge of the same signal captures pulse length in CC2. The DMA then transfers captured values into two memory locations. Since DMA is configured in circular mode next capture will override previous values in the same locations.
      To start he process you use HAL_TIM_IC_Start_DMA with an address of first memory location, e.g. uint16_t period, and again with address of second location, e.g. uint16_t duration. Whenever your program needs data, you simply do duty = (100*duration)/period.
      Note, that you need to deal with zero values when there are no pulses. Also some MCUs support dedicated PWM capture mode, that does all of this automatically for you, but it can be tricky to make work, so I prefer the above method.

    •  5 หลายเดือนก่อน

      @@dmitrymarukh6857 I can't thank you enough for this information. I am just starting my journey with STM32 and this is a hidden gem! Tried and worked. I used duty = (100*(duration+1))/(period+1), as I was thinking the counter started from 0. I wonder if this is correct or not...

    • @Gruftgrabbler
      @Gruftgrabbler 4 หลายเดือนก่อน

      ​@@dmitrymarukh6857 Ah I understand. Thank you very much for the accurate explanation. This will be a very good reference for future ones.
      In my own project I am measuring the duty cycle of a 1Mhz signal using the "PWM Input" Mode of a Timer. (Using a STM32G4 series) It is a very elegant solution but also has the downside of consuming a lot of cpu time. According to my understanding it basically does the exact same thing as you described.
      However I think the advantage of doing it manually is that you can increase the DMA buffer size and avoid triggering the ISR so often. Saving the captured CCRs in a buffer and later doing some stuff with it when the buffer is full.
      Is that something you would agree?
      In my application I am using a workaround where I disable the corresponding global Timer interrupt after a rising edge occurs and I am enabling that in a second timer which runs on ~1/10 of the pam frequency and which is also doing the actual math. Yeah this is throwing away a lot of possible readings but right now I am currently satisfied with this workaround, I might upgrade that later on.

  • @ricolauersdorf687
    @ricolauersdorf687 ปีที่แล้ว +3

    Hello Sir! Your videos are my source for fastest learning STM32. And i really thank you very much! Could you maybe please show, how to dma read parallel gpio information triggered by io? I think, it should be possible to arrange a input capture triggered dma and then read from gpio register, instead of timer capture register, as i have seen something similar. It would be great sir!

  • @공돌이-h9v
    @공돌이-h9v 7 หลายเดือนก่อน

    Hi, friend! Thanks for your valuable video. Did you upload a video about another way to measure fast frequencies that you mentioned at the end of the video? Please share the link.

  • @Karroo74
    @Karroo74 3 ปีที่แล้ว +2

    All what you do is very useful. Thank you!

  • @winnersolutions1982
    @winnersolutions1982 6 หลายเดือนก่อน

    Congratulations for the good work!
    Can the STM32F446RE read six input PWM signals (500Hz) simultaneously?
    Thanks

    • @dmitrymarukh6857
      @dmitrymarukh6857 5 หลายเดือนก่อน

      If you use the simple method I've described in my comment, STM32F446 can capture up to 14 PWM signals, depending on the package. TIM1-5 and TIM8 two signals each, and TIM9/TIM12 one signal each. 64-pin RE package may not have all of them available due to pin multiplexing.

  • @nsanandkumarak
    @nsanandkumarak 2 ปีที่แล้ว +2

    Hi Controller Tech, May i know how many years of experience do you have?
    you are really great...you are making useful videos, teaching, and making a good embedded engineers.
    The real usage of peripherals...explanation is well

  • @bisoncom5139
    @bisoncom5139 2 ปีที่แล้ว +3

    WARNING: The DMA code to calculate the averaged width is full of error. It doesn't check the array boundaries at all. DON'T blindly copy/paste them!

    • @dmitrymarukh6857
      @dmitrymarukh6857 ปีที่แล้ว +1

      Not to mention that the code itself is pointless. All that scanning and averaging is only there because the timer is not configured to automatically reset on rising edge

    • @ThinhLeQuang-d6h
      @ThinhLeQuang-d6h ปีที่แล้ว

      can you help me explain more detail sir, thanks

  • @ZahraVahidi-ki9pv
    @ZahraVahidi-ki9pv 5 หลายเดือนก่อน

    I had a question about the PWM function you replaced in minute 7:00; what was the correct one? because actually the one that you replaced wasn't different from the wrong one

    • @ControllersTech
      @ControllersTech  5 หลายเดือนก่อน

      It was HAL_TIMex_PWMN_Start

    • @ZahraVahidi-ki9pv
      @ZahraVahidi-ki9pv 5 หลายเดือนก่อน

      @@ControllersTech but I again got error with this function; it seems STM32 HAL library doesn't have this function, what can I use instead?

    • @ControllersTech
      @ControllersTech  5 หลายเดือนก่อน

      That is why I replaced it in the video.

    • @ZahraVahidi-ki9pv
      @ZahraVahidi-ki9pv 5 หลายเดือนก่อน

      @@ControllersTech I get weird output with "HAL_TIM_PWM_Start" too, I'm using STM32F103C8T6

    • @ZahraVahidi-ki9pv
      @ZahraVahidi-ki9pv 5 หลายเดือนก่อน

      Thanks for your responding

  • @swapnilmeshram8774
    @swapnilmeshram8774 3 ปีที่แล้ว

    Sir CAN you explain, why this same piece of code is not working with Nucleo STM32H743ZI2 board... It is perfectly working fine with Nucleo STM32F767ZI board but with Nucleo STM32H743ZI2 dma interrupt is not working, HAL_TIM_IC_CaptureCallback this function is not getting called once...

  • @IdinEsmkhani
    @IdinEsmkhani ปีที่แล้ว

    I want to measure 40 MHz frequency. How ca I do it ?

  • @tandungbui5694
    @tandungbui5694 ปีที่แล้ว

    Hello sir, i cant understand the variable riseData number meaning. Can you make the video explain the code in callback function?

    • @tandungbui5694
      @tandungbui5694 ปีที่แล้ว

      i use STM32F103 so the maximum Preriod is 65535 but it still get the riseData with uint32_t type. How it can be?

  • @sidpan-op8dm
    @sidpan-op8dm ปีที่แล้ว

    What is dma used for?

  • @adesuyisunday4287
    @adesuyisunday4287 3 ปีที่แล้ว

    Nice. Can you do sinewave inverter using stm32 and in hbridge configuration? Something like that

  • @mortezaghorbani7927
    @mortezaghorbani7927 9 หลายเดือนก่อน

    how to measure it without input capture?

  • @Andr_e_y
    @Andr_e_y 3 ปีที่แล้ว

    HAL_TIM_IC_CaptureCallback on the f767 board also does not work for me. Judging by the debugging The isMeasured flag is not set

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      If you are capturing a low frequency pulse, it will take some time for it to collect the required number of samples..

    • @Andr_e_y
      @Andr_e_y 3 ปีที่แล้ว

      @@ControllersTech I capture 1 MHz, as in the example. TIM2 - 54MHz count up to 65535.

  • @SpaceAp3
    @SpaceAp3 2 ปีที่แล้ว

    Any tips on getting an input capture of a 50 Hz signal with this method?

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      Use small frequency for timer..

    • @SpaceAp3
      @SpaceAp3 2 ปีที่แล้ว

      @@ControllersTech I tried that, I'm hoping to use the 16 bit timer for this task, I've only successfully tested timer 2 (32bit), I'm also using a STM32F4...

  • @surajjadhav7043
    @surajjadhav7043 3 ปีที่แล้ว

    Sir,Can you Please make a video on the Azure RTOS implementation on the STM32

  • @RixtronixLAB
    @RixtronixLAB 3 ปีที่แล้ว

    Nice video, thank you :)

  • @deutrion
    @deutrion 3 ปีที่แล้ว

    Thanks forthe video

  • @mirsadnadarevic-karlsson1463
    @mirsadnadarevic-karlsson1463 3 ปีที่แล้ว

    U are the best

  • @sugiyartosugiyarto1587
    @sugiyartosugiyarto1587 3 ปีที่แล้ว

    Sir please make look up table using stm32cubemx..thanks

  • @usmanhaider4653
    @usmanhaider4653 2 ปีที่แล้ว

    Plz add serial number to same topic videos.