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.

320F28044 ccsv4: division vs. interrupt

Hi,

i have a problem with a division in the main loop and ADC interrupts.

The division (int32) needs 56 CPU Cycles. (Sourcecode: result = number1 / number2;)
Is it possible that the division can not be interruped by the ADC interupt? 
Because, if i comment out my division the interrupt is on time. If the division ist commented in, the interrupt occur to late.

How can i solve this?

Best regards
Benjamin

  • Benjamin,

    Your observation is on target.  Your int32 division will call the L$$DIV function from the RTS library.  This function contains a single-repeat (RPT) construct that will lock out interrupts for 33 cycles:

             RPT    #31
     || SUBCUL  ACC, *-SP[2]

    If you step through the L$$DIV function in the disassembly window, you will see the above construct.  The 33 cycles is 1 cycle for RPT, 1 cycle for the first SUBCUL, and then 31 cycles for the repeated SUBCUL.  RPT is not interruptible.

    To get around this you need to do two things:

    1) Modify the libraries L$$DIV function to get rid of the RPT construct

    2) Get the tools to call the modified function rather than the original.

    Item #1 above is easy.  The L$$DIV function is in the compiler \lib folder.  Unzip the rtssrc.zip archive to a temp directory, and locate the file l_div28.inc.  This is an include file that gets used when the library is built.  You can replace the RPT #31 || SUBCUL with a total of 32 inline SUBCUL instructions.  Note that this will cause the function to execute more slowly, since a single SUBCUL takes 2 cycles whereas a RPT SUBCUL takes N+1 cycles where N is the number of times repeated.  If this is a concern, you can break the RPT #31 into several smaller RPT constructs, for example two RPT #15 constructs.  An interrupt can be taken in between the two RPT #15:

         RPT     #15
      || SUBCUL  ACC, DEN

         RPT     #15
      || SUBCUL  ACC, DEN

    You need to calculate how much interrupt time interrupts can be locked out for in your system, and break the RPT up accordingly.

    Now item #2, getting the tools to call the modified function, is more tricky.  You could just rebuild the RTS library (there is a mklib.exe command line function in that folder that will do this).  That will mean all long division in your project will use the new function.  This may well be acceptible to you.  If you want only a particular call to the division to use the modified function, then you will need to play around a bit.  I'd put the source code for the L$$DIV function into its own source file that you add to your function.  Also, I'd change the name of the function to something else, say MyL$$DIV.  Then instead of writing code to as z=x/y, you would do this: z = MyL$$DIV(x, y).

    Regards,

    David

     

     

     

     

  • David,

    thank you very much. I think we got it.


    Best Regards 


    Benjamin