Jump to content
43oh

Boxing headgear wireless counter


Recommended Posts

Hi everyone!

I stumbled on to this forum whilst searching for information about the msp430 micro controller, a component which i was tasked to use in building this project, the WASPS (wireless automatic slim pressure sensor) system. Basically the way it works is that Ive attached pressure sensors around a boxing head hear which is then attached to an msp430g2553 (no crystals)  which is then connected via wires to an XBee 2mW PCB Antenna transmitter module. The Receiver, which is connected to the computer will print out text on the screen (terminal), i.e. '1 punch detected' everytime a signal is detected from the pressure sensors.

so far: the ADC code is working fine for the msp430 from the sensors (UART) and the wireless modules are able to communicate with each other (i.e whatever gets sent from the transmitter is received by receiver and prints the output on terminal)

Now my hurdle and my final piece of the puzzle is the msp430 sending the text 'punch detected' to the XBee module everytime it gets a signal from its ADC. I was wondering if anyone would be kind enough to help a noob out and suggest ways on how i could code the msp430 to do this? The logic im assuming would be something along the lines of:
1)signal detected in ADC,
2)print 'punch detected'
3)transmit?

pls let me know if i am in the wrong thread. 

Much thanks.

Link to post
Share on other sites

Well here's the thing enigmatic:

My working ADC code is programmed in C... 
The msp430g2553 and XBee can both use UART.

and yes I am able to receive data on the other end( at the computer) provided that I have the transmitter and receiver isolated from the project and enter something  into the (yes you assumed right) terminal manually myself.

BUT..

a) I just copied of the ADC code of the internet

and 

I have no idea how it works.. well a very very rough idea.. and the thing that worries me the most

 

B) Other than entering data manually (via the terminal) into the transmitter from one computer and receiving it into another, I'm not sure how else I can input data into the transmitter (XBee) modules.. I know I can feed something into its data input from the output of the msp430, but I'm not sure how I can get the msp430g2553 to communicate with the XBee (transmitter) module.

So I was hoping if someone could show me the right direction as to how i can learn to do this.

Below is the ADC code that my partner found online which seems to work on its own (with just the msp430 and sensors)

#include <msp430.h>



unsigned int voltageLevel[4];
void ReadAdc(void);
void Mydelay(void);
void ConfigureAdc(void);
void DisplayLed(void);


void main(void){
  WDTCTL = WDTPW + WDTHOLD;
  ConfigureAdc();
  P1DIR |= BIT6;
  P1OUT &= ~BIT6;

  while(1){
      ADC10SA = (unsigned int)voltageLevel;
      ReadAdc();
      DisplayLed();
  }
}

void ConfigureAdc(void){

      ADC10CTL1 = INCH_3 + SHS_0 + CONSEQ_1;
      ADC10CTL0 = SREF_0 + ADC10SHT_2 + MSC + ADC10ON ;
      ADC10AE0 = BIT3 + BIT2 +BIT1 + BIT0;
      ADC10DTC1 = 0x4;

}

void Mydelay(void){
    unsigned int i = 100000;
    while(i>0)
        i--;
}

void ReadAdc(void){
    ADC10CTL0 |= ENC + ADC10SC;
    while(ADC10CTL1 & BUSY);
    ADC10CTL0 |= ~ADC10SC;
}

void DisplayLed(void){

    if(voltageLevel[2] >= voltageLevel[3]){
        P1OUT |= BIT6;

    }else if (voltageLevel[2] < voltageLevel[3]){
        P1OUT &= ~BIT6;
    }
}

and below is the link of the code which we are using to get something sent over from the msp430 to the wireless modules.


http://msp430.gorillaembedded.com/2013/02/msp430g2553-uart-print.html

we are trying to play around the 2 codes and figure out how we can sync them together.. but to no success. Up to 2 weeks ago, we have never heard of the msp430 or what UART is.. and we are given 8 weeks to build this thing, we are now into our 3rd. So we're trying to get some sort of crash course into this thing haha

Any help would be much appreciated,

Cheers

Link to post
Share on other sites

Combined the two and made some changes to fix/clean them. I won't explain what I did, I'll leave that up to you to read the code and figure it out :D (There might be one error, as I removed the "_BIS_SR(GIE);" line, but I'm not seeing any interrupts to enable. Everything is polled when needed).

#include <msp430.h>

// MSP430 UART Example http://msp430.gorillaembedded.com By Silver Back [Gorilla Embedded ]
// MSP430G2553 P1.1 and P1.2 as TX and RX

// Uart Prototype
void send_uart(char *data);
void ConfigureUART(void);

// ADC Prototype
unsigned int voltageLevel[4];
void ReadAdc(void);
void ConfigureAdc(void);
void UpdateOnHit(void);

void main(void) {
	WDTCTL = WDTPW + WDTHOLD;               // Stop WDT , not used
	BCSCTL1 = CALBC1_1MHZ;                  // DCO at 1 MHz
	DCOCTL = CALDCO_1MHZ;                   // DCO at 1 MHz

	// Configure LED
	P1DIR |= BIT6;
	P1OUT &= ~BIT6;

	ConfigureAdc();
	ConfigureUART();

	while(1){
		ADC10SA = (unsigned int)voltageLevel;
		ReadAdc();
		UpdateOnHit();
	}
}

void ConfigureAdc(void){
	ADC10CTL1 = INCH_3 + SHS_0 + CONSEQ_1;
	ADC10CTL0 = SREF_0 + ADC10SHT_2 + MSC + ADC10ON ;
	ADC10AE0 = BIT3 + BIT2 +BIT1 + BIT0;
	ADC10DTC1 = 0x4;
}

void ConfigureUART(void) {
	P1SEL |= 0x06;                       // Use P1.1 and P1.2 as USCI_A0
	P1SEL2|= 0x06;                        // Use P1.1 and P1.2 as USCI_A0
	P1DIR |= 0x04;                          // Set 1.2 as output
	UCA0CTL1 |= UCSSEL_2;                   // Use SMCLK / DCO 
	UCA0BR0 = 104;                          // 1 MHz -> 9600   N=Clock/Baud
	UCA0BR1 = 0;                            // 1 MHz -> 9600
	UCA0MCTL = UCBRS1;                      // Modulation UCBRSx = 1
	UCA0CTL1 &= ~UCSWRST;                   // **Initialize USCI  
}

void ReadAdc(void) {
	ADC10CTL0 |= ENC + ADC10SC;
	while(ADC10CTL1 & BUSY);
	ADC10CTL0 |= ~ADC10SC;
}

void send_uart(char *data) {
	P1OUT ^= BIT6;  // Toggle LED 

	unsigned int i;
	unsigned int size = strlen(data);      //get length of data to be sent
	for (i = 0; i < size; i++) {
		while (!(IFG2 & UCA0TXIFG));      //Wait UART to finish before next send
		UCA0TXBUF = data[i];
	}
}

void UpdateOnHit(void){

	if( voltageLevel[2] >= voltageLevel[3] ) {
		send_uart("Punch Detected! OUCH!\n\r");
	}
}
Link to post
Share on other sites

hey @@cde enigmatic, 
ive ran the code using ccs and im getting these errors.

my LED2 is also continuously blinking.. im assuming its the continuous polling thats happening with the while loop?

Ive also noticed that at the expressions tab doesnt have voltage level 3 and 4 which you have included in your code. Any suggestions? thank you!

p.s. still reading http://www.glitovsky.com/Tutorialv0_3.pdf and other material trying to understand your code :smile:

post-34006-0-11746900-1380691787_thumb.jpg

post-34006-0-32432000-1380691798_thumb.jpg

Link to post
Share on other sites

hey @@cde enigmatic, 

ive ran the code using ccs and im getting these errors.

 

my LED2 is also continuously blinking.. im assuming its the continuous polling thats happening with the while loop?

 

Ive also noticed that at the expressions tab doesnt have voltage level 3 and 4 which you have included in your code. Any suggestions? thank you!

 

p.s. still reading http://www.glitovsky.com/Tutorialv0_3.pdf and other material trying to understand your code :smile:

Those errors is because the debugger cannot read the memory while the code is running, when you pause it, or place a breakpoint, they will update.

 

The voltage level part, as well as reading the ADC part, I did not change, thats pretty much the same code. What I did change is that it only checks for a hit (voltageLevel[2] >= voltageLevel[3]) and if so, sends a string to the Uart code. Every time that code is ran, the led will toggle. Notice the while loop and the readadc parts are the same?

 

Try setting a breakpoint at the if (voltageLevel[2] >= voltageLevel[3]) point, and check the values. If the adc isn't updating voltageLevel, then voltageLevel[2] = 0, voltage level[3] = 0, and 0 is always >= 0, so the if is always true and it runs the uart code. 

 

Also your sensor must be hooked up properly while testing, or else the ADC will not have anything to read.

Link to post
Share on other sites

hmm maybe the problem is that my xbee doesnt even seem to be transmitting anything.. the leds on it arent lighting up..

can I ask which pins of the msp430 im meant to connect to the sensors and the Xbee module?
Is it p1.2 to data in of the wireless router and p1.1 for the sensor?

coz the msp430 is reading my adc values.. but im not getting anything from my terminal on the other computer

Link to post
Share on other sites

The sensor needs to hook up to the same adc channel it did in the original code. The uart/serial is tx on p1.2 to the xbee's rx pin. Doubt the msp430's rx pin needs to be connected, but that is p1.1.

 

If the msp430 is reading the adc correctly, then the issue is simply the serial connection somewhere between the msp430, the xbee, and the other end of the xbee and computer.

Link to post
Share on other sites

hi enigmatic, just an update,

yeah im thinking its also the connection..Just trying to figure that out at the moment. I have:

Vcc of msp430g2 connected to one end of the sensor and the xbee to power both of them
Gnd of msp430g2 connected to one end of the sensor and the xbee

1.2 of msp430g2 connected to DataIn/Rx of Xbee
1.1 of msp430g2 connected to the other end of sensor to receive signal

im thinking of maybe just doublechecking my xbees to see if their still synced to each other.

Link to post
Share on other sites

hi enigmatic, just an update,

 

yeah im thinking its also the connection..Just trying to figure that out at the moment. I have:

 

Vcc of msp430g2 connected to one end of the sensor and the xbee to power both of them

Gnd of msp430g2 connected to one end of the sensor and the xbee

1.2 of msp430g2 connected to DataIn/Rx of Xbee

1.1 of msp430g2 connected to the other end of sensor to receive signal

 

im thinking of maybe just doublechecking my xbees to see if their still synced to each other.

The simplest way to troubleshoot this is use the launchpad's serial connection. If you get the "Punch Detected" directly, then its an issue with the xbees. If not, then its an issue with the code or sensor wiring. 

Link to post
Share on other sites

Hi enigmatic!

Weve tried fiddling with the rx and tx of both the xbee and the msp430 as well as trying someone elses usb's but to no success.
We cant get the msp430 to send anything to the xbee.
We tested the adc it works fine, and we tried isolating the 2 xbees again both with our xbees and my fellow classmates at uni and they work too.

But when connected its the xbee transmitter is not receiving anything from the msp430, therefore unable to send anything to my other xbee/computer terminal.

A classmate who's doing a similar project suggested, maybe we might need a timer? like a specific rate or something included in the code?
We have very similar codes to his except for that his has interrupts which we dont need.
He has this bit of code
UCA0MCTL = UCBRS1;                      // Modulation UCBRSx = 1
 

set as UCBRS0?

Ill try and acquire some of his code, specifically the timer as it seemed to be the only thing different from your code and post it here.
Thanks heaps again enigmatic 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...