avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Fine Tuning code timings


From: Parthasaradhi Nayani
Subject: Re: [avr-gcc-list] Fine Tuning code timings
Date: Sun, 23 Dec 2007 07:34:10 -0800 (PST)

Hi Alex,
I am not sure why you are capturing the timer1 value, unless you are using the timer for other purposes as well. If not then the easiest method is to:

1. Enable time over flow interrupt.
2. Load the timer withe the required delay for the chosen baud rate. The port pin can be made low here itself as the start bit.
3. When the timer over flow occurs, send the bit and re-load the timer with the earlier value (so the interrupt will occur at the same time for the next bit)

If your baud rate is high (19,200 or more) then it makes sense to use an 8 bit timer as the higher byte of a 16 bit timer may have to be 0xff.

One rough method to get the timing s to pulse the port pin and monitor it on a scope and adjust the timer re-load value. When stop bit is sent, you may stop the timer to prevent unnecessary interrupts eating into processor time. Hope this helps.

Partha



Alex Shepherd <address@hidden> wrote:
Hi Guys,

I'm trying to fine tune some C code timing issues for a software UART
written in AVRGCC.

Essentially when I go to transmit a byte, I capture the value of Timer1, set
the output compare value to the current timer value + the bit period,
activate the Tx pin and then wait for the interrupt handler to output the
rest of the bits in the byte.

The problem I'm having is that the latency between the timer interrupt
firing and the code in the interrupt handler that drives the pin state is
causing some error. I need some way to calculate the amount of time to
reduce the initial timer period by so that the pin state driving logic in
the interrupt handler executes at the right time.

What I would like to try and find out (and why I'm asking on this list):

Is there any way to figure out using compiler tricks/magic how far into a
function or interrupt handler a line of code is so that I can use this
offset value to tune the initial start-bit timer value. The subsequent bit
timings are ok as they are generated using the same code path?

I have experimented using LABELS in the code and trying to do pointer
arithmetic but they don't seem to be accessible outside the function or I
was just doing it wrong.

Merry Christmas

Alex Shepherd



_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Never miss a thing. Make Yahoo your homepage.
reply via email to

[Prev in Thread] Current Thread [Next in Thread]