[Top][All Lists]

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

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

From: larry barello
Subject: RE: [avr-gcc-list] Fine Tuning code timings
Date: Sun, 23 Dec 2007 07:27:26 -0800

I just adjusted the initial bit time by a few counts to offset the delay.
Subsequent bits were sampled/output through the same code path so I just
continued to add the bit time to the OCxx register for the next interrupt.

In my code I used TIMER3 as CPU/8.  I had to adjust my initial delays by 10
counts (~80 cycles) to eliminate the ~75 clocks of ISR entry code
(determined by inspection of generated assembly).  All subsequent
adjustments to the OC3X register were just the bit time for the next
compare. I for Rx I used IC3 to capture the start time and adjusted that -10
cycled so the first OC3X interrupt would sample at the right time.

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of Alex
Sent: Saturday, December 22, 2007 11:17 PM
To: address@hidden
Subject: [avr-gcc-list] Fine Tuning code timings

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]