Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How would i start with interrupt driven IR RC5 using AVR ?

Status
Not open for further replies.

Terminator Electricity

Member level 5
Joined
Feb 2, 2006
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,973
avr interrupt driven ir decode

Hi ,,,
I have successfully made a c code for reception of IR RC5 code using ATmega16 with the help of the avr application notes

BUT i dont know how to write or how to start to write an interrupt driven RC5 IR recever

I am using codevision ,, plz could anyone help me to how to start ? cuz i was totally lost here ,, cuz no reference found on that subject

Thanks
 

input capture in avr

This is my code for IR RC5 reciever using an ATmega16

Code:

Code:
/*****************************************************



Chip type           : ATmega16L
Program type        : Application
Clock frequency     : 7.372800 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

 
void setup_AVR();
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
#include <mega16.h> 
#include <stdio.h>
#include <io.h>
unsigned char temp=0;
unsigned char command[10]={0};
unsigned char system[10]={0};
unsigned char timerH=0;
unsigned char timerL=0;
int bitcnt;                     //number of bits waiting to be recieved
unsigned char ref1;                     // 3/4 bit_time
unsigned char ref2;                     // 5/4 bit_time     
int i=6;   
int j=5;
int k;

interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
timerL++;                              //increments every 255* 1/7.372800 seconds
temp++;                             
if(temp==255) {temp=0;timerH++;} //increments every 255*255* 1/7.372800  seconds
}

void main(void)
{
setup_AVR();



#asm("sei")

while (1)
      { 

initialize:   temp=0;
      timerH=0;   
           
detect1:   timerL=0; 
             
detect2:   if(timerH>15)   //If no start bit detected within 132ms
                goto fault;
                               
      if(timerL>102)   //If line high for more than 3.5ms
      goto start1;   //then wait for the first start bit

      if(!CHECKBIT(PIND,2))           //If line is :
           goto detect1;   // PIND=0  low  - jump to detect1 and reset the timer
      else goto detect2;   // PIND=1  high - jump to detect2 and recheck for 3.5 ms of ideal high

start1:      while(CHECKBIT(PIND,2))//keep checking for the first start bit
                {
                if(timerH>15)   //If no start bit detected within 132ms
                 goto fault;   //then exit    printf("5");
                }

      timerL=0;   //Measure halflength of start bit     
      
start2:      while(!CHECKBIT(PIND,2))//Measure halflength of start bit (low level length)
                {
                if(timerL>26)   //If startbit longer than 1.1ms,
      goto fault ;   //   exit
                }
                //timerL = 1/2 bit time
      ref1 =3.0*timerL/2.0;        //ref1 = 3/4 bit time
      ref2 =5.0*ref1/3.0;        //ref2 = 5/4 bit time
                timerL=0;
               
start3:      while(CHECKBIT(PIND,2))//check if second starting bit is recieved
                {
                if(timerL>ref1)   //If rising edge is too long
      goto fault;   //exit
                }
               
      bitcnt  =12;   //Receive 12 bits
                j=5;            //For command
                i=5;            //For system
sample:      timerL  =0 ;
                while(timerL<ref1); // wait untill first 1/4 of next bit   
               
                while(bitcnt>0)
               
      {
      //Now recieving first 7 bits including the toggle bit
      while(bitcnt>6)
           { if (PIND.2==0){                             //The bit recieved is 0
                              system[i]=0;               //store the bit in system
                              i-- ;bitcnt--;             //prepare for the next bit
                              while(!CHECKBIT(PIND,2))   //wait untill the next edge
                                {
                                if(timerL>ref2) goto fault;
                                }
                              goto sample;               //wait for the next bit
                           }
                     
                       else          {                             //The bit recieved is 1
                                        system[i]=1;               //store the bit in system
                                        i-- ;bitcnt--;             //prepare for the next bit
                                        while(CHECKBIT(PIND,2))    //wait untill the next edge
                                          {
                                          if(timerL>ref2) goto fault;
                                          }
                                        goto sample;               //wait for the next bit
                                     }
                     }                 
                //Now recieving last 6 bits
                                                                                     
                if(PIND.2==0){                                     //The bit recieved is 0
                                command[j]=0;                      //store the bit in command
                                j-- ;bitcnt--;                     //prepare for the next bit
                                while(!CHECKBIT(PIND,2))           //wait untill the next edge
                                  {
                                  if(timerL>ref2) goto fault;
                                  }
                                goto sample;                       //wait for the next bit
                              }                                 
               
                else         {                                      //The bit recieved is 1
                                command[j]=1;                       //store the bit in command
                                j-- ;bitcnt--;                      //prepare for the next bit
                                while(CHECKBIT(PIND,2))             //wait untill the next edge
                                  {
                                  if(timerL>ref2) goto fault;
                                  }
                                goto sample;                        //wait for the next bit
                             }
               }       
               


   
printf("aa");
for(k=5;k>=0;k--)
printf("%d",command[k]);
printf("bb");
for(k=5;k>=0;k--)
printf("%d",system[k]);

fault:      goto initialize;

      };
}
void setup_AVR()
{
PORTD=0x00;
DDRD=0x00;
TCCR0=0x01;
TCNT0=0x00;
OCR0=0x00;
TIMSK=0x01;
ACSR=0x80;
SFIOR=0x00;
}
how do i change it to be interrupt driven ? plz help
 

exit interrupt avr

**broken link removed**

Sony Protocal
 

avr ir capture and

Two way can do.
First :
Use input capture pin to detect the IR signal, I'm not sure AVR already provided this feature or not, try to check on data sheet.

Second :
Use one external interrupt plus one timer, start the timer counting when a IR signal come to the external interrupt pin.
 

interrupt driven rc5

i think input capture is a very fine method,,, got any resources plz?
 

rc5.h+avr

kittythai said:
http://www.wara.com/modules.php?name=News&file=article&sid=610

Sony Protocal

thanks


BUT this is an indian web site POST the english one .thanks
 

rc5 by avr

Terminator Electricity said:
i think input capture is a very fine method,,, got any resources plz?
Checked on 16bit Timer, already provided the input capture function via ICP1 pin, try to use this to decode IR signal.:D
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top