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.

Timing question on RX code

denny9167

Newbie level 5
Joined
Apr 23, 2022
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
65
I've been doing some work on an RF project, and Im using PIC to PIC communication, I already have the TX code, but Im concerned about the timing on the RX code. Im using a bitcount method(count marks,ignore spaces), and wanted to see if my timing was correct on detecting preamble. I believe my TMR0 settings are correct. I need to read a 300us preamble, and I have a frequency window of 2400 to 3600Hz. Any help is appreciated, Im new to this forum, so please excuse any ignorance on my part regarding any violation of forum standards. below is a link to the RX code.

[moderator action: removed link to external file server]
 
Last edited by a moderator:

denny9167

Newbie level 5
Joined
Apr 23, 2022
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
65

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*  File: RX_ASKv2.0.c
 *  Author: Denny
 *  Internal oscillator used @ 8Mhz
 */
 
 
#include <xc.h>
#include <stdint.h>
 
 
// PIC12F615 Configuration Bit Settings
 
 
// CONFIG
#pragma config FOSC = INTOSCIO  
#pragma config WDTE = OFF       
#pragma config PWRTE = OFF      
#pragma config MCLRE = OFF       
#pragma config CP = OFF         
#pragma config IOSCFS = 8MHZ
#pragma config BOREN = ON     
 
#define _XTAL_FREQ 8000000
 
#define LED        GPIObits.GPIO5        // RF receive status indicator 
 
#define RF_IN   GPIObits.GPIO3        // RF DATA PORT 
 
//=============================================================================
//   RECEIVE_RF_PACKET
//=============================================================================
 
unsigned int overflow=0;
 
 
void receive_rf_packet(void)
{
  //-------------------------------------------------------
  // This function receives an RF packet of bytes in the pulse period
  // encoded format. The packet must have 2 valid contiguous bytes
  // global variables; address_byte and command_byte hold the byte result.
  //-------------------------------------------------------
  
  unsigned int pulse_time;
  unsigned char bitcount;
  unsigned char address_byte;
  unsigned char command_byte;
  
  while(1){   // loop until it has received 2 contiguous RF bytes
  address_byte=0;
  command_byte=0;
  
  
    //-----------------------------------------
    // wait for a start pulse >300us
    
      while(RF_IN);    // wait for input / edge
      overflow =0;
      TMR0 = 0;                    // and ready to record next period
      while(!RF_IN);     // wait for input \ edge
      pulse_time=(overflow >>8) +TMR0;
      if ((pulse_time > 2400) && (pulse_time < 3600)){  // grab the pulse time(frequency limit)
      
           
    //-----------------------------------------
    // now we had a start pulse, record 8 address bits
    
    for(bitcount = 0 ; bitcount < 8; bitcount++){    // 8 address bits
    
      while(RF_IN);    // wait for input / edge
      overflow =0;
      TMR0 = 0;
      while(!RF_IN);     // wait for input \ edge
      pulse_time = (overflow >>8) + TMR0;           // grab the pulse time!
      address_byte <<= 1;                              // shift
      address_byte &= 0x7F;                            // top bit zero
      if (pulse_time> 0x40){
      address_byte ^= 0x80;                        // top bit 1
                }
           }
 
    //-----------------------------------------
    // now record 8 command bits
    
    for(bitcount = 0 ; bitcount < 8; bitcount++){    // 8 command bits
    
      while(RF_IN);    // wait for input / edge
      overflow =0;
      TMR0 = 0;
      while(!RF_IN);     // wait for input \ edge
      pulse_time = (overflow >>8) + TMR0;           // grab the pulse time!
      command_byte<<= 1;                              // shift
      command_byte &= 0x7F;                            // top bit zero
      if (pulse_time> 0x40){
      command_byte ^= 0x80;                        // top bit 1
                }
           }
 
      if(address_byte == 0xF8){
      if(command_byte == 0xFA){
      
              LED = ~LED;
              __delay_ms(100);
         
      }
      }
      }
  }
}
 
    
//-----------------------------------------------------------------------------
// Timer0 interrupt
 
void __interrupt() ISR(void){
 
    if (INTCONbits.T0IF) {
        overflow++;                    // increment overflow
        INTCONbits.T0IF = 0;                 // Clear Timer0 overflow interrupt flag
    }
}
 
 
/* THE main source code starts here*/
void main()
{
    CMCON0=0x7;                // disable the comparator 
    ANSEL =0x00;
    TRISIO3=1;               // Only GP3 is set to input rest are out
    TRISIO5=0;
    OPTION_REG=0x81;        //pull-ups disabled, 1:4 pre-scaler = 500kHz
    INTCONbits.GIE = 1;               // Global interrupt enable
    INTCONbits.T0IE =1;               // Timer0 interrupt enable
    GPIO =0;
    
    receive_rf_packet();
}


--- Updated ---

I've been doing some work on an RF project, and Im using PIC to PIC communication, I already have the TX code, but Im concerned about the timing on the RX code. Im using a bitcount method(count marks,ignore spaces), and wanted to see if my timing was correct on detecting preamble. I believe my TMR0 settings are correct. I need to read a 300us preamble, and I have a frequency window of 2400 to 3600Hz. Any help is appreciated, Im new to this forum, so please excuse any ignorance on my part regarding any violation of forum standards. below is a link to the RX code.

[moderator action: removed link to external file server]
 
Last edited:

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top