[Top][All Lists]

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

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

From: Jan Menzel
Subject: Re: [avr-gcc-list] Fine Tuning code timings
Date: Fri, 28 Dec 2007 18:00:57 +0100
User-agent: Thunderbird (Windows/20071031)

Hi Alex!
I'd suggest to take larrys approach and generate the start bit from within the ISR. For precise timings you might add the bit time to the current OCR value (insight the ISR). Using this schema you can have an arbitrary (but constant) phase difference between the interrupt and the time of changing the tx-pin. To start a transmission I'd just set the OCR to TIMER + x where x shall be set such that the ISR is called as fast as you like the transmission to start.

        Kind regards

Alex Shepherd 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

reply via email to

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