EmbeddedRelated.com
Forums

lpc2148 with uart is increasing delay in loop.. please help

Started by ani_rec_2001 August 24, 2009
Dear all,
i am using lpc2148 UART0 in interrupt mode (code i got from this group only). along with this i am using timer interrupt to capture some pulses. problem is my loop time is getting delayed( while(1) loop)
. if i will remove printf statement then my device is working fast and if i will use printf it is adding delay in overall loop.
how to use uart without delay. please help me
Thanks
anil

An Engineer's Guide to the LPC2100 Series

Hi,

It's sure that uart takes time depending on your speed. So you need to push
what you are going to print in a long-enough buffer. Then you can print them
later when you have time. Also note that you have 16-byte FIFO on your uart
that help you about this.

Best Regards,
Chutiman Yongprapat


--- In l..., "ani_rec_2001" wrote:
>
> Dear all,
> i am using lpc2148 UART0 in interrupt mode (code i got from this group only). along with this i am using timer interrupt to capture some pulses. problem is my loop time is getting delayed( while(1) loop)
> . if i will remove printf statement then my device is working fast and if i will use printf it is adding delay in overall loop.
> how to use uart without delay. please help me
> Thanks
> anil
>

Get rid of printf and all of the baggage it brings along. You can easily create string functions to do the conversions.

Try "The C Programming Language" book by Kernighan & Ritchie.

You really want an output queue of some large size to feed the interrupt driven UART transmit handler. Since you are dealing with strings, it is probably best to implement the queue as an array of strings of some fixed maximum length. What you don't want to do is implement it as some kind of heap storage.

At some point you may decide that a real-time operating system will help schedule the tasks. FreeRTOS comes to mind.

Reconsider how your while(1) loop works. Maybe you should break the loop into parts. The first part does one conversion, the second part does another conversion, the third part updates the queue, etc. These are really just case statements within the while(1) loop. Each pass will do another part of the task before looking for that pulse data.

Richard
--- In l..., "ani_rec_2001" wrote:
>
> Dear all,
> i am using lpc2148 UART0 in interrupt mode (code i got from this group only). along with this i am using timer interrupt to capture some pulses. problem is my loop time is getting delayed( while(1) loop)
> . if i will remove printf statement then my device is working fast and if i will use printf it is adding delay in overall loop.
> how to use uart without delay. please help me
> Thanks
> anil
>

Does your printf send its output to a serial port ?
If so, whats the baud rate ?
If no, where is it going ?

Please give enough information to help.

don
--- In l..., "donhamilton2002" wrote:
>
> --- In l..., "ani_rec_2001" wrote:
> >
> > Dear all,
> > i am using lpc2148 UART0 in interrupt mode (code i got from this group only). along with this i am using timer interrupt to capture some pulses. problem is my loop time is getting delayed( while(1) loop)
> > . if i will remove printf statement then my device is working fast and if i will use printf it is adding delay in overall loop.
> > how to use uart without delay. please help me
> > Thanks
> > anil
> > Does your printf send its output to a serial port ?
> If so, whats the baud rate ?
> If no, where is it going ?
>
> Please give enough information to help.
>
> don
>
Dear don
yes i am sending my output to serial port with the baud rate of 9600
--- In l..., "ani_rec_2001" wrote:
>
> --- In l..., "donhamilton2002" wrote:
> >
> > --- In l..., "ani_rec_2001" wrote:
> > >
> > > Dear all,
> > > i am using lpc2148 UART0 in interrupt mode (code i got from this group only). along with this i am using timer interrupt to capture some pulses. problem is my loop time is getting delayed( while(1) loop)
> > > . if i will remove printf statement then my device is working fast and if i will use printf it is adding delay in overall loop.
> > > how to use uart without delay. please help me
> > > Thanks
> > > anil
> > >
> >
> > Does your printf send its output to a serial port ?
> > If so, whats the baud rate ?
> > If no, where is it going ?
> >
> > Please give enough information to help.
> >
> > don
> >
> Dear don
> yes i am sending my output to serial port with the baud rate of 9600
>

This is going to need some analysis.

How many characters are you sending out the serial port ??

9600 baud is about 1 millsecond per char sent.

So your delay should be #char x 1 mSec.

Do you know what a circular buffer is ??

Have you used the serial port interrupt ?

How often do you need to send chars out the serial port (prinrf) ?

don

PS: What are your development tools ?
--- In l..., "donhamilton2002" wrote:
>
> --- In l..., "ani_rec_2001" wrote:
> >
> > --- In l..., "donhamilton2002" wrote:
> > >
> > > --- In l..., "ani_rec_2001" wrote:
> > > >
> > > > Dear all,
> > > > i am using lpc2148 UART0 in interrupt mode (code i got from this group only). along with this i am using timer interrupt to capture some pulses. problem is my loop time is getting delayed( while(1) loop)
> > > > . if i will remove printf statement then my device is working fast and if i will use printf it is adding delay in overall loop.
> > > > how to use uart without delay. please help me
> > > > Thanks
> > > > anil
> > > >
> > >
> > > Does your printf send its output to a serial port ?
> > > If so, whats the baud rate ?
> > > If no, where is it going ?
> > >
> > > Please give enough information to help.
> > >
> > > don
> > >
> > Dear don
> > yes i am sending my output to serial port with the baud rate of 9600
> > This is going to need some analysis.
>
> How many characters are you sending out the serial port ??
>
> 9600 baud is about 1 millsecond per char sent.
>
> So your delay should be #char x 1 mSec.
>
> Do you know what a circular buffer is ??
>
> Have you used the serial port interrupt ?
>
> How often do you need to send chars out the serial port (prinrf) ?
>
> don
>
> PS: What are your development tools ?
>
Dear Don,
yes i have to send arround 100 Bytes periodically. how to send periodically that i have to work out frankly.
my development tool is keil compiler only.
i am using it in iterrupt mode only.
Thanks n Regards
Anil
> >
> Dear Don,
> yes i have to send arround 100 Bytes periodically. how to send periodically that i have to work out frankly.
> my development tool is keil compiler only.
> i am using it in iterrupt mode only.
> Thanks n Regards
> Anil
>

?? If you are only doing anything useful in interrupts, why does it matter if your 'while(1)' loop is delayed?

If you are using interrupts for all I/O and you need to 'do more than one thing at a time', then, like rtstofer said, you should get an RTOS to make it easier to throw around data, queue buffers to UARTs etc. sprintffing stuff to a string buffer and queueing the buffer to a UART interrupt handler is much quicker than waiting for the UART to issue every character from a printf().

Rgds,
Martin
I had a similar problem and I solved it by using a circular buffer with the
THRE interrupt for the UART. A lot of time is wasted while looping to wait
for the transmit register to be empty.

while(!((UART0_LSR) & U0LSR_TRANSMIT_HOLDING_REG_EMPTY)){}

So, I suggest copy transmit data to a buffer( I use a circular buffer of
size 2**n for easy counting) and then use interrupt to pick up data from
the buffer and put it in the UART.

-Ananda

On Thu, Sep 3, 2009 at 1:36 AM, mjames_doveridge <
m...@googlemail.com> wrote:

> > >
> > Dear Don,
> > yes i have to send arround 100 Bytes periodically. how to send
> periodically that i have to work out frankly.
> > my development tool is keil compiler only.
> > i am using it in iterrupt mode only.
> > Thanks n Regards
> > Anil
> > ?? If you are only doing anything useful in interrupts, why does it matter
> if your 'while(1)' loop is delayed?
>
> If you are using interrupts for all I/O and you need to 'do more than one
> thing at a time', then, like rtstofer said, you should get an RTOS to make
> it easier to throw around data, queue buffers to UARTs etc. sprintffing
> stuff to a string buffer and queueing the buffer to a UART interrupt handler
> is much quicker than waiting for the UART to issue every character from a
> printf().
>
> Rgds,
> Martin
>
>
>