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.

TM4C123GH6PM: Time measurement via HWREG(DWT_BASE + DWT_O_CYCCNT)

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL

Hello,

To count the clock cycles on a tm4c123gh6pm I have been doing:

// enable clock measurement
HWREG(NVIC_DBG_INT) |= 0x01000000;    // enable TRCENA bit in NVIC_DBG_INT
HWREG(DWT_BASE + DWT_O_CYCCNT) = 0;   // reset the counter
HWREG(DWT_BASE) |= 0x01;              // enable the counter

uint32_t marker = HWREG(DWT_BASE + DWT_O_CYCCNT);
Which is basically a counter with each clock cycle. Is there anyway I can intervene to overflow situation, like maybe trigger an interrrupt when overflow occurs?I would like to set a marker, when an overflow occurs, so that I later can calcuate real seconds, using this as an offset.Also, can someone point me the documentation for nvic? there is no reference to this at the datasheet.Best Regards,C.A.

  • Hi Can,

      DWT is the Digital Watchdog. DWT is a down counter, not a up counter. Normally you would do a one time setup for the counter value (e.g. 500ms). You first preload the WD counter with your timeout value and the counter will count toward zero. Before the counter is expired, you must periodically clear the WD to prevent it from expiration. When WD reaches zero, it will first generate an interrupt. Upon the second expiration, it will generate a reset. The WD is used as a means to reset the system when you have a runaway code. 

      I'm not sure about your application. I will suggest you use RTC (Real-Time Counter) to count real time based on a a 32.768kHz oscillator. Take a look at C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl\hibernate.

    Other options include the Timer Module. You could use Timer Module with RTC as the input clock for time keeping too. Please refer to the datasheet for details. 

    You can also use SysTick that is a built-n timer in the processor. Take a look at C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\systick example. 

      

  • Dear Charles,

    The application is to generate 1microseconds or less timestamps. So far I am using the SysTick interrupt at frequencies of 1024hz, and getting the SysTickValue() to calculate the timestamp as an alternative to getting it from digital watch dog. If the systick value is decremented with each clock cycle, this should give us the same precision as getting it from DWT, am I correct here?

    I don't really need time keeping, but I do need to sync host and mcu in time. What would you recommend in such scenario? what can I gatin buy using the built in rtc?

    For example, can the built in rtc generate an interrupt or drive a pin with given frequency?

    best regards,

    c.

  • Hello,

    I have read the "7.3.5.1 RTC Counter - Seconds/Subseconds Mode" chapter in the datasheet.

    Would it be safe to say I can get a 15bit counter with subsecond precision if I use RTC?

    It seems that by reading HIBRTCSS I can get the subsecond value, and use this as a timestamp.

    And it says "A write to the HIBRTCLD register clears the 15-bit sub-seconds counter field" so I can use this to reset the counter, but only to 15bit precision. Are these correct?

    Best Regards,

    C.

  • Hi,

    Would it be safe to say I can get a 15bit counter with subsecond precision if I use RTC?

      Yes, you can use the Hibernate module for subsection precision.