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 based time interval generation

Other Parts Discussed in Thread: TMS570LS20216, HALCOGEN

Hello,

It is necessary to implement the following functions for TMS570LS20216 microcontroller:

1) Generation of periodic interrupts (approximately 10ms). This will be used as time base for generation of much larger intervals in software.

2) Start and Stop counting another timer. This timer should be started and stopped from software. If timer is not stopped then interrupt should be generated. This approach will be used to limit response time from other devices in our application.  

General purpose timers/counters were used to realize these functions for 8- and 16-bit microcontrollers.

As I understand NHET should be used for this purpose. Can you please advise how to implement these functions using NHET?

No PWM is required for this particular application. Most of the NHET I/O pins will be used as GIO. My question regards only time interval generation and their corresponding interrupts.

Best regards,

Vitalij

  • Hi Vitalij,

    I have forwarded your question to our NHET expert. He will be responding you soon. Thanks

    Regards,

    QJ

  • Hello Vitalji,

    For #1, you use RTI to generate this periodic interrupt.  In my opinion, NHET is an overkill for this task.  The RTI module is designed specifically for this purpose.  Just setup only one time and all the counter and comparator will be automatically updated for 10 ms.  As a matter of fact, you can generate multiple periodic interrupts.  We can provide example RTI codes for you.

    For #2, i do not really understand your description.  Can you please clarify in term of an example on how you would envision the two timers (one is NHET and other timer is in another device) and the software running on TMS570 R4 would interact?

    Thanks and Best Regards,

    Henry Nguyen

  • Hello Henry,

    I was not sure about proper module for this purpose because this is the first project with TMS570 microcontroller. I will take a look on RTI description too. Example RTI codes would be very helpful to get started.

    #1 One 10ms periodic interrupt is required in my particular application.

    #2 The second timer should not operate periodically / continuously. Let’s assume it is necessary to generate single 1ms interval. This timer is started from software. When 1ms interval expires this timer generates an interrupt. Then ISR stops timer and performs required task. Software should be also able to stop this timer before it generates an interrupt.

    Thanks

    Vitalij  

  • Hi Vitalij,

    Thanks for the clarification.  I am clear now on what you want to do.

    For #1 and #2, you can use RTI to handle this task.

    Use block 0 counters for #1 solution and block 1 counters for #2 solution.

    Please download HalCoGen (GUI interface to generate baseline drivers and start up codes) from http://www.ti.com/tool/halcogen.

    Create new project (select correct device).

    Go to DriverEnable tab (see attached screen shot) and select only RTI driver to be generated.

    Go to RTI tab (see attached screen shot) and configure interrupt interval time for 1 ms and 10 ms.

    Click on generate codes.  This will be baseline codes.  You can add user configuration on top of these baseline API.

    One caveat  for using RTI for solution #2 is that user has to write to disable block 1 counters to stop the counter before servicing the 1 ms interrupt.  The RTI does not have the one shot option.

    If writing to disable RTI block 1 counters is not an option, then you can also write a simple NHET program to do this.

    Example as below:

    ; count up to X ms and stop.
    ; user has to write 1 to start data field bit 7 to start the counter,not hr_data field.
    ; user can also write 1 to start data field bit 7 anytime to stop the counter, not hr_data field
    ; calculate your max time as an example:

    ;Assume your period is 1 ms = 1000 ns.
    ;Assume VCLK2= 12.5 ns and LRP=16 => Number of LRP (period) = 1000 ns / (12.5 ns * 16) = 5 LRP.
    ;In this case just program MAXC=any number larger than 5, and TIMERCOMP.data=5, TIMERCOMP.hr_data=0.

    ;Assume VCLK2= 12.5 ns and LRP = 32, => Number of LRP (period) = 1000 ns / (12.5 ns * 32) = 2.5
    ;This means 2.5*LRP or LR=2, HR=10h (16 in decimal or half LRP loop clock. Each LRP is 32 HRCLK).
    ;In this case, just program MAXC=any number larger than 2, and TIMECOMP.data=2, TIMECOMP.hr_data[6:2]=10h (16 dec)

    MAXC      .equ   10

    START      MOV32 {type=IMTOREG, reg=A, data=0, hr_data=0}
               ECMP  {reg=A, action=PULSEHI, pin=0, en_pin_action=OFF, irq=OFF, data=1, hr_data=0, cond_addr=ENCOUNTER, next=OFFSTATE }

    DISCOUNTER MOV32 {type=IMTOREG&REM, reg=NONE, remote=START, data=0, hr_data=0}
    OFFSTATE   BR    {event=NOCOND, cond_addr=START, next=START}

    ENCOUNTER  CNT   { reg=T, max= MAXC, irq = OFF }
    TIMERCOMP  ECMP  { reg=T, action=PULSEHI, pin=0, en_pin_action=OFF, irq=ON, data=5, hr_data=16h, cond_addr=DISCOUNTER, next=START }

    ; The ECMP instruction will generate interrupt to CPU when 1 ms comparison matches.

    ; Please also enable NHET interrupt and VIM.

  • Uploading second image since each post can only attach one file

  • for clarification of how 7-bit HR data field is used, please look at TimeBase section 18.4.3 Time Base, 18.4.3.2 The 7-Bit HR Data Field

  • Hello Henry,

    I took a look on RTI module. At the moment I am trying to generate 10ms periodic intervals. RTI configuration was performed in HalCoGen:

    1) RTI driver enabled,

    2) Comp 3 source is Counter 1,

    3) VIM channel 5 enabled for RTI Compare 3.

    rtiInit () was first called in CCS. Then Compare Interrupt 3 was enabled and RTI counter block 1 was started.

    The problem is so that periodic interrupts are not generated. What is wrong in this example? The project is attached.

    6011.RTI.zip

    Best regards,

    Vitalij

  • Hello Henry,

    Can I ask you to check my example project?

    I have just created it.

    Besta regards,

    Vitalij

  • I found my error. IRQs were not enabled. Now 10ms periodic interrupts are generated normally.

    Thank you very much for information. I will study it too.