Designing a tracking remote and I am stuck at the programming part! Please Help!

Discussion in 'Programmer's Corner' started by pdevilliers, Apr 10, 2010.

  1. pdevilliers

    Thread Starter New Member

    Apr 10, 2010
    3
    0
    Hello all,
    My group and I are working on designing a tracking remote device for our Junior project at school. The purpose of the device is to help track often misplaced items such as keys, remote control, glasses, cell phones etc.We have done the design of the circuit and all the math as far as what resistor to use and what capacitor needs to be put in the circuit!Our frequency of operation is 433MHz. The circuit consist of 2 subcircuits (main remote and user circuit) that are supposed to be communicating with each other through an antenna system.That's were the issues arise because we can't get the two circuits to communicate and display the desired data on the LED.when power is applied, only thing that happens is the LED turning on that's it. We can't get any data to display on the LED what so ever! I am new to this, so excuse the mistakes i may make within my line of codes or design.
    I will really appreciate if you guys can help me figure out what i'm doing wrong.
    I have included a copy of the code i wrote (in C) that is supposed to display the direction (angle) between the main board and the second board. Also, i'm trying to find a way to calculate and display the distance between the 2 which is more important than finding the angle. ANY HELP? Thanks.
     
  2. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,347
    Hello,

    One post is enough.
    As you are having trouble with the programming I left this.

    Bertus
     
    pdevilliers likes this.
  3. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,347
    Hello,

    I am not able to read the first DOC file.
    You can try to post the pictures local to the AAC using the manage attachments button as you did with the DOC files.
    The code can be placed between code tags in the post itself.

    Bertus
     
  4. pdevilliers

    Thread Starter New Member

    Apr 10, 2010
    3
    0
    ok Thanks Bertus!
    Below is a the code. I couldn't find any other way to attach the pictures without sending them as an attachment. I sent it again.I hope it work this time. Thanks for your help.


    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4.    #include <16F877A.h>   // this is the type of pic we are using.
    5.    
    6.   //#device ICD=TRUE
    7.   #device *=16, ADC=10        // Use 16-bit pointers, use 10-bit ADC
    8.    
    9.    
    10.    
    11.   #use delay (clock=20000000)         // What speed clock do you want today?
    12.    
    13.   // These require use of Set_Tris_x()
    14.   #use fast_io(A)
    15.   // End Preprocessor Directives
    16.    
    17.   // tris - 1 = input, 0 = output
    18.   #define MY_TRISA    0b00001111
    19.   #define MY_TRISB    0b00000000
    20.   #define MY_TRISC    0b00001000
    21.   #define MY_TRISD    0b00000000
    22.    
    23.   #define RSSI_IN     PIN_A1
    24.   #define RSSILED1    PIN_D4
    25.   #define RSSILED2   PIN_D5
    26.   #define RSSILED3   PIN_D6
    27.   #define RSSILED4   PIN_D7
    28.    
    29.   #define RX          PIN_C0
    30.   #define TX          PIN_C1
    31.    
    32.   #define ANTSELOUT   PIN_C2
    33.   #define ANTSELIN    PIN_C3
    34.   #define alpha      3
    35.    
    36.    
    37.    
    38.   /******************************************************************************\
    39.   *                                                                              *
    40.   *                        G L O B A L  V A R I A B L E S                        *
    41.   *                                                                              *
    42.   \******************************************************************************/
    43.   int8 timer2count;
    44.   int1 TxRxmode;   // 1 - receive, 0 - transmit
    45.    
    46.    
    47.   /******************************************************************************\
    48.   *                                                                              *
    49.   *                            M A I N   R O U T I N E                           *
    50.   *                                                                              *
    51.   \******************************************************************************/
    52.   #pragma zero_ram          // Interesting command ....
    53.   void main( void)
    54.   {
    55.    
    56.      // define variables here
    57.      long rssi;
    58.      long antsig,ant1,ant2;
    59.      signed long antdiff;
    60.    
    61.      disable_interrupts(GLOBAL);             // don't interrupt us yet
    62.      delay_ms(500);                          // wait for voltages to stablize
    63.    
    64.      // set I/O ports
    65.      Set_tris_A(MY_TRISA);
    66.      set_tris_B(MY_TRISB);
    67.      set_tris_C(MY_TRISC);
    68.      set_tris_D(MY_TRISD);
    69.      // setup_comparator(A0_A3_NC_NC_OUT_ON_A4);// low battery indicator
    70.      delay_ms(50);
    71.    
    72.      // setup timers/counters/pwm
    73.      setup_ccp1(CCP_PWM);
    74.      setup_timer_2(T2_DIV_BY_16,255,1);         // timer2 at 1.22kHz
    75.      set_pwm1_duty(128);                     // 50% duty cycle at 1.22kHz
    76.      enable_interrupts(INT_TIMER2);
    77.      timer2count = 0;
    78.      TxRxmode = 0;
    79.      enable_interrupts(GLOBAL);                 // start interrupts again
    80.    
    81.      // setup ADC
    82.      setup_port_a(A_ANALOG);                 // A0, A1, A2, A3, A5 analog, reference VDD
    83.      setup_adc(adc_clock_internal);
    84.    
    85.      // set LEDs off
    86.      output_high(RSSILED1);
    87.      output_high(RSSILED2);
    88.      output_high(RSSILED3);
    89.      output_high(RSSILED4);
    90.    
    91.      while (1) {
    92.    
    93.          // output TX/RX signals
    94.          output_bit(RX,TxRxmode);
    95.          output_bit(TX,!TxRxmode);
    96.      
    97.          // tasks which must only be done in Rx mode
    98.          if (TxRxmode) {
    99.    
    100.             // RSSI indicator
    101.             set_adc_channel(1);
    102.             delay_us(10);
    103.             rssi = read_adc();
    104.             if (rssi > 0x0ff) {
    105.                output_low(RSSILED1);
    106.                if (rssi > 0x118) {
    107.                   output_low(RSSILED2);
    108.                   if (rssi > 0x134) {
    109.                      output_low(RSSILED3);
    110.                      if (rssi > 0x157) {
    111.                         output_low(RSSILED4);
    112.                      } else output_high(RSSILED4);
    113.                   } else output_high(RSSILED3);
    114.                } else output_high(RSSILED2);
    115.             } else output_high(RSSILED1);
    116.        
    117.             // Direction finding
    118.             set_adc_channel(2);
    119.             delay_us(10);
    120.             antsig = read_adc();
    121.    
    122.             //average new value with old value
    123.             // antx' = antx*2^-alpha + antsig*(1-2^-alpha)
    124.               if (input(ANTSELIN)) ant1 = (ant1>>alpha) + antsig - (antsig>>alpha);
    125.              else ant2 = (ant2>>alpha) + antsig - (antsig>>alpha);
    126.    
    127.               antdiff = ant1 - ant2;
    128.    
    129.             if (antdiff < -91)
    130.                 output_b(0b10111111);
    131.             else if (antdiff < -55)
    132.                 output_b(0b11011111);
    133.             else if (antdiff < -18)
    134.                 output_b(0b11101111);
    135.             else if (antdiff < 18)
    136.                 output_b(0b11110111);
    137.             else if (antdiff < 55)
    138.                 output_b(0b11111011);
    139.             else if (antdiff < 91)
    140.                 output_b(0b11111101);
    141.             else
    142.                 output_b(0b00000001);
    143.    
    144.          }
    145.      }
    146.   }
    147.   // End Main Routine
    148.    
    149.    
    150.   /******************************************************************************\
    151.   *                                                                              *
    152.   *              I N T E R R U P T   S E R V I C E   R O U T I N E S             *
    153.   *                                                                              *
    154.   \******************************************************************************/
    155.    
    156.   //  Purpose:        Timer2 ISR
    157.   //  Precondition:   timer2 initialized
    158.   //  Postcondition:  tx/rx signal updated
    159.   #INT_TIMER2
    160.   void Timer2ISR(void) {
    161.       timer2count++;
    162.       if (TxRxmode) {
    163.           if (timer2count > 75) {
    164.               timer2count = 0;
    165.               TxRxmode = 0;
    166.           }
    167.       } else {
    168.           if (timer2count > 50) {
    169.               timer2count = 0;
    170.               TxRxmode = 1;
    171.           }
    172.       }
    173.   }
    174.  
    175.  
     
Loading...