Jump to content
43oh

MSP430 data acquisition from multiple sensors


Recommended Posts

Hi all,

 

For my senior design project I have to program a MSP430 F1611 to acquire data from:

3-axis accelerometer breakout :Freescale semiconductor - MMA7361L: pins 4,5,6 for x,y,z outputs

PE vibration sensor: minisense 100: pins 61 and 62

2 Foot Force Sensors: FSR 402: pins 2 and 3

and have them stored onto a SD card.

 

this is suppose to be a data logger that records data on the go with the microcontroller tied onto the ankle.

 

To get started can anyone give me an example code so I can follow? i've read through the list of references for beginners provided on the forum but still very lost. I am new and have no experience on programming a microcontroller. could someone please show me how to start step by step?

 

the project can be roughly divided into three parts. data acquisition (from sensors to the MC), data storage (MC to SD card, should be in a txt format with each sample saved per row)

 

I know the pins the sensors are connected to, and the sampling frequency 100 Hz for accelerometer, PE sensor 50Hz for foot sensors. so I guess to get started could someone please give me an example including the hexadecimal address to connect to the various pins to retrieve data because I have absolutely no idea where to start thanks in advance!

Link to post
Share on other sites

Well, that sounds like an exciting project! A whizzy cool pedometer. Right on!

 

By the way, if you add a gps, gobs of RAM and FLASH, a monster cpu and a cellphone module then you will have a Parole Ankle Module. Just like Paris Hilton or Martha Stewart had. :lol:

 

 

The first thing you should do is investigate the communication methods between the sensors and the micro. I haven't looked up the sensors but I bet that they talk either SPI or I2C.

 

Once you figured that out then you could begin by selecting one of the devices and write some c code to talk with it. Once you've done that then you've written your first device driver. WOO HOO!

 

If the remaining sensors speak the same way then it's a matter of repeating the device driver development for each sensor. Each one may be slightly different from the others so the datasheets will be your close companion.

 

I know that the SD card is an SPI device and there's sample code out there that you could embrace and extend for your needs. I know that TI's MSP430F5529 has a dev board with an microSD card on it. I also believe that the MSP430F5438A has a dev board with microSD card on it.

 

So you could download the sample code for either of those boards and use it as a starting point. Most likely, you will rip it out of its context and then patch it into your system. It's just like working with Lego blocks.

 

If you post up some code then we are willing to help you refine your work. As many others here have said, we'll help you succeed but we won't do the work for you.

 

Remember this. There's nothing to fear. Failure is perfectly acceptable thing because it tells you what not to do. You can design it out of the results though. So make a plan/design. Adapt it as needed. You WILL succeed!

 

Please post some pictures of it for us.

Link to post
Share on other sites

Thanks for the reply! It's glad to have someone with such enthusiasm willing to help! :)

I am deeply troubled by this project.. i've been reading and reading online looking for a step by step guide for beginners but I was out of luck, i am really new to this and I have no previous experience with microcontrollers at all, so excuse all the dumb questions and please bear with me as i am trying to learn the best i could. thanks!!!!

 

The first thing you should do is investigate the communication methods between the sensors and the micro. I haven't looked up the sensors but I bet that they talk either SPI or I2C.

 

I've been looking at the datasheet of each sensor but i do not know whether they use SPI or I2C where do you look to determine the communication methods?

 

Once you figured that out then you could begin by selecting one of the devices and write some c code to talk with it. Once you've done that then you've written your first device driver. WOO HOO!

 

If the remaining sensors speak the same way then it's a matter of repeating the device driver development for each sensor. Each one may be slightly different from the others so the datasheets will be your close companion.

 

I'm not sure if it this right but I was looking at some sample code online and basically wrote the code following the same format:

 

// pin 6.2 Piezeoelectric sensor (61)
signed long getADC1(){
ADC12CTL0 = SHT0_6 + SHT1_6 + REFON + ADC12ON;
ADC12CTL1 = SHP;
ADC12MCTL0 = INCH_2 + SREF_1;
ADC12CTL0 |= ADC12SC + ENC;
while(ADC12CTL1 & 0x1);
return ADC12MEM0 & 0xFFF;
}

// pin 6.3 Foot Sensor 1 (2)
signed long getADC2(){
ADC12CTL0 = SHT0_6 + SHT1_6 + REFON + ADC12ON;
ADC12CTL1 = SHP;
ADC12MCTL0 = INCH_3 + SREF_1;
ADC12CTL0 |= ADC12SC + ENC;
while(ADC12CTL1 & 0x1);
return ADC12MEM0 & 0xFFF;
}

// pin 6.4 Foot Sensor 2 (3)
signed long getADC3(){
ADC12CTL0 = SHT0_6 + SHT1_6 + REFON + ADC12ON;
ADC12CTL1 = SHP;
ADC12MCTL0 = INCH_4 + SREF_1;
ADC12CTL0 |= ADC12SC + ENC;
while(ADC12CTL1 & 0x1);
return ADC12MEM0 & 0xFFF;
}

// pin 6.5 Accelerometer X-axis (4)
signed long getADC4(){
ADC12CTL0 = SHT0_6 + SHT1_6 + REFON + ADC12ON;
ADC12CTL1 = SHP;
ADC12MCTL0 = INCH_5 + SREF_1;
ADC12CTL0 |= ADC12SC + ENC;
while(ADC12CTL1 & 0x1);
return ADC12MEM0 & 0xFFF;
}

// pin 6.6 Accelerometer Y-axis (5)
signed long getADC5(){
ADC12CTL0 = SHT0_6 + SHT1_6 + REFON + ADC12ON;
ADC12CTL1 = SHP;
ADC12MCTL0 = INCH_6 + SREF_1;
ADC12CTL0 |= ADC12SC + ENC;
while(ADC12CTL1 & 0x1);
return ADC12MEM0 & 0xFFF;
}

// pin 6.7 Accelerometer Z-axis(6)
signed long getADC6(){
ADC12CTL0 = SHT0_6 + SHT1_6 + REFON + ADC12ON;
ADC12CTL1 = SHP;
ADC12MCTL0 = INCH_7 + SREF_1;
ADC12CTL0 |= ADC12SC + ENC;
while(ADC12CTL1 & 0x1);
return ADC12MEM0 & 0xFFF;
}

 

This is the only code I have so far. I haven't started writing the void main function yet. Frankly, I do not know how to start, just reading the sample code is quite overwhelming.. I really hope there is a step-by-step guide available that teaches you the basics and how to start your own program. I've learned C before but programming C on a microcontroller is quite different from programming just a C code using the computer from what I have gathered so far.

 

So far I have the following problems I need to solve:

 

1) For the project I also have to timestamp the logged data, how do i approach this? does the MSP430F1611 have a real time clock to use?

 

2) Also I am having trouble on figuring out how to set up the sampling rate. I need to sample at 2 frequencies 100 Hz and 50 Hz. Could you please give me a step by step instruction or teach me the basics on how to write the code for that?

 

Sorry for all the questions, but I'm really new to this and I need help, I've been desperately searching for references online or tutorials that i can follow but they've only gotten me so far, and I have a lot more i need to learn.

 

I know that the SD card is an SPI device and there's sample code out there that you could embrace and extend for your needs. I know that TI's MSP430F5529 has a dev board with an microSD card on it. I also believe that the MSP430F5438A has a dev board with microSD card on it.

 

I am interfacing an MMC/SD headerboard with the microcontroller, but before we go on to the SD card i would like to focus on data acquisition for now.

 

Thanks in advance zeke!

Link to post
Share on other sites

btw is it possible to program the microcontroller to output a .txt file and store logged data onto the SD card in the format of:

 

time_sensor output1_sensor output2_sensor output3..... and so forth with "_" representing "space" so it'd look something like this:

 

 

0.00 5.2323 4.232 3.23213

0.01 5.2323 4.232 3.23213

0.02 5.2323 4.232 3.23213

0.03 5.2323 4.232 3.23213 .......

 

since there are three sensors im looking for one .txt file per sensor with the various outputs

so the accelerometer would have time and three outputs (x,y,z)

the foot force sensors would have time and the two outputs f1 f2

and the piezo would have just time and the one output value.

 

just wondering if it is possible? many thanks!

Link to post
Share on other sites

You may need to step back from the details of your project for a little bit because you sound like you're drowning in the details.

 

Oh, and stop hyperventilating. As Douglas Adams said, Don't Panic!

 

I think you should take a tour of the MSP430 to get a feel for how things are done with it. Normally, folks try out the blinking LED sample program.

 

I think you should also take a look at this thread. It's a collection of notes for MSP430 Beginner's. It will point out some resources that you can use to help you get up to speed. Take special note of the Davies book. It's the best one out there.

 

Once you sort out how to drive the MSP430 then you can begin to design your system.

 

I'll give you my approach and you can see if it might work for you. I may have to use some analogies to paint a picture in your mind. Compare those images to your situation to see if they might work.

 

You've been asked to create a data logger. It has multiple sensors. Each sensor has it's own particular language. In the analogy, let's call them gears in a transmission. Temperature = 1st gear, Accelerometer (X,Y,Z) = 2nd gear, Time = 3rd gear and so on.

 

The MSP430 is the engine. It spins the transmission. So, you have to get the engine running first.

 

First, get the MSP430 running off of the 32kHz crystal. Solder on the little crystal that comes with the Launchpad.

Then program the MSP430 to use that crystal. Your code should use interrupts. Generate an timer interrupt once a second. This is the engine speed. You will be able to change the RPM of the engine later, as needed.

 

Then, you have to make the transmission work. This is where you would design a routine to blink a LED, or read a push button, or read the accelerometer, or write a byte to the SD card. The key is that you would do one thing at a time.

 

So, as a test, write a blink LED routine. Then, make it blink in time with the 1 second interrupt. If you can turn the LED off or on then do that inside the interrupt routine. Just one thing though - on or off.

 

After that, you have to add in each routine so that it will do its operation once every revolution of the timer.

 

What you are building here is a state machine. The 1 second timer is the driving force of the state machine. The sub-routines are the individual states. You transition from state to state using time or input signals as triggers.

 

 

Are you starting to see the big picture yet?

 

Summary:

Design your project as a state machine.

Use the timer to run the state machine.

Switch states using time intervals or input signals.

Design each state to be a single operation that can complete in a short amount of time.

Start small and simple.

Design on paper first. I can't stress this enough. Know what you're doing before you begin coding.

 

And, ask questions. There's a lot of smart and experienced people lurking here!

Link to post
Share on other sites

I have tried programming the blinking LED program awhile ago, but that is vastly different from what I'm trying to do.

Now I'm stuck on whether the microcontroller can be programmed to write a .txt file onto the SD card on the go. how may I approach that?

Link to post
Share on other sites

So, are you saying that you've completed your paper design already and you are now implementing all your state machines but you are stuck on the SD card interface?

 

Or, are you saying that you are throwing caution to the wind and becoming fixated on getting the SD card interface working?

 

It would be wise to build a good foundation for your code to operate on then you will have predictable results and easy to fix bugs.

 

So, if I understand you, you're asking if the SD card can be written in such a fashion that a PC could read the results. Correct?

 

If so, then the answer is yes. But you have to follow the file system specification to make that happen. Read the SD Wikipedia article for starters. To see an example of using the SD card, go and see what the Arduino folks are doing with it. Arduino code can be ported to the MSP430 without too much difficulty.

 

 

Are my responses helpful?

Link to post
Share on other sites

check out this article

http://alumni.cs.ucr.edu/~amitra/sdcard ... _foust.pdf

 

and http://en.wikipedia.org/wiki/Text_file

 

from what i understand, a txt file is a header and an EOF marker and data in-between the markers. as long as your SD card is formatted in FAT you should be able to just write header, then the data and close it out with an EOF marker and should be able to read it. If you can write files with dd then you should be able to write them with a Uc lol

 

 

Try formatting the SD card in fat and then try writing a zero- byte file and then go from there

Link to post
Share on other sites
I have tried programming the blinking LED program awhile ago, but that is vastly different from what I'm trying to do.

Are you saying you have tried, did not succeed and gave up on Blinky, everyone's best friend?

 

You really have to do this. Everything starts with Blinky. A simple output is Blinky. Making it blink are timers. Timers are clocks. Making Blinky glow is PWM. Add a simple button and/or a pot -- inputs, interrupts, ADC.

 

Without a strong command of these facilities any microcontroller project (not just MSP430, these are general concepts) is a quick way down. You really have to begin at the beginning. There are no shortcuts at this stage. For me, it took the Davies book, a LaunchPad, MSPGCC4, mspdebug and about three weeks to start getting the big picture. There really is no way around this.

 

Blinky is the alphabet and the times table of it all.

Link to post
Share on other sites

I guess we should ask what school the OP is going to. Why? Well, it's May 31st and he needs to complete a senior design project.

 

If he were in university or college then he would have written his finals by now and be out job hunting. Right?

 

If he were in high school then he would be still in school and getting ready to graduate in a month's time.

 

So, I'm guessing that he's in high school. Am I correct?

If so, then he's gotta haul a** and get this project done quickly.

 

@alchuang: Which scenario is it? Please tell us your timeline.

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...