EmbDev.net

Forum: ARM programming with GCC/GNU tools run code faster


von Sevc D. (sevc)


Rate this post
useful
not useful
Hi all.
today question is how to run code faster.
I use LPC2142 and core is set to 60MHz,peripheral clock is 15Mhz .
I mesaure any code execution with osciloscope and some time in us.
But can this code run faster????
I try Optimization change (now is 5) and do efect or code do not run.
Is any way how to run code faster????

regards.

PS: I don't need USB

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful
Sevc Dominik wrote:
> today question is how to run code faster.
> I use LPC2142 and core is set to 60MHz,peripheral clock is 15Mhz .
> I mesaure any code execution with osciloscope and some time in us.
There is some overhead in "pin-toggle" esp. when using "legacy" GPIO. On
LPC214x FIO is available which is faster. Try to determine the
time-overhead for GPIO-access first with a simple loop that just toogles
a port-pin and take it into account.

> But can this code run faster????
First of all check your code, maybe you can use another faster
algorithm.

Did you enable the MAM? Flash-access on LPC2000 with activated MAM is
rather fast but RAM is still faster esp. if there is a "cache miss"
during flash-access. You can execute code from RAM esp. time-critical
functions.

> I try Optimization change (now is 5) and do efect or code do not run.
Do you mean -O5? I don't know this level, maybe you mean -Os which
optimizes for size. Did you try -O3 (or 2 or 1)?

Of cause very time critical functions can be written in assembler. But
look into the assembler-code or disassembly first before spending too
much time with assembler-coding. Maybe the compiler-generated code is
already optimized well

von Sevc D. (sevc)


Rate this post
useful
not useful
Hi Martin.
I use source code from your code example for lpc214x
optimization in make file is :
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
#OPT = 0

I don't know if MAM is activated or not, I start my project form
existing example in WinArm .


regards.
PS: I read this post >
http://www.embeddedrelated.com/groups/lpc2000/show/9897.php
But I can set any variable for PLL and other register .

von Sevc D. (sevc)


Rate this post
useful
not useful
Martin.
On this time I can't create function to run from RAM.

regards

von Clifford S. (clifford)


Rate this post
useful
not useful
The available optimisation levels are -00 to -O3, and -Os (no level 5!).

If your optimised code fails to run, it is probably incorrect code.
Errors you might get away with without optimisation can cause failures
with optimisation. For example, crude delay loops will take zero time if
the counter variable is not declared volatile - the optimiser will see
that nothing ever uses the values assigned to the variable and will
optimise the entire loop to nothing!

Check the microcontroller's data sheet, ensure you have enabled caches,
flash acceleration, make sure the clock is correctly configured. I/O
access cycles can be slower than memory access, causing wait states -
check the documentation, some parts may have 'fast' I/O on certain pins,
or an I/O architecture that can be tweaked. If your part uses external
SDRAM, make sure the memory timings are optimised for the specifi parts.
This is general advice, I have not looked at your part specifically.

Clifford

von Sevc D. (sevc)


Rate this post
useful
not useful
Hi Clifford.
I don't know why but some is wrong.
I create code to genrate step to step motor.
I define velocity and aceleration and start . program genrate step and
motor is go on but , can generate only up to 8Khz step . IF set more
then timer stop.
It's creazy AVR is faster then LPC2142???? I know so AVR is RISC and LPC
is ARM7 but AVR if give 14MHz OSCilator then go fast then LPC 60MHz
core.

I calculate this:
step resolution is 0,0025mm
aceleration set 20mm/s
velocity max set 20mm/s
basic time is 1/15000000

V= sqrt(V0*V0+2aceleration*step)
V0 is velocity before, V= velocity in next 0,0025 with 20mm/s
aceleration
and I set timer0 compare match register with this>
t= (V-V0)/aceleration
t is double
then I set : T0MR0 += t/(base time)

All work good but if set highest velocity more then 20mm/s then halt
timer.

Length of interup (code) is 24us , and in 8Khz step it's again every
125us.
I have 100us free time , to do what I vant but no.

I don't have JTAG , can't look in to MCU what happend but use osciloscop
and see wha t is do.

regards

von Clifford S. (clifford)


Rate this post
useful
not useful
I cannot tell what is wrong from the description. You'd have to make the
code available. Are you sure that your integer math is robust? - If your
denominator is greater than your numerator you will end up with zero.

I would not use a timer interrupt to toggle the output, I would use a
PWM timer to drive the output, and merely count the timer overflow
interrupts until the required number of steps (you can also change the
frequency at this point to effect an acceleration profile). This will
give your more precise timing.

BTW ARM is a RISC architecture too!

von Sevc D. (sevc)


Rate this post
useful
not useful
Hi
Clifford Slocombe wrote:
> I would not use a timer interrupt to toggle the output, I would use a
> PWM timer to drive the output, and merely count the timer overflow
> interrupts until the required number of steps (you can also change the
> frequency at this point to effect an acceleration profile). This will
> give your more precise timing.
>
> BTW ARM is a RISC architecture too!

Super, your idea is cool , realy its easy and powerfool.
write more please about it.
give me 1day to get the thing on the brain .

but hmmm. Idon't know how define time for 4axes independent.

send your email adress and I send your my code (full directory).

regards.

von Mhel M. (mhel)


Attached files:

Rate this post
useful
not useful
this is not an answer to your questions, but I thought you might be
interested in the attachment.

von Sevc D. (sevc)


Rate this post
useful
not useful
Mhel Marcelo wrote:
> this is not an answer to your questions, but I thought you might be
> interested in the attachment.

thanks , I use this formulas (not all) in my application.

Clifford I meditate about your idea use PWM to genrate step pulse , but
I think so can't use it.Look, step driver L297 have (not just this)
direction and clock input. clock input time is about 600ns. how to
genrate step pulse with 1us pulses????
Now I use timer0 (match register0-3)to generate interupt every needed
time , if I'm in interupt then with easy loop generate pulse(1-3us)
calculate new time and append to match register .
there is :

static void Timer0Handler (void) __irq
{
  if (T0IR&(1<<MR0I)) // check interupt
  {
  T0IR = (1<<MR0I); // clear interupt
    if (Ax_p_x.Vbefore <Ax_p_x.Vneed) // check velocity
    {
    MoveX(AxR); // velocity is les then need move step to right
                            // calculate velocity and Time ... .
    T0MR0 += Ax_p_x.Timer;
    }
    else // velocity is more or equal then need
    {
    T0MR0 += Ax_p_x.Timer; // Time represent needed velocity
    Ax_Step_X(AxR);  // step motor to right no calculate
    }
  };

  if (T0IR&(1<<MR1I))
  {
  T0IR = (1<<MR1I);
  SetBit(MR1I);
  };

  if (T0IR&(1<<MR2I))
  {
  T0IR = (1<<MR2I);
  SetBit(MR2I);
  };

  if (T0IR&(1<<MR3I))
  {
  T0IR = (1<<MR3I);
  SetBit(MR3I);
  };

    IENABLE;      /* handles nested interrupt */
    Timer0Int = TRUE;
    IDISABLE;
    VICVectAddr = 0;    /* Acknowledge Interrupt */
}

in Ax_Step_X(AxR) function is loop function to generate pulse for step
driver (L297)
I initialize timer0 > if interupt any match register generate only
interupt no reset timer or stop . match register are 32bit (super) and
if owerload then count more from 0.1.2.3... .

Calsulate speed velocity in next step, Ramp define aceleration
deceleration:

double CalSpeed(const double Vbef,const double Acel,const double
SStep,const BYTE Ramp)
{
if (Ramp) return sqrt(Vbef*Vbef+2*Acel*SStep);
else if ((Vbef*Vbef-2*Acel*SStep)>0) return
sqrt(Vbef*Vbef-2*Acel*SStep);else return 0;
}
calculate time between two step:
double Caltime(const double Vbef,const double Vact,const double Acel)
{
return fabs(Vact-Vbef)/Acel;
}

funtion to calculate Tick is base time of timer 1/15000000:
void MoveX(const BYTE Dir)
{
Ax_Step_X(Dir);
Ax_p_x.Vactual = CalSpeed(Ax_p_x.Vbefore,Ax_p_x.Aramp,Ax_p_x.Sstep,1);
Ax_p_x.Time = Caltime(Ax_p_x.Vbefore,Ax_p_x.Vactual,Ax_p_x.Aramp);
Ax_p_x.Timer = Ax_p_x.Time/Ax_p_x.Tick;
Ax_p_x.Vbefore = Ax_p_x.Vactual;
Ax_p_x.Terror += (Ax_p_x.Time/Ax_p_x.Tick)-Ax_p_x.Timer;
if (Ax_p_x.Terror > 1) {Ax_p_x.Timer++;Ax_p_x.Terror-=1;};
T0MR0 += Ax_p_x.Timer;
}


Clifford write more about your idea.
I'm start with LPC just some time ago.

regards

von Clifford S. (clifford)


Rate this post
useful
not useful
Sevc Dominik wrote:
> Clifford I meditate about your idea use PWM to genrate step pulse , but
> I think so can't use it.Look, step driver L297 have (not just this)
> direction and clock input. clock input time is about 600ns. how to
> genrate step pulse with 1us pulses????

You seem to be making this harder than it need be by misunderstanding
the requirements or the PWM. I took a quick look at the L297 and it
seems that the minimum step pulse width is 1usec, it may be longer.
The step occurs on the falling edge, it is only the timing of that edge
that is critical. The maximum frequency is 25KHz. I believe that the PWM
timer can easily generate such timing.

I have not got time right now, but I will try and take a look at your
code and the LPC2142 and L297 data sheets later.

Clifford

von Sevc D. (sevc)


Rate this post
useful
not useful
Hi all who interest about my post.
I found problem.
my code create from timer0 > 4 independent timers.
every interupt from any match register I append new value to match
register and there is problem.
element of my CODE:
 if (T0IR&(1<<MR0I)) //check interupt
  {
  T0IR = (1<<MR0I); // clear interupt
    T0MR0 += Ax_p_x.Timer;   <--- here is problem
    }
  };
I append new value, but T0TC still go on , and in some time it all
crash.
solution is easy end work goog :

 T0MR0 = T0TC + Ax_p_x.Timer;

I can generate more then 80Khz step pulse.but now I have diferent
problem with aceleration and decelarion ... another forum .

regards

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.