cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746: behaviour of from Timer to Memory DMA transfer when timer event occurs

BrMel10
Associate II
 
Hi everyone

 

Question: suppose one sets up a DMA transfer from a Timer1 register to memory so that it gets executed when timer event is raised. What happens first:
  • the peripheral to memory DMA transfer is executed ?
  • or the Timer registers are updated?

 

Context:
I am trying to implement a periodic pulse counter.
In a nutshell:
  • A timer acts as master and handles the time window (for ex.: 50microseconds) generation. When the window period elapses, its UPDATE event triggers the TRGO
  • Another timer (Timer1) is continuously counting pulses on its ETR clock source. Timer1 is setup as Slave in "Combined Reset Triger mode" so that upon master timer signal is sensed on the ITR, the timer/counter gets reset and resumes counting pulses.
The issue is that the pulses are only around 20nanoseconds long and should all be counted. But also, at the very end of each measuring window, the CNT register must be read just before being reset to zero.
Given how fast the pulses are, the assumption is that the best chance of not loosing pulses is via a DMA transfer to transfer/copy the the value in the CNT register to memory which is (I think) requested by the Timer event. 
 
But has mentioned, the doubt is: will the copy to memory be executed before or after the CNT register is zero'ed?

 

I've been trying to make this work for a will now using (DMA2 Strem0 Channel 6 TIM1_TRIG), but so far unsuccessfully. So I thought I'd post the question here because I maybe trying to accomplish something that, to the eyes of someone more knowledgeable, may be obviously impossible and I am just loosing time.
Any chance someone knows if it is possible to read the CNT register before it gets erased?
If this is not the correct approach, could someone suggest a alternative?
 
1 REPLY 1
MasterT
Lead

I don't see a necessity of reset counting timer. Set one timer to trigger dma transaction with periodicity you like, 20 kHz (50 usec) or so. DMA transfers CNT of counting timer to memory. Subrtacting two data samples located in memory array  N0 - (N-1)  gives number of pulses in present time slot. Overflow is special case, and easily checked and corrected, arduino frequency counter library is an excelent example of code