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.

NHET PCNT Instruction

Hi,

I am using the TMS570 Microcontroller Development Stick, with a TMS570LS20216 MCU (ASPGEQQ1).
I have a short NHET program to measure time periods:

P01   PCNT { next=P02,reqnum=0,request=GENREQ,irq=ON,type=FALL2FALL,pin=10,period=0,data=0,hr_data=0}
P02      BR    {next=P01,cond_addr=P01,event=NOCOND}

I am getting data in the PCNT Data Field, but the data does not appear in bits 0 to 3. Looking at the Technical Reference Manual, this suggests that the lower 7 bits are for "HR Data", does this mean that I should shift my data right by 7 bits?

When I ignore the lower 4 bits (i.e. I shift the data right by 4 bits) and convert the hex data read to a decimal value and then multiply this by the period, calculated from 1/VCLK2, this gives me the measured count period in seconds. From this I can calculate the frequency, which seems to be the right number. If I have to shift the data (by 7 bits instead), the calculation will not work.

For example, I am using a 10kHz square wave, which is a period of 100microseconds. I have set VCLK2 to be 34MHz, so the period should be 2.9411E-08 (29.411ns).

My Prescale Factor Register is 0x00000300, which gives loop resolution =8 and high resolution = 1.

The data I read is D440, D44 converts to 3396. Multiplying this by the period gives 9.988E-05 seconds, which converts to 10000Hz.

Should I be shifting the data by 7 bits?

 

 

  • Hi Dave,

    NHET works with numbers in a Q25.n format, left justified in memory.   The integer portion of the number is units of loop resolution periods.

    The '.n' means that the number of bits representing the fractional portion of the number depends on the loop resolution prescaler.

    In your case, your LRP is set for 8 clocks;  and the highest resolution that the NHET can operate at is in increments of 1/8 of the LRP clock.

    This means that n = 3, so your numbers are Q25.3 left justified.

    Left justified means that the upper 25 bits (integer portion) of the number are always located in memory bits [32:7].   The decimal place is between bits 7 and 6.  Bit 7 has a weight of 1 LRP;  bit 6 a weight of 1/2 LRP, bit 5 a weight of 1/4 LRP,  bit 4 a weight of 1/8 LRP.  In your case this is as far as you can go because the highest resolution clock is only 1/8 LRP.   So for your example bits 3:0 wind up being reserved - you shouldn't pay any attention to them.

    Hope that helps, but if not let me refer you to "18-6 Table 18-6.  Interpretation of the 7-Bit HR Data Field" of SPNU489B  (http://www.ti.com/litv/pdf/spnu489b)

    NOTE: over time the revision 'b' may change as the doc is updated so if the link doesn't work try searching TI.com for SPNU489 ..

  • Hi Anthony,

    I have one question here. I am also measuring the frequecy (or period ) of the input square wave signal. Please let me know whether my calculation of frequecy is correct or not.

    VCLK2 = 160Mhz. hr=1, lr=64, and the freucy of the inout signal is 12khz.

    Below is the data filed value of the PCNT instrution that i get.

    PCNT Data Filed : 0x6830.

    Bit 31 to bit 7 : This filed represent the loop resolution count : And for this example , It is D0hex that means 208 loop resolution cycles.

    bit 7 to bit 0 : This filed represnet the High resoltion count : And for this example, it is 18hex ( used "18-6 Table 18-6.  Interpretation of the 7-Bit HR Data Field" ) that means 24 High resolution cycles.

    LRP = 400ns HRP = 62.5ns

    So input signal time period = 400*208 + 24 *6.25 =83350ns

    Expected value = 83333ns.

    Please correct me if my understanding of calculation is wrong.

     

  • The calculation is correct. But VCLK2=160MHz is out of the spec.

     

  • Thanks for the quick reply anthony.

    What do you mean by out of spec ?

    I have few more quections about measurement.

    1. Once after the enabling the het, what is right time to read PCNT data filed ? I mean how much time we need to wait ?

    2. I try to read the Data filed of PCNT continuosly 10 times, without changeing the input signal frequecy as below. In every loop, the value of the Data files changes. Why ?

     for(j=0; j<10; j++)
     {

    // function to read the Data filed.
      signal = capGetSignal(cap0);

    // Delay for some time
      for(i=0; i<100; i++);
     }

     

  • In the datasheet, the VCLK2 frequency should <=100MHz.

    Following this application note (Leveraging the High-End Timer Transfer Unit on Hercules ARM Safety MCUs (Rev. A)), the PCNT data field will automatically transfer to the main SRAM once it is updated.

    What is the percentage of this change? It should be less than a few HRPs if the frequency is stable.

  • Hi,

    Thanks for the clarification. Once after the initialization of NHET, i did not see any update in the Data filed of PCNT. I waited for few dummy for loops to be able to see the value in PCNT data fileld.

    Yes. Looks like the change is few HRP cycles only.