Skip to main content
EvgenS Po
Associate III
May 9, 2018
Question

timer DMA GPIO input capture with constant frequency

  • May 9, 2018
  • 14 replies
  • 3986 views
Posted on May 09, 2018 at 08:37

Hello! I need to capture signals on inputs with constant frequency for further investigation. I use the following scheme: set timer frequency needed with update DMA request and capture size for DMA, then get data from input pins via DMA. The capture itself works. The problem is DMA capture inaccuracy, it seems DMA capture frequency floats and is not constant which results in input signal wrong capture. For exapmle, timer update frequency (capture frequency) is 100 kHz, input is10 kHz PWM signal with 50 % duty cycle; capture is 10,5 kHz PWM with 40 % - 55 % duty cycle. The more capturing frequency, the more capture inaccuracy. If timer update frequency is 1 MHz, input is10 kHz PWM signal with 50 % duty cycle; capture is 10,5 - 12,3 kHz PWM with 40 % - 55 % duty cycle. Please, see attached picture. I tried to sleep CPU while capturing, the result is the same.

What could be done to make capturing precise and stable?

#timer-update-dma-gpio

Note: this post was migrated and contained many threaded conversations, some content may be missing.
This topic has been closed for replies.

14 replies

Tesla DeLorean
Guru
May 9, 2018
Posted on May 09, 2018 at 10:48

Salient details here would be the specific STM32 parts being used, the clocks, and prescaler/period settings of the timers.

The periodicity of TIM driven DMA should be pretty consistent.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
T J
Senior III
May 9, 2018
Posted on May 09, 2018 at 13:20

it may be that your program is not structured quite right.

I found using input capture on either edge, captures a fast running clock.

the trick is never reset the TimerValue, just use the relative time between interrupts.

but when the pulse is almost instant at 0.00001% duty cycle, you will miss an interrupt,

so the DMA is the better path.

not sure if you ask the DMA to save the timer value,:( never tried it )

then the DMA could save all 32TimerBits, if you need fine, high resolution

which chip is it ?

which reference manual are you looking in ?

EvgenS Po
EvgenS PoAuthor
Associate III
May 9, 2018
Posted on May 09, 2018 at 13:50

MCU is stm32f042k6t6t, system clock is 48 MHz PLL sourced by HSI/2 clock. DMA request timer is TIM3, PSC = 23, ARR = 20. During capture cpu sleeps (WFI command), no processing executed, only DMA and TIM3 are active.

'The periodicity of TIM driven DMA should be pretty consistent.' How can one achieve that? Does external crystal add stability?

waclawek.jan
Super User
May 9, 2018
Posted on May 09, 2018 at 16:27

system clock is 48 MHz [...] PSC = 23, ARR = 20

That does not sound like 100kHz nor 1MHz.

JW

EvgenS Po
EvgenS PoAuthor
Associate III
May 9, 2018
Posted on May 09, 2018 at 17:08

48000000/(PSC+1)/ARR=48000000/24/20=100000.

Frequency itself does not matter in that case. Whatever it is, it seems DMA capture happens with different periods.

henry.dick
Associate II
May 10, 2018
Posted on May 10, 2018 at 14:19

From your description it is not clear if you are sampling the in out or capturing the input. 

And what you were trying to show with that picture.

EvgenS Po
EvgenS PoAuthor
Associate III
May 10, 2018
Posted on May 10, 2018 at 14:45

I'm capturing GPIOx->IDR. The picture shows captured signal on PA0, which should be of 50% duty cycle, but as it's seen, it's not.

henry.dick
Associate II
May 11, 2018
Posted on May 11, 2018 at 14:38

'

The picture shows captured signal on PA0'

how? what's the mechanism in your code that ensures that PA0 flips with each capture event?