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

Thread Starter

pdevilliers

Joined Apr 10, 2010
3
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.
 

Attachments

bertus

Joined Apr 5, 2008
22,266
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
 

Thread Starter

pdevilliers

Joined Apr 10, 2010
3
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.


Rich (BB code):
   #include <16F877A.h>   // this is the type of pic we are using.
   
  //#device ICD=TRUE
  #device *=16, ADC=10        // Use 16-bit pointers, use 10-bit ADC
   
   
   
  #use delay (clock=20000000)         // What speed clock do you want today?
   
  // These require use of Set_Tris_x()
  #use fast_io(A)
  // End Preprocessor Directives
   
  // tris - 1 = input, 0 = output
  #define MY_TRISA    0b00001111
  #define MY_TRISB    0b00000000
  #define MY_TRISC    0b00001000
  #define MY_TRISD    0b00000000
   
  #define RSSI_IN     PIN_A1
  #define RSSILED1    PIN_D4
  #define RSSILED2   PIN_D5
  #define RSSILED3   PIN_D6
  #define RSSILED4   PIN_D7
   
  #define RX          PIN_C0
  #define TX          PIN_C1
   
  #define ANTSELOUT   PIN_C2
  #define ANTSELIN    PIN_C3
  #define alpha      3
   
   
   
  /******************************************************************************\
  *                                                                              *
  *                        G L O B A L  V A R I A B L E S                        *
  *                                                                              *
  \******************************************************************************/
  int8 timer2count;
  int1 TxRxmode;   // 1 - receive, 0 - transmit
   
   
  /******************************************************************************\
  *                                                                              *
  *                            M A I N   R O U T I N E                           *
  *                                                                              *
  \******************************************************************************/
  #pragma zero_ram          // Interesting command ....
  void main( void)
  {
   
     // define variables here
     long rssi;
     long antsig,ant1,ant2;
     signed long antdiff;
   
     disable_interrupts(GLOBAL);             // don't interrupt us yet
     delay_ms(500);                          // wait for voltages to stablize
   
     // set I/O ports
     Set_tris_A(MY_TRISA);
     set_tris_B(MY_TRISB);
     set_tris_C(MY_TRISC);
     set_tris_D(MY_TRISD);
     // setup_comparator(A0_A3_NC_NC_OUT_ON_A4);// low battery indicator
     delay_ms(50);
   
     // setup timers/counters/pwm
     setup_ccp1(CCP_PWM);
     setup_timer_2(T2_DIV_BY_16,255,1);         // timer2 at 1.22kHz
     set_pwm1_duty(128);                     // 50% duty cycle at 1.22kHz
     enable_interrupts(INT_TIMER2);
     timer2count = 0;
     TxRxmode = 0;
     enable_interrupts(GLOBAL);                 // start interrupts again
   
     // setup ADC
     setup_port_a(A_ANALOG);                 // A0, A1, A2, A3, A5 analog, reference VDD
     setup_adc(adc_clock_internal);
   
     // set LEDs off
     output_high(RSSILED1);
     output_high(RSSILED2);
     output_high(RSSILED3);
     output_high(RSSILED4);
   
     while (1) {
   
         // output TX/RX signals
         output_bit(RX,TxRxmode);
         output_bit(TX,!TxRxmode);
     
         // tasks which must only be done in Rx mode
         if (TxRxmode) {
   
            // RSSI indicator
            set_adc_channel(1);
            delay_us(10);
            rssi = read_adc();
            if (rssi > 0x0ff) {
               output_low(RSSILED1);
               if (rssi > 0x118) {
                  output_low(RSSILED2);
                  if (rssi > 0x134) {
                     output_low(RSSILED3);
                     if (rssi > 0x157) {
                        output_low(RSSILED4);
                     } else output_high(RSSILED4);
                  } else output_high(RSSILED3);
               } else output_high(RSSILED2);
            } else output_high(RSSILED1);
       
            // Direction finding
            set_adc_channel(2);
            delay_us(10);
            antsig = read_adc();
   
            //average new value with old value
            // antx' = antx*2^-alpha + antsig*(1-2^-alpha)
              if (input(ANTSELIN)) ant1 = (ant1>>alpha) + antsig - (antsig>>alpha);
             else ant2 = (ant2>>alpha) + antsig - (antsig>>alpha);
   
              antdiff = ant1 - ant2;
   
            if (antdiff < -91)
                output_b(0b10111111);
            else if (antdiff < -55)
                output_b(0b11011111);
            else if (antdiff < -18)
                output_b(0b11101111);
            else if (antdiff < 18)
                output_b(0b11110111);
            else if (antdiff < 55)
                output_b(0b11111011);
            else if (antdiff < 91)
                output_b(0b11111101);
            else
                output_b(0b00000001);
   
         }
     }
  }
  // End Main Routine
   
   
  /******************************************************************************\
  *                                                                              *
  *              I N T E R R U P T   S E R V I C E   R O U T I N E S             *
  *                                                                              *
  \******************************************************************************/
   
  //  Purpose:        Timer2 ISR
  //  Precondition:   timer2 initialized
  //  Postcondition:  tx/rx signal updated
  #INT_TIMER2
  void Timer2ISR(void) {
      timer2count++;
      if (TxRxmode) {
          if (timer2count > 75) {
              timer2count = 0;
              TxRxmode = 0;
          }
      } else {
          if (timer2count > 50) {
              timer2count = 0;
              TxRxmode = 1;
          }
      }
  }
 
Top