lpcware

The difference of LPCOpen version to use division ROM

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 18, 2016 by lpcware
Content originally posted in LPCWare by gl_belre9 on Thu Mar 17 00:36:20 MST 2016
Hello,
I found it takes process time of division ROM in LPCOpen version 2.15 more than in 2.19, using LPCXpresso824-MAX board.
I'd like to know the reason of this difference.

I verified the process time by using SysTick timer, showing source code below.
I compiled this code in Optimization Level -O0.

It takes 115us in LPCOpen 2.19, and 144us in 2.15.

Thank you.


/*
===============================================================================
Name        : lpc824_divtest.c
Author      : gl_belre9
Version     :
Description : main definition
===============================================================================
*/

#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

#include <cr_section_macros.h>

#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) {
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();

    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);

    /// Enable SysTick Timer
SysTick_Config(SystemCoreClock / TICKRATE_HZ);

volatile int i;
    volatile int x = 3;
    volatile int y = 100;
    volatile int z = 0;
    volatile int count = 0;

    /// Simple Division
    while(1) {
    for(i = 0 ; i < LOOP_NUMBER; i ++) {
z = y / x;
if( z == 0) {
count --;
} else {
count++;
}
    }
ticks++;
    }
    return 0 ;
}



Outcomes