<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックRe: The difference of LPCOpen version to use division ROM</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565973#M17218</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;bump&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 19 Jun 2016 01:05:26 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-19T01:05:26Z</dc:date>
    <item>
      <title>The difference of LPCOpen version to use division ROM</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565968#M17213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gl_belre9 on Thu Mar 17 00:36:20 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I found it takes process time of division ROM in LPCOpen version 2.15 more than in 2.19, using LPCXpresso824-MAX board.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd like to know the reason of this difference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I verified the process time by using SysTick timer, showing source code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I compiled this code in Optimization Level -O0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It takes 115us in LPCOpen 2.19, and 144us in 2.15.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/*
===============================================================================
 Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : lpc824_divtest.c
 Author&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : gl_belre9
 Version&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :
 Description : main definition
===============================================================================
*/

#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

#include &amp;lt;cr_section_macros.h&amp;gt;

#define TICKRATE_HZ (2)/// Frequency for SysTick Timer
#define LOOP_NUMBER24

/*****************************************************************************
 * Public types/enumerations/variables
 ****************************************************************************/
static volatile uint32_t ticks;

/*****************************************************************************
 * Private functions
 ****************************************************************************/


/*****************************************************************************
 * Public functions
 ****************************************************************************/
/**
 * @briefHandle interrupt from SysTick timer, measurement of time
 * @returnNothing
 */
void SysTick_Handler(void)
{
volatile float time = (float)((1.0 / TICKRATE_HZ) / (float)ticks);
time *= 1000000;
ticks = 0;
}
int main(void) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read clock settings and update SystemCoreClock variable
&amp;nbsp;&amp;nbsp;&amp;nbsp; SystemCoreClockUpdate();

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set up and initialize all required blocks and
&amp;nbsp;&amp;nbsp;&amp;nbsp; // functions related to the board hardware
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_Init();
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set the LED to the state of "On"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_LED_Set(0, true);

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Enable SysTick Timer
SysTick_Config(SystemCoreClock / TICKRATE_HZ);

volatile int i;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int x = 3;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int y = 100;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int z = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int count = 0;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Simple Division
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i = 0 ; i &amp;lt; LOOP_NUMBER; i ++) {
z = y / x;
if( z == 0) {
count --;
} else {
count++;
}
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
ticks++;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0 ;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:05:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565968#M17213</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: The difference of LPCOpen version to use division ROM</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565969#M17214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by vtw.433e on Thu Mar 17 04:22:22 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Do not try to benchmark unoptimized (aka Debug and -O0) code. The compiler generates very poor code that works, but that is all you can say about it. When benchmarking, use -O2 or -O3 or -Os.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your example the ROM code obviously does not change so you are comparing the compiler generated code that stack the parameters and calls the ROM code. &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:05:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565969#M17214</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: The difference of LPCOpen version to use division ROM</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565970#M17215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gl_belre9 on Thu Mar 17 17:31:23 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;OK, I tried to benchmark in optimized level -O2. I wrote 'volatile' on variable 'x', 'y', 'z' because division procedure is ignored.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As a result, it takes 140us in 2.15 and 111us in 2.19.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have no idea about the time differences.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:05:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565970#M17215</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: The difference of LPCOpen version to use division ROM</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565971#M17216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by vtw.433e on Fri Mar 18 01:56:39 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't understand your code. The main problem is that you are not actually measuring how long it takes to do the division(s). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Change your Systick handler so that it just counts ticks. Don't try to do time calcluations here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Do a large number of divisions (100's or 1000's). This will reduce any timing variations&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Change the numbers used in each division. You are always using the same numbers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Note the number of ticks at the start of your division loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Note the number of ticks at the end of the division and calculate the difference from #4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6. Repeat several times to give an average&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will then give you a meaningful average time to do a division.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:05:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565971#M17216</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: The difference of LPCOpen version to use division ROM</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565972#M17217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gl_belre9 on Mon Mar 21 17:49:09 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry for replying late.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I considered my code to calculate the process time of division ROM again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I checked the value of numerator and denominator at division and Systick handles.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In addition, I won't use interrupt to measure process time directly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It takes some time of division ROM(x24):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.19&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Proc Time:0.108800[ms]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2.15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Proc Time:0.136000[ms]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll show my source code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/*
===============================================================================
 Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : lpc824_divtest.c
 Author&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : gl_belre9
 Version&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :
 Description : main definition
===============================================================================
*/

#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

#include &amp;lt;cr_section_macros.h&amp;gt;

#define TICKRATE_HZ (1000)/// Frequency for SysTick Timer
#define CALC_NUMBER10000
#define LOOP_NUMBER24*CALC_NUMBER

/*****************************************************************************
 * Public types/enumerations/variables
 ****************************************************************************/
static volatile uint32_t ticks;

/*****************************************************************************
 * Private functions
 ****************************************************************************/


/*****************************************************************************
 * Public functions
 ****************************************************************************/
/**
 * @briefHandle interrupt from SysTick timer, measurement of time
 * @returnNothing
 */
/// 1. Change your Systick handler so that it just counts ticks. Don't try to do time calcluations here
void SysTick_Handler(void)
{
ticks++;
}
int main(void) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read clock settings and update SystemCoreClock variable
&amp;nbsp;&amp;nbsp;&amp;nbsp; SystemCoreClockUpdate();

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set up and initialize all required blocks and
&amp;nbsp;&amp;nbsp;&amp;nbsp; // functions related to the board hardware
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_Init();
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set the LED to the state of "On"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_LED_Set(0, true);

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Enable SysTick Timer
SysTick_Config(SystemCoreClock / TICKRATE_HZ);

volatile int i;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int x = 1000;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int y = 100;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int z = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int count = 0;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Simple Division
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; /// 2. Do a large number of divisions (100's or 1000's). This will reduce any timing variations
&amp;nbsp;&amp;nbsp;&amp;nbsp; x = 100;
&amp;nbsp;&amp;nbsp;&amp;nbsp; y = 1000;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// 4. Note the number of ticks at the start of your division loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Simple Division
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int startticks = ticks;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// 6. Repeat several times to give an average
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i = 0 ; i &amp;lt; LOOP_NUMBER; i ++ )
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// 3. Change the numbers used in each division. You are always using the same numbers
&amp;nbsp;&amp;nbsp;&amp;nbsp; z = ++y / ++x;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }


&amp;nbsp;&amp;nbsp;&amp;nbsp; /// 5. Note the number of ticks at the end of the division and calculate the difference from #4
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile int endticks = ticks;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Calculate Process Time
&amp;nbsp;&amp;nbsp;&amp;nbsp; float tickstime = (float)(endticks - startticks) / CALC_NUMBER;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// UART Debug
&amp;nbsp;&amp;nbsp;&amp;nbsp; DEBUGOUT("Proc Time(x%d):%f[ms]\r\n", LOOP_NUMBER/CALC_NUMBER, tickstime);

&amp;nbsp;&amp;nbsp;&amp;nbsp; /// Reset Ticks
&amp;nbsp;&amp;nbsp;&amp;nbsp; ticks = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0 ;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:05:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565972#M17217</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: The difference of LPCOpen version to use division ROM</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565973#M17218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;bump&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Jun 2016 01:05:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/The-difference-of-LPCOpen-version-to-use-division-ROM/m-p/565973#M17218</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-19T01:05:26Z</dc:date>
    </item>
  </channel>
</rss>

