This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280049: Precise frequency measurement with HRCAP, eCAP, eQEP

Part Number: TMS320F280049

Hello there,

I already asked related question regarding using HRCAP for precise frequency measurement here.

I would like to compare these three modules (HRCAP, eCAP, eQEP) for frequency measurement of square wave.

Lets say we have square wave of 50% duty cycle running at 1-2 MHz. Width of each pulse is dependent on frequency as: 0.25 usec (50% duty cycle of 2 MHz) to 0.5 usec (50% duty cycle of 1 MHz). 

Please see following picture showing measured signal:

My questions:

Q1: Can each of these modules be used for measurement of such a signal?

Q2: What are limitations of each module in matter of min and max input frequency, duty cycle etc.?

Q3: What are achievable timing resolutions for each module?

For eCAP I found in SPRAAH1 and SPRU807B where timing resolution for eCAP is 1/SYSCLKOUT. Is then correct that eCAP has timing resolution of 10ns at 100MHz SYSCLK?

For HRCAP I found in SPRS945F (7.11.2.1) timing resolution of 450 ps for measurement longer >5usec.

For eQEP I found SPRSP14D (7.12.4.1) where timing resolution is specified as 2x SYSCLK. Here I am not sure what is resolution then.

Can you please summarize input frequencies requirements for each of this module?  

I appreciate your help.

Thank you,

Michael 

  • Hi Michael,

    Here are the answers to your question:

    1. Yes eCAP, HRCAP or eQEP can be used to measure frequency and duty cycle.

    2. Only limitation is Max frequency / min pulse width duration. (Please refer to datasheet on requirements)

    Pretty much all of them minimum input pulse width duration as 2*SYSCLK period = 2*10ns =20ns. Unless you use eCAP with GPIO input qualifier (please refer datasheet for more details)

    3. Resolution is what you have listed, eCAP=10ns (Sysclk period), HRCAP = 450ps (>5us) and eQEP = 20ns (2*sysclk period).

    Input frequency requirement for all the module is pretty much 50MHz. Which should meet your requirement of 1-2MHz. No limitation from Duty cycle point of view.

    Best Regards,

    Nirav

  • Hi Nirav,

    perfect. So ideally to use HRCAP module for best resolution.

    In previous question I got answer from Frank that minimum input frequency must be 9 MHz. That does not correlate with your answer. 

    What do you mean then by:

    Input frequency requirement for all the module is pretty much 50MHz. Which should meet your requirement of 1-2MHz.

    Q1: What is minimum required frequency of measured signal? ( I assume that max measured input frequency of signal is 50 MHz).

    Also I would like to understand a bit more how HRCAP works. Mainly to get bigger picture of processes inside, whether it reduces MCU's process power, etc.

    Q2: Is there some deep manual for HRCAP? (I found some SPRUI10  but they usually only describe performance, requirements etc.)

    Does it work as separate HW module which does not uses that much of MCU process time as regular periphery such as GPIO? 

    Q3:  Most important, is there any delay between capturing signal and having data in for further processing? Such as that HRCAP works as software which gives it its unique resolution. 

    In case of tens of usec latency between HRCAP and data I may not be able to use it.

    Q4: Is there a difference in functionality (latency, resolution etc.) between HRCAP type 0 and type 1? 

    I own F28069M, but I may rather use F280049C since it is newer design.

    Thank you Nirav,

    Best Regards,

    Michael 

  • Hi Michael.

    Frank is correct, I overlooked, if you look at the Datasheet you will see HRCAP max input frequency is 9MHz.

    Answers to your question:

    1. There is no restriction on minimum input frequency. In you application if your input frequency is 1-2 MHz, you can use eCAP/HRCAP both should work. In your application if you are ok with 20ns resolution, you can use eCAP.

    2. Please go through the Technical reference manual it has more details on HRCAP. But to answer your question HRCAP and eCAP are identical, only difference with HRCAP is it has high resolution block to capture any edges within SYSCLK period. eCAP/HRCAP are timer based module, which will capture the time stamp and stop the timer based on how you configure. But you still need CPU to process the captured values and calculate frequency/duty cycle.

    https://www.ti.com/product/TMS320F280049

    3. I dont completely understand your question on delay, but like I said in point #2 HRCAP will capture the event and stop the counter, and generate interrupt as user defined. Afterwards CPU has to go read the timer values for further processing. But this will not change the captured time stamp, as the counters will be stopped after the event has occurred. In case you have it defined in continuous mode than in between captures if you do not read values, you may loose the previous captured values. eCAP also had DMA access.

    4.If you want to use HRCAP I would recommend using newer device F280049C as you mentioned. It has some improvements in the calibration circuit. Please reference datasheet for more details on any timing differences.

    Best Regards,

    Nirav 

  • Hi Nirav,

    Frank may have accidently written opposite. 

    The HRCAP on the F28004x device requires a minimum pulse of 110ns which works out to about a 9MHz signal so will not work for your 1MHz signal. (The signal of 1-2 MHz works with this requirements since pulse width is 500 - 250 ns).

    Based on your answer and SPRS945F the minimum pulse width 110 ns (220 ns 1 period) corresponds to MAX frequency of 4.54 MHz (50% duty cycle PWM signal) correct?

    Your Q3 - 

    Q3:  Most important, is there any delay between capturing signal and having data in for further processing? Such as that HRCAP works as software which gives it its unique resolution. 

    I wanted to know if there may be some special software postprocess which gives it the high resolution but which would add latency after measurement. It does not look like. 

    Once signal captured for lets say 50 usec then MCU will read out the registers of HRCAP. I wanted to know what may be a delay between finished measurement of 50 usec and accessibility of results for MCU? The further process time in MCU to calculate frequency may be small (tents to hundreds of ns).

    Thank you.

    Best Regards,

    Michael

  • Hi Michael,

    Nirav is out of office this week so will take over this for now. You are correct, I misread your input signal requirement as 10MHz rather than 1MHz. The HRCAP should work for you.

    The min pulse width is 110ns which works out to 9MHz. However the frequency of the signal you are trying to capture depends on whether you are measuring the duty cycle or frequency. A square wave will have rise->fall->rise to indicate one period. To measure the frequency, you will need to capture rise->rise which means your frequency can be 9MHz using the HRCAP in order to meet 110ns requirement.

    However if you were trying to capture the duty cycle for this same signal, it wouldn't work because the delta between rise->fall or fall->rise will be about half 110ns. In essence if you want to measure the duty cycle, your signal has to be max of 4.5MHz for 50% duty cycle like you pointed out. Adjust accordingly for non 50% duty cycle. The min pulse width requirement here just refers to the time delta between 2 events (rise or fall).

    For your question on the latency, the ECAP/HRCAP does not have a post processing block so after the event has been captured, you will need to fire off an interrupt and service it. In addition, there are only 4 ECAP events so it's actually not possible to capture 50us worth of events in one shot if your signal is 1MHz (i.e 50 events). In your case, it will be better to use the DMA. You can setup the DMA to transfer the 50 ECAP capture events as they happen to some location in memory. After these 50 DMA transfers are complete, you can then fire off an interrupt to process them. Let us know if this is not clear.

  • Hi Frank,

    yes, I measure just frequency of 1-2MHz square wave signal, measurement rise->rise. Duty cycles are not my interest. They are always 50%.

    I have few questions regarding your answer:

    In addition, there are only 4 ECAP events so it's actually not possible to capture 50us worth of events in one shot if your signal is 1MHz (i.e 50 events). In your case, it will be better to use the DMA. You can setup the DMA to transfer the 50 ECAP capture events as they happen to some location in memory. After these 50 DMA transfers are complete, you can then fire off an interrupt to process them. Let us know if this is not clear.

    As you speak about 4 ECAP events does it correspond to HRCAP events as well? 

    As using DMA, MCU must after each 4 events (4x rise->rise) take values from HRCAP register and save it, so every 1-2 usec interval there must be MCU input. As it is DMA - HRCAP can run without stop, just MCU will every few usec save values from DMA. After 50 usec MCU will take all saved values and process them.

    MCU should have enough time to save all values without loosing any sample as it runs at 100 x faster than signal. Correct?

    Can these two processes run simultaneously? Continuously capturing data (without stop) and process them once per 50 usec ? 

    Even during the data being processed by MCU, MCU may always stop while processing and save a new data from DMA as new data from HRCAP are available. Correct?

    Thank you Frank,

    Best Regards,

    Michael

  • Hi Michael,

    Ok, if you are only interested in frequency, then 9MHz is your upper limit. Answers to your questions below:

    1. Yes, the 4 events also extend to the HRCAP. Keep in mind the HRCAP is an extension of the ECAP. There are a few caveats as outlined in the TRM but the 4 events also apply. I think your input signal is slow enough that you actually might be able to get away with just using 1 event.

    2. DMA means no CPU intervention once setup. In this case, after every 4 events, the DMA will transfer those 4 captured values to a location in RAM without CPU intervention and keep doing this until 48 or 52 captures are completed. After that point, the DMA will trigger an interrupt to service these captures. This is where the CPU comes in.

    3. As mentioned above, the only point where software/CPU comes into play is when you are processing the captures in the interrupt. As to whether or not you have time to complete the processing in the current interrupt and wait for the next interrupt depends on exactly what processing you are doing.

    4. Yes, these can run simultaneously in hardware. The capturing by ECAP and saving to memory by DMA will all happen completely in hardware. You will just need to make sure the processing time doesn't exceed the interrupt frequency. Essentially you will need to finish the processing before the DMA starts re-writing the table from the beginning else the data will be stale.

    5. Yes, you can stop this at any time. For instance after you receive the interrupt, you can stop the ECAP from making anymore captures before you start processing the data so the capture table doesn't get overwritten. After you are done with the processing, you can re-arm the ECAP, exit the interrupt and wait for the next set of captures.

  • Frank,

    Perfect, that is what I needed to know.

    1 - Do you mean to use one event instead of 4? I think 4 will make better average and gives more accuracy.

    2 - 5 - Ideally to calculate average from 48-52 events within one event of capture. Then there is no need to stop capturing new data. Question is whether the MCU can finish this calculation before one new capture overwrite previous (0.25 usec), or it should copy 48-52 captures in other location to preserve from overwriting them by new measurements and process within next 50 usec of new measurement period?

    My application is quite sensitive to latency between sensed data and forward them postprocessed (average, lookup table etc.) further. Therefore I do not want to loose any measurement data during the processing.

    Thank you,

    Michael 

  • Michael,

    1. I meant since you are only capturing rising edges, you don't need to use all 4 events but it will be slightly trickier to setup the DMA for 4 events in this fashion. To keep it simple, you can just setup 1 event and have the DMA transfer 1 at a time instead of 4 at a time. Sure the DMA will be under heavier utilization in this case but this all happens in hardware so shouldn't be a burden on anything else. I would recommend you start with this to see how the system works before increasing it to 4 events at a time.

    2. If your signal is 1MHz and you are capturing 50 periods, that gives you 5000 sysclks (at 100MHz) in total for your processing. However you have 100 sysclks (period of 1MHz assuming you are capturing just 1 event at a time) after you get your interrupt to copy your data before it gets overwritten. Essentially you have a little more time for processing but very little time before the data gets stale.

    There are 2 approaches you can use for this: You either copy the data as soon as you receive the interrupt before processing or better yet, also use the DMA for this. Basically after the initial 50 transfer is complete by DMA1, instead of it triggering your processing interrupt, it triggers DMA2 to copy the content to a buffer location. This second copy will be much faster because it will happen at sysclk rate and not the ECAP capturing rate. After DMA2 is done buffering the content, it fires off your processing interrupt which works on your buffered content and not the original transfer. Processing interrupt ends and cycle repeats.

  • I test suggested approach and let you know.

    Thank you Frank for all support.