Are Timers used?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
MaxWax

Are Timers used?

Post by MaxWax » Sat Sep 06, 2008 2:13 am

Dear all,

I try to toggle a PIN on a ATMega8@12MHz every 100ns using the HID-data template.

The code works fine until I enable Timer1.
Is the timer used otherwise?

The following code was added:


Code: Select all

void TimerInit(void){

   TCNT1=0x0000;//set timer counter initial value
   OCR1A=0x04B0; //Set timer output compare registerA to 1200 -> 100ns
   
   TCCR1B |= (1<<CS10 | 1<<WGM12);  // No prescaling -> 12MHz; Enable CTC
   TIMSK  |= (1<<OCIE1A);// Enable Compare Match ISR

}

ISR(TIMER1_CAPT_vect){
   PORTC ^= _BV(PIN5);
}

Grendel
Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA
Contact:

Post by Grendel » Sat Sep 06, 2008 2:38 am

You are over running the CPU. 1/100ns = 10MHz, ie. 1.2 clock cycles per IRQ... Once the time is started the CPU is locked into the ISR routine.

Grendl

Post by Grendl » Sat Sep 06, 2008 11:50 am

Dear Grendl,

you are absolutely right! There is a mistake in my comments.

The plan is to establish a 10400 baud serial communication (car OBD2). This will result in sending one bit every 96µs. At 12MHz I would need an interrupt every 1154 cycles.

I already thought of using the UART to shift this data but I did not see a way to disable the stop-bit to get a pure 8 bit communication (the second thing was I did not find the settings for 10400 baud).
A timer interrupt every 96µs is the only idea I had trying to establish this serial communication.

Thank you, I appreciate every hint!
MaxWax

henni
Posts: 16
Joined: Mon Sep 08, 2008 4:17 pm

Post by henni » Tue Sep 09, 2008 8:42 am

> The plan is to establish a 10400 baud serial communication (car OBD2).
> This will result in sending one bit every 96µs.
> ...
> UART ... I did not see a way to disable the stop-bit...

You need a stop bit, otherwise, the start bit makes no sense!
The UART receiver is awaiting a 1->0 transition to detect a start bit.
Maybe, you can live with 7-bit transmission and one stop bit.
Or you should use the USI/SPI instead (no start bit in this case too).

Note that AVRUSB and fast+fluent (non-interrupting) serial communication cannot be implemented, as AVRUSB may disable interrupts for up to 75 µs (1 bulk packet with 8 data bytes) or even more for contiguous SETUP+DATA transmissions.

If you really need less interruptions, consider to use two Atmel processors (as multi-CPU microcontrollers don't exist yet:-) or a dedicated USB controller chip (e.g. FT245).

Post Reply