This time i'm made and adjust timeing for RC5 Decoder (Receiver) Function.
When RA2 pin of Receiver Pic receive firts logic level (0), enter Interrupt function, it call IR_Receiver() function and start RC5 decoder in two Variables (address and comando).
The most big problem is understand right timing for a right decoding !!!!
So i inserted a test trigger signal << LATC7_bit = 1; Delay_us(1); LATC7_bit = 0;>> to synchronize it across the length of the word. (address and command)
Thank you in advance.MY QUESTIONS:
1) At 21.53 on 25.Jan.23 I used 2° Method to understand how set timing, but is impossible or hard find right alignment between the trigger test signal and the rising and falling edges of the protocol. (look Signal analyzer)
How should the trigger peaks be aligned with the protocol looking at the logical analyzer?
Leo.
related topic:
viewtopic.php?f=88&t=79758
https://techdocs.altium.com/display/FPG ... n+Protocol
interrupt()
Code: Select all
// GLOBAL VARIABLES:
bit RC5_Flag;
unsigned short i, Comando, Address;
void interrupt()
{
// INTERRUPT ON RA2
if (PIR0.INTF == 1)
{
IR_Receiver();
PIR0.INTF = 0;
}
}
IR_Receiver(): 2° Method SIGNAL TRIGGER: LATC7_bit = 1; Delay_us(1); LATC7_bit = 0;
Code: Select all
void IR_Receiver(){
RC5_Flag=0;
i=0;
// Check if the received signal is RC5 protocol
if(~PORTA.B2) { Delay_us(889); }
else return;
Delay_us(30); // Delay for Adjust time.
if(PORTA.B2) {Delay_us(889); }
else return;
// while wait last start and toggle signal
if(~PORTA.B2) { while(~PORTA.B2);/*Delay_us(1778);*/ }//1778
else return;
Delay_us(2650); // Delay for Adjust time. 2600(03) Move Signal trigger test on left or right
while (i < 12) {
LATC7_bit = 1; Delay_us(1); LATC7_bit = 0; // SIGNAL TRIGGER TEST
if(i < 6) { // READ ADDRESS BIT was 6
if(PORTA.B2){
Address &= !(1 << (5-i)); //CLEAR BIT 5-i
}
else {
Address |= (1 << (5-i)); //SET BIT 5-i
}
}
else { //READ COMMAND BIT
if(PORTA.B2){
Comando &= !(1 << (11-i)); //CLEAR BIT 11-i
}
else {
Comando |= (1 << (11-i)); //SET BIT 11-i
}
}
Delay_us(1580); // instead 1778 impossible because instructions take some us
i++;
} // end while
RC5_Flag = 1;
} // END FUNCTION