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.

[General] wireless distance measurement

Status
Not open for further replies.

pabel971123

Newbie level 3
Joined
Feb 12, 2018
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
Hi,
I want to measure distance between two points using rf. I am using msp430f5528 microcontroller which uses 24 MHz crystal oscillator . It is based on tof technology. First msp430 sends a data through rf and switch on a timer. Other side receiver receives it and sends an acknowledge signal. msp430 receives this and switch off the timer. Then calculate the distance.

Now in program I want to display the timer value on an lcd and calculate the distance manually for clarity. The program is:
Code:
#include <msp430.h>

#define DR P4OUT = P4OUT | BIT1 // define RS high
#define CWR P4OUT = P4OUT & (~BIT1) // define RS low
#define READ P4OUT = P4OUT | BIT2 // define Read signal R/W = 1 for reading
#define WRITE P4OUT = P4OUT & (~BIT2) // define Write signal R/W = 0 for writing
#define ENABLE_HIGH P1OUT = P1OUT | BIT4 // define Enable high signal
#define ENABLE_LOW P1OUT = P1OUT & (~BIT4) // define Enable Low signal
unsigned int i;
unsigned int j;

void delay(unsigned int k)
{
for(j=0;j<=k;j++)
{
for(i=0;i<100;i++);
}
}
void data_write(void)
{
ENABLE_HIGH;
delay(2);
ENABLE_LOW;
}
void data_read(void)
{
ENABLE_LOW;
delay(2);
ENABLE_HIGH;
}
void check_busy(void)
{
PJDIR &= ~(BIT3); // make P1.3 as input
while((PJIN&BIT3)==1)
{
data_read();
}
PJDIR |= BIT3; // make P1.3 as output
}
void send_command(unsigned char cmd)
{
check_busy();
WRITE;
CWR;
PJOUT = (PJOUT & 0xF0)|((cmd>>4) & 0x0F); // send higher nibble
data_write(); // give enable trigger
PJOUT = (PJOUT & 0xF0)|(cmd & 0x0F); // send lower nibble
data_write(); // give enable trigger
}
void send_data( char data)
{
check_busy();
WRITE;
DR;
PJOUT = (PJOUT & 0xF0)|((data>>4) & 0x0F); // send higher nibble
data_write(); // give enable trigger
PJOUT = (PJOUT & 0xF0)|(data & 0x0F); // send lower nibble
data_write(); // give enable trigger
}
void send_string(char  *s)
{
while(*s)
{
send_data(*s);
s++;
}
}
void lcd_init(void)
{
PJDIR |= 0xFF;
PJOUT &= 0x00;
P4DIR |= 0xFF;
P4OUT &= 0x00;
P1DIR |= 0xFF;
P1OUT &= 0x00;
send_command(0x33);
send_command(0x32);
send_command(0x28); // 4 bit mode
send_command(0x0E); // clear the screen
send_command(0x01); // display on cursor on
send_command(0x06); // increment cursor
send_command(0x80); // row 1 column 1
}


char data;
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  P4SEL = BIT4+BIT5;                        // P3.4,5 = USCI_A0 TXD/RXD
  UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA1CTL1 |= UCSSEL_2;                     // SMCLK
  UCA1BR0 = 6;                              // 1MHz 9600 (see User's Guide)
  UCA1BR1 = 0;                              // 1MHz 9600
  UCA1MCTL = UCBRS_0 + UCBRF_13 + UCOS16;   // Modln UCBRSx=0, UCBRFx=0,
                                            // over sampling
  UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

  UCA1IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

            UCA1TXBUF = 3;                  // TX -> RXed character


            __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
            __no_operation();                         // For debugger
}

// Echo back RXed character, confirm TX buffer is ready first
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(UCA1IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:
    TA0CTL = MC__STOP;
            // Vector 2 - RXIFG
      data=TA0R;
      lcd_init();
                                char data1=data%10 + 0x30;
                                    send_string(&data1);
                                    data=data/10;
                                    data1=data%10 + 0x30;
                                    send_string(&data1);
                                    data=data/10;
                                    data1=data%10 + 0x30;
                                    send_string(&data1);
                                    data=data/10;
                                    data1=data%10 + 0x30;
                                    send_string(&data1);
                                    data=data/10;
                                    data1=data%10 + 0x30;
                                    send_string(&data1);
     TA0CTL |=TACLR;
      while (!(UCA1IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
       UCA1TXBUF = UCA1RXBUF;                  // TX -> RXed character

         TA0CCR0 = 65535;
          TA0CTL = TASSEL_2 + MC_1 + TACLR;         // SMCLK, upmode, clear TAR
    break;
  case 4:

      break;                             // Vector 4 - TXIFG
  default: break;
  }


 // __bic_SR_register_on_exit (LPM0_bits);
}


In this code I am displaying the timer value on lcd to calculate the distance, but it is not displaying.
Please help me in this.



Thanks

Pabel
 

Hi,

no professional will write the whole code at once and expect it to work...

Divide it into smaller parts and test one part after the other.
Then at the and you will join all parts.

* Test if sending the START signal works
* test if you receive the ACKNOWLEDGE signal correctly
* try sending a fix string like "Hello world" to the display..
and so on.

Klaus
 

In addition to the above tips, it would also be noticeable that you need to review some programming concepts often remaked here, because the above program make access to the Display from within the serial interrupt, and in addition initializes the display itself there. Start with a simpler program, and then add resources in a bottom-up approach.
 

You say "RF" (electromagnetic waves), not ultrasonic? Can you give as an idea of the intended distance range and expected resolution? You might be underestimating the processing speed requirements.
 

Hi,
Thank you all for replying!

I am new to msp430 and this is my first project using msp430.
I have checked it part by part I was working.

Previously I have accessed the display in main program but it was not showing anythig. Then checked in ISR, it was displaying some data but that is not actual.

I have to measure it in a range of around 300m. Rf travels approximately 300000000 m/s . msp430 have 24 MHz clock. That means I can get 42ns accuracy. It is around 7m. 7m is not a good resolution but at least I can measure the distance with my existing components.

Please help..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top