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 Жыл бұрын
THANK YOU;;;;;;;;;;;;;;;;;;;
@Gruftgrabbler7 ай бұрын
Hello can you please explain your suggestions in a more clear way? I have trouble to understand it.
@dmitrymarukh68577 ай бұрын
@@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.
7 ай бұрын
@@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...
@Gruftgrabbler7 ай бұрын
@@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.
@ZahraVahidi-ki9pv7 ай бұрын
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
@ControllersTech7 ай бұрын
It was HAL_TIMex_PWMN_Start
@ZahraVahidi-ki9pv7 ай бұрын
@@ControllersTech but I again got error with this function; it seems STM32 HAL library doesn't have this function, what can I use instead?
@ControllersTech7 ай бұрын
That is why I replaced it in the video.
@ZahraVahidi-ki9pv7 ай бұрын
@@ControllersTech I get weird output with "HAL_TIM_PWM_Start" too, I'm using STM32F103C8T6
@ZahraVahidi-ki9pv7 ай бұрын
Thanks for your responding
@ricolauersdorf6872 жыл бұрын
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!
@공돌이-h9v9 ай бұрын
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.
@bisoncom51392 жыл бұрын
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!
@dmitrymarukh68572 жыл бұрын
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 Жыл бұрын
can you help me explain more detail sir, thanks
@nsanandkumarak3 жыл бұрын
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
@ControllersTech3 жыл бұрын
With stm, i have around 4 years..
@winnersolutions19828 ай бұрын
Congratulations for the good work! Can the STM32F446RE read six input PWM signals (500Hz) simultaneously? Thanks
@dmitrymarukh68577 ай бұрын
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.
@Karroo743 жыл бұрын
All what you do is very useful. Thank you!
@swapnilmeshram87743 жыл бұрын
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...
@sidpan-op8dm Жыл бұрын
What is dma used for?
@tandungbui5694 Жыл бұрын
Hello sir, i cant understand the variable riseData number meaning. Can you make the video explain the code in callback function?
@tandungbui5694 Жыл бұрын
i use STM32F103 so the maximum Preriod is 65535 but it still get the riseData with uint32_t type. How it can be?
@IdinEsmkhani Жыл бұрын
I want to measure 40 MHz frequency. How ca I do it ?
@mortezaghorbani792711 ай бұрын
how to measure it without input capture?
@adesuyisunday42873 жыл бұрын
Nice. Can you do sinewave inverter using stm32 and in hbridge configuration? Something like that
@Andr_e_y3 жыл бұрын
HAL_TIM_IC_CaptureCallback on the f767 board also does not work for me. Judging by the debugging The isMeasured flag is not set
@ControllersTech3 жыл бұрын
If you are capturing a low frequency pulse, it will take some time for it to collect the required number of samples..
@Andr_e_y3 жыл бұрын
@@ControllersTech I capture 1 MHz, as in the example. TIM2 - 54MHz count up to 65535.
@AtmoPierce3 жыл бұрын
Any tips on getting an input capture of a 50 Hz signal with this method?
@ControllersTech3 жыл бұрын
Use small frequency for timer..
@AtmoPierce3 жыл бұрын
@@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...
@usmanhaider46532 жыл бұрын
Plz add serial number to same topic videos.
@surajjadhav70433 жыл бұрын
Sir,Can you Please make a video on the Azure RTOS implementation on the STM32
@RixtronixLAB3 жыл бұрын
Nice video, thank you :)
@deutrion3 жыл бұрын
Thanks forthe video
@mirsadnadarevic-karlsson14633 жыл бұрын
U are the best
@sugiyartosugiyarto15873 жыл бұрын
Sir please make look up table using stm32cubemx..thanks