Pages

Wednesday, November 30, 2011

Batteryless Infrared Remote

To use the batteryless TV remote is as simple as 1-2-3. Just shake the remote a few times and press the desired key!

Circuit Inside the Remote
TV Remote
         The main section of the microcontroller executes a tight loop waiting for a key to be pressed. Until a key press occurs, the microcontroller goes into sleep mode to conserve power. A key press causes a pin change interrupt, which wakes up the controller. The microcontroller executes a key scan subroutine to identify the key. In the next step, the transmit subroutine is executed to transmit the key code as per the selected protocol. Once the key code is transmitted, the microcontroller goes into sleep mode until a key is pressed again.

ISR(PCINT0_vect)
//Interrupt handler for pin change
{
MCUCR &= ~((1<<SE) | (1<<SM1));
//Disable sleep (power down) mode
PCMSK &= ~((1<<PCINT4) | (1<<PCINT3) |
(1<<PCINT2));
//Pin change interrupt is disabled on
//all pins
New_Key_Pressed = 1;
}

         The key code that is to be transmitted modulates a carrier frequency(Fc). Fc depends upon the selected remote protocol & which is operating at a clock frequency of 1 MHz, uses the internal eight-bit timer in clear timer on compare (CTC) mode to generate Fc. The required  Fc is generated by toggling the output bit. So to get 36-KHz Fc, the interrupt rate has to be set to 72 KHz.

ISR(TIMER0_COMPA_vect)
//Interrupt handler for compare
//match
{
PORTB ^= (1<<IR_LED);
//Toggle the PIN to generate PWM
}

       For the RC5 protocol, the timer is initialized as follows:
{
TCCR0A |= (1<<WGM01);
//Clear timer on compare mode
//enabled
TCCR0B |= (1<<CS00);  
//Clock frequency 8 MHz(prescalar =
//1), CTC mode
OCR0A = 14;    
//Approx. 72KHz Interrupt rate
TIMSK |= (1<<OCIE0A);
//Enable CTC interrupt
sei();
}

          Any key code transmission for a particular protocol involves turning off and on the IR LED at the rate of the carrier frequency modulated with the bits of the code (logic “0” or logic “1”), as shown in the illustration below. The following code listing shows the actual bit transmission for RC5 protocol:

void transmit_RC5(void)
{
while(Tx == 1)
{
if(Tx_bit_RC5[i] == 0)
{
DDRB |= (1<<IR_LED);
//Enable carrier
_delay_us(RC5_ON_PERIOD_ZERO);
DDRB &= ~(1<<IR_LED);  
//Disable carrier
_delay_us(RC5_OFF_PERIOD_ZERO);
}
if(Tx_bit_RC5[i] == 1)
{
DDRB &= ~(1<<IR_LED);    
//Disable carrier
_delay_us(RC5_OFF_PERIOD_ONE);
DDRB |= (1<<IR_LED);
//Enable carrier
_delay_us(RC5_ON_PERIOD_ONE);
}
i++;
if(i == 14)
{
i=0;
Tx = 0;
}
}
PCMSK |= ((1<<PCINT4) | (1<<PCINT3) |
(1<<PCINT2));
}

Note:All logic are given here... If you have any doubt than ask...

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...