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.

Interrupts and Timer Question

Other Parts Discussed in Thread: HALCOGEN

I've checked the RM4 Wiki, the video online training, the datasheet, and technical reference manual, and I cannot find any example code implementing a timer or handling an interrupt with Hercules microcontroller. 
Is there any example code available?
Is there any training available for interrupts? 

Thanks

  • Philip,

    If you install HalCoGen, there is an examples folder.

    The example 'example_rtiBlinky.c' shows how to use the RTI timer w. interrupts.

     

  • Thanks for the quick response.

    I was able to generate an interrupt after looking at that example. 

    I need a timer or something to benchmark some code.  According to the technical reference manual, I should be able to do that with the RTI, but I can not find any examples for that.   How do I read the registers and compare them to see how long some code has taken?

    Thanks again, 

    Phillip

  • Phillip,

    For profiling, the CPU includes a PMU unit with several counters - one is a dedicated cycle counter but there are others where you can measure cool stuff like # of dual issues, etc.

    HalCoGen includes code for PMU;  although I don't see a canned example like there is for the rtiBlinky.

    I've got a project (doesn't run standalone, so it wouldn't make sense to .zip it) that uses PMU.

    Here are the pieces that I added to my project:

    1)  #include "sys_pmu.h"

    2)In test bench code before your algo that you want to benchmark:

    _pmuInit_();

    _pmuEnableCountersGlobal_();

    _pmuResetCycleCounter_();

    _pmuStartCounters_(pmuCYCLE_COUNTER);

    3)  to read the counter, call

    _pmuGetCycleCount_()

    I believe this takes void as a paramter and returns uint32 as a result (in cycles) but not 100% sure so pls. double check.


    The delta time can be read by subtracting two values returned by _pmuGetCycleCount_().

    So put these around your algo and you'll get the time.  Although there will be some error due to the overhead in the

    _pmuGetCycleCount_ function.   You can put two successive calls to _pmuGetCycleCount_ with nothing in between to get the overhead and then subtract the result from your algo result if you want to be more accurate. 

    The PMU itself can be accessed in only 6 cycles and doesn't need to have a pointer loaded into a register since it's in the coprocessor space of the CPU.  Therefore it's a lot more accurate and less intrusive than trying to do the same through RTI.  

     

    EDIT: I forgot - of course you need to check your HalCoGen config for PMU, to make sure pmuInit() actually initalizes it the way you want.   But,  since the above uses the dedicated cycle counter I don't think there's too much that could go wrong...