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.

RM48 N2HET ~64bit timer + HTU

Hi,

I have a complex encoder I need to data log each of the rising and falling edges of the encoder. I wish to save the time stamp of each edge into a memory for later processing.

Given the nature of what I am measuring, the maximum time between edges can be several minutes, and the minimum time is likely to be a few milliseconds.

My questions:

1. What is the best way to set up a virtual counter in the N2HET for around 64bit operation. Is it best to use the CNT instruction to define a 25bit counter and then is there possibility to check for a rollover?

2. If I can use a rollover, or CNT = 0 or similar approach, what next?. Is it best to use DADM64 or similar?

3. On each rising of falling edge of a pin, I wish to snapshot this 64 bit counter to a memory location using HTU. Is this the best approach?

Any feedback would be great.

Thanks

Stomp!.

  • Hi Stomp,

    First of all, have you considered using the WCAP instruction? The WCAP instruction is designed for capture timestamps. You might be able to configure the Loop Clock such that with just one 25-bit counter you can cover the max time (in the range of minutes) to the min (in the range of milliseconds). Of course you need to do some study to see if this is feasible using only one counter to cover both ends.

    1. When the CNT reaches the max count it will set the Z flag at which time the virtual counter will rollover. You can generate an interrupt for the CNT instruction for the Z flag is set.

    2. I think DADM64 is one option. Since NHET is a programmable coprocessor, there can be multiple ways to accomplish the same goal. I could image to use a BR instruction where it will branch conditionally depending on the state of the Z flag. When Z flag is set it can branch to another virtual counter to implement a cascaded 50-bit counter. This is just another thought.

    3. Using HTU is possible. In my opinion it depends on how often and how many data you need to read from the HET RAM. If you are reading only two data fields you might want to consider using the CPU to read it at each captured edge. Using the HTU is possible but you are transfering only two data fields from the HET RAM to the CPU RAM. Once the transfer is done, the HTU still needs to generate an interrupt to the CPU to notify the CPU the transfer is done. In this case, I don't really see a big advantage to use the HTU to read.
  • With the N2HET,  you can implement a 64-bit counter by using an   ADD followed by an ADC.

    Just capture both the data field of the ADD and the ADC when the event occurs. 

    If you want Hi-Res capture that should still work but in the ADD, add 0x80 (the 2^0 position for 25.7 fixed pt)

    and let the capture's hi-res feature do the rest.   Just make sure that the result of the ADD is in the register

    (usually T) that you capture hi-res against.   The upper 32-bits should be captured w. Loop Res.

    -Anthony