[SOLVED] RC5 and VUSB

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
mschumann
Posts: 14
Joined: Thu Jan 29, 2009 8:01 pm

[SOLVED] RC5 and VUSB

Post by mschumann » Thu Jun 04, 2009 6:02 pm

Has anyone managed to get an rc5 (infrared remote control) decoding and vusb running both on a chip with 16 MHz or less?

The solution to the Problem was to enable interrupt within the polling timer so that it doesnt block the USB interrupts. I nearly went crazy because the USB stack crashed when I used a timer at F_CPU/1024 with that code without the highligthed sei(); With the sei(); everything runs like clockwork since the rc5 decoding is not too time critical.

Code: Select all

ISR(TIMER0_OVF_vect)
{
   // triggert FCPU/1024, 64µs
   
   TIMSK &= ~(1 << TOIE0);
   TCNT0 = -1;
       
   [b]sei();[/b]
   
   uint16_t tmp = rc5_tmp;
   
   if (++rc5_time > PULSE_MAX) {
      if (!(tmp & 0x4000) && tmp & 0x2000) rc5_data = tmp;
      tmp = 0;
    }            
   
   if ((rc5_bit ^ PIND) & (1 << PIND3)) {      
      rc5_bit = ~rc5_bit;   

      if (rc5_time < PULSE_MIN) tmp = 0;
      if (!tmp || rc5_time > PULSE_1_2) {   
         if (!(tmp & 0x4000)) tmp <<= 1;
         if (!(rc5_bit & 1<<PIND3))   tmp |= 1;
          rc5_time = 0;   
      }
      
   }
   rc5_tmp = tmp;
   
   TIMSK |= (1 << TOIE0);
}
)

Post Reply