[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Fine Tuning code timings
From: |
Paulo Marques |
Subject: |
Re: [avr-gcc-list] Fine Tuning code timings |
Date: |
Wed, 02 Jan 2008 12:56:52 +0000 |
User-agent: |
Thunderbird 1.5.0.12 (X11/20070509) |
Jan Menzel wrote:
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.
Agreed.
IMHO, the simplest way to do this is to just forget about start / data /
stop bits, and just use a 16 bits shift register and shift count.
Something along these lines (_not_ actual code):
volatile unsigned int shift_register;
volatile unsigned char shift_count;
ISR()
{
if (!shift_count)
return;
output_bit(shift_register & 1);
shift_register >>= 1;
shift_count--;
}
void send_byte(unsigned char data)
{
while (shift_count)
;
shift_register = (data << 1) | 0x200;
shift_count = 10;
}
Then, just setup the timer to fire the interrupt at the correct baud
rate. If you're using a 8 bit timer with no way to set the frequency,
just add a constant value to the timer counter inside the interrupt
function to fire the overflow with a fixed period.
Since it is the same code path that outputs all bits, the baud rate is
guaranteed to be constant, unless there are other sources of interrupts
to add latencies...
I hope this helps,
--
Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com
"You're just jealous because the voices only talk to me."
- Re: [avr-gcc-list] Fine Tuning code timings,
Paulo Marques <=