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.

simple timer for TMS570

Other Parts Discussed in Thread: HALCOGEN

Hello, I need a simple count up or down timer to trigger an interrupt routine when finished, preferably 32 bit. I don't have a lot of time to evaluate the Hercules product and as such cannot get into the throws of the HET. I've tried several approaches with the Halcogen program with no avail. Thx.

  • Jon,

    The HalCoGen 'example_rtiBlinky.c' should show how to do this.

    Did you try that example and have some problem with it or is it not a fit somehow?

  • Hello Anthony,

    Yes, I have done rtiBlinky and it works with the parameter set forth in HalCoGen. However, when i try to change them with the HalCoGen APi (i.e. rtiSetPeriod) the resulting period retains the original initial set period configured with the HalCoGen program.

    void main(void)
    {
    /* USER CODE BEGIN (3) */
    	rtiInit();
    	gioInit();
    
    	rtiStopCounter(rtiCOUNTER_BLOCK0);
    	while(!rtiResetCounter(rtiCOUNTER_BLOCK0));
    	rtiSetPeriod(rtiCOMPARE0,200);
    
        /* Start RTI Counter Block 0 */
    	rtiStartCounter(rtiCOUNTER_BLOCK0);
    
        /* Set high end timer GIO port hetPort pin direction to all output */
    	//gioSetDirection(gioPORTA, 0x00000004);
    
        /* Enable RTI Compare 0 interrupt notification */
    	rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
    
        /* Enable IRQ - Clear I flag in CPS register */
        /* Note: This is usually done by the OS or in an svc dispatcher */
    	_enable_IRQ();
    
    	gioToggleBit(gioPORTA,0);
        /* Run forever */
    	while(1);
    /* USER CODE END */
    }
    
    And in the notification.c
    #pragma WEAK(rtiNotification)
    void rtiNotification(uint32 notification)
    {
    /*  enter user code between the USER CODE BEGIN and USER CODE END. */
    /* USER CODE BEGIN (9) */
    	gioToggleBit(gioPORTA,0);
    	rtiStopCounter(rtiCOUNTER_BLOCK0);
    /* USER CODE END */
    }

    Thx, Jon

  • John,

    I started from the example in a bit of a clean-slate and tried changing the period in the way that I'd expect to do it, and it worked.  I did this because I wasn't sure what you were trying to do through the 'rtiStopCounter' call, etc.

    Here's the C file for main:

    2553.sys_main.c

    Aside from the new declarations this is the code I did this:

    /* Run forever */

    while(1) {

    current_period = rtiGetPeriod(rtiCOMPARE0);

    rtiSetPeriod(rtiCOMPARE0, current_period);

    for (delay = 0; delay < 0x1000000; delay++);

    }

    The way that I tested this was to run this for a while and see that the LED is flashing at 1Hz.

    Then pause, and set a breakpoint at the line 'rtiSetPeriod'.  

    When the breakpoint is hit, add 'current_period' to the watch window.
    I saw it was something like 10000000 for 1Hz.  I changed the period to : 2500000, cleared the breakpoint, and ran again to see that the period had gone to about 4Hz.

    Our RTI is a little different than a simple RTI so maybe you were doing the stop counter without knowing the RTI architecture.    In our RTI the counter is free running,  you don't have to reset it at all. 

    The compare registers have an 'update compare' buffer register.  When the compare matches,  the update compare value is *added* to the compare value and written back into the compare register.

    For example if you make update compare 0x100 then the first time that the compare matches it will change the compare to 0x200.   The second time the compare matches it will change to 0x300, etc.   You never have to reset the counter to get the 0x100 period.   And if you want to change the period of the next compare to 0x150, you just write this to the update compare register.   Then in this example when the compare hit 0x300,  it would get + 0x150 so that the next compare would be set for the count value of 0x450.

    This is nice also because the different compare registers 0,1,2,3 can be set to periods that are basically independent of each other;  given that the counter is not reset.

    And there are a few timestamp 'capture' registers that you can use to measure the timing of system events against this same timebase.

     

     

  • Anthony,

    Thank you for your reply. I don't think the rti is going to work for me. I need something much more simple than this. But I appreciate your time to check it out for me. Jon Buckman