This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HELP! Data acquisition from multiple sensors!

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!

  • Allen Chuang said:
    I am new and have no experience on programming a microcontroller.

    It's quite a big project for a newcomer with no microcontroller experience, let alone MSP specific experience.

    Allen Chuang said:
    he project can be roughly divided into three parts.

    What is the third part?

    nevertheless, some general comments on the project:

    1) data acquisition
    i guess that the sensores are all providing an analog signal. Or do they have a digital interface? If so, then the project can be subdivided.
    Analog sampling on the 1611 is done with an SAR ADC. This means, the ADC12 selects one of the input lines (you configure which one, or even define a sequence), opens its input and samples the input voltage for some (configurable) time, then close the input and does a suucessive approximation. After this is done, the result is provided and depending on the mode, the ADC retuns to idle mode, or the next sample is taken from teh same or a different input channel.
    There are ways to control the timing uning a timer. Or you just let it do the work with maximum frequency and pick up the latest conversion result if you need it.

    However, there is no (simple) way to do conversion of different signals with different speeds. So just do all with the maximum speed and ignore those you don't want.

    There are several threads in this forum dealing with ADC12 usage (timer controlled or direct)

    2) SD storage. This is actually a two-part part. First is the SD card access itself. There are many threads here too which discuss it, complete with detailed order of steps for the card init etc.
    Then there is the file system part. This is the more difficult thing. There are some libraries which provide FAT support. These libs require you to write the low-level transfer functions fro readign or writing a sector to the storage device.
    However, do the low-level stuff first (init an SD card and read and write data).

    Since you want to contiue sampling data while the system is busy writing to the file, you might want to check out the DMA controller too for doing the block transfer. Here again, first do the low-level part (make a DMA transfer work, and the basic SD card stuff) before you try to use DMA for doing the SD card access.

    Allen Chuang said:
    could someone please give me an example including the hexadecimal address to connect to the various pins to retrieve data

    The 1611 datasheet tells you the signal names which are routed to the different pins of the 1611. The 1x family users guide tells you how to work with these signals based on the symbolic namees used for compiler and linker.

    Example: if a (physical) pin has the signals P1.1 and A1 routed, this means that you can use this pin for GPIO - in which case it is part of Port 1 and controlled by bit 1 of the P1DIR, P1OUT, P1IN registers (and some more for interrupts), or you can use it as analog input 1 for the ADC12. In this case it should be configured for plain analog usage by setting bit 1 in P1SEL register to assign it to other module usage than GPIO.

    And since you don't have MC experience, one word of advice: on MCs, usually less is more. Use the fastest, not the nicest solution. Use INT and not FLOAT, use inlined code instead of exporting every little one-liner into an own function. Your resources are limited.

    If you have specific problem simplementing a code detail, we're happy to help you.

  • 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!

    Jens-Michael Gross said:

    What is the third part?

    Sorry, I meant two parts.

    Jens-Michael Gross said:

    nevertheless, some general comments on the project:

    1) data acquisition
    i guess that the sensores are all providing an analog signal. Or do they have a digital interface? If so, then the project can be subdivided.
    Analog sampling on the 1611 is done with an SAR ADC. This means, the ADC12 selects one of the input lines (you configure which one, or even define a sequence), opens its input and samples the input voltage for some (configurable) time, then close the input and does a suucessive approximation. After this is done, the result is provided and depending on the mode, the ADC retuns to idle mode, or the next sample is taken from teh same or a different input channel.
    There are ways to control the timing uning a timer. Or you just let it do the work with maximum frequency and pick up the latest conversion result if you need it.

    However, there is no (simple) way to do conversion of different signals with different speeds. So just do all with the maximum speed and ignore those you don't want. 

    There are several threads in this forum dealing with ADC12 usage (timer controlled or direct)

    could you give a code example of how to set the sampling frequency of the ADC? Since I only need to sample at 2 different frequencies: 100 Hz and 50Hz, and 50 is just half of 100 i can just set a while loop and sample every other time? does that work?

    Jens-Michael Gross said:

    2) SD storage. This is actually a two-part part. First is the SD card access itself. There are many threads here too which discuss it, complete with detailed order of steps for the card init etc.
    Then there is the file system part. This is the more difficult thing. There are some libraries which provide FAT support. These libs require you to write the low-level transfer functions fro readign or writing a sector to the storage device.
    However, do the low-level stuff first (init an SD card and read and write data).

    Since you want to contiue sampling data while the system is busy writing to the file, you might want to check out the DMA controller too for doing the block transfer. Here again, first do the low-level part (make a DMA transfer work, and the basic SD card stuff) before you try to use DMA for doing the SD card access.

    This sounds really difficult.. wow.. not to mention the project also requires a .txt output onto the SD card. so far I do not know how to store the data acquired from the sensor into the SD card and i've been searching online and now i'm not sure if it is even possible to create a *.txt file on the SD card (need to include stdio.h?) will this exceed the free version of the 16kb limited CCE?

    right now all i have is the ADC code for the various sensors but i do not know how to set the sampling frequency.
    Does the following code look good? 

     

    // pin 6.2 Piezeoelectric sensor (61)

    signed long getADC3(){

    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 getADC4(){

    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 getADC5(){

    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 getADC6(){

    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 getADC7(){

    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 getADC8(){

    ADC12CTL0 = SHT0_6 + SHT1_6 + REFON + ADC12ON;

    ADC12CTL1 = SHP;

    ADC12MCTL0 = INCH_7 + SREF_1;

    ADC12CTL0 |= ADC12SC + ENC;

    while(ADC12CTL1 & 0x1);

    return ADC12MEM0 & 0xFFF;

    }

     

    thanks ahead for the help!

  • Allen Chuang said:
    could you give a code example of how to set the sampling frequency of the ADC?

    There is no 'the sampling frequency' for the ADC12. and therefore no setting. But there are a large number of ways to define it.

    First, the ADC12 is an SAR converter with S&H unit. That means, it will first charge a capacitor to the voltage to convert (Sample), then cut the connection to the signal source and do a successive approximation conversion of the 'voltage snapshot' (Hold).
    The conversion stage happens with the given ADC12OSC frequency, either provided through SMCLK or ACLK or by using the internally generated ADC12OSC (~5-6MHz). The conversion takes always n+1 cycles, depending on the selected bit width, so 13 for a 12 bit conversion or 9 for an 8 bit conversion.
    The sampling phase can be influenced in two ways. One of them is to define the number of ADC12CLK cycles for the sampling phase. The other is by a timer.

    So if you provide an ADC12CLK of, say, 1MHz and set the SHT (Sample&Hold Timer) to 64 clock cycles, one conversion will take 64+13 = 77 clock cycles, resulting in a sampling frequency of ~13kHz. In most cases this is sufficient. The length of the S&H time has an influence on the sampeld signal, forming sort of a low-pass to the input signal. Which usually is desired (if you are jsut sampling momentars snapshots of a noisy signal on a low smaplign frequency, the result will appear quite random - with a long S&H time, you will get a filtered signal which better fits your samplign frequency)

    However, if you want to convert data from more than one input, this frequency is divided by the number of different sources, and an additional cycle is required for the channel switching. So for two sources (as in your case), both are done after 155 clock cycles (and in a repeated mode, it takes 156 cycles per run).

    A different way to set the sampling frequency is by using a timer. There are again several ways. You can set up a timer so it will trigger an interrupt with the frequency you want. the ADC12 is configured like before except that it will not use any of the repeated mdoes (so only one conversion or one conversion sequence is done at a time) Inside the timer ISR, you start a conversion and 156 cycles later (with the given clock and SHT settings) you'll have the result. Then teh ADC sleeps until the next tiemr ISR starts the next conversion run.

    this allows you a fairly good control over the sampling frequency. However, interrupt latency and maybe blocked interrupt swill cause a certain jitter or stop the sampling totally (until the interrupts are enabled again).

    The last way is to directly use a Timer CCR unit to control the sampling process. In this mode, the S&H stage is configured to ignore the ADC122CLK and the SHT settings. The CCR unit is configured to directly control the S&H unit using a PWN signal (whose frequency controls the sampling frequency adn the duty cycle controls the sampling time). When the CCR output goes low, the ADC connects its S&H unit to the signal, when the PWm output goes high again, it closes the connection and starts the conversion. 13 ADC12CLK cycles later the result is available. On the next PWM cycle, the next channel (in case of a samplign sequence) is sampled (and at the end of the sequence you'll get an interrupt telling you that all results are done), or (if you are samplign just one channel) the next conversion is started on the same channel.

    It sounds complicated and partly is, but it allows you to do things the way it fits your project best.

    There is, however, no way to have the ADC12 converting different channels at different frequencies. You'll have to pick the highest one you need and ignore the superfluous results on teh other channels.

     

    Allen Chuang said:
    not to mention the project also requires a .txt output onto the SD card. so far I do not know how to store the data acquired from the sensor into the SD card and i've been searching online and now i'm not sure if it is even possible to create a *.txt file on the SD card (need to include stdio.h?)

    For handling files on an SD card (or any other storage media), you'll need a file system driver. It will provide the required code to open a file on teh storage device, write to it, read from it and will handle the directory stuff. So once you have a FS library in your project, writing to a .txt file is simple. Just open a file (e.g. using fopen or so), write to it (using fwrite), close it when done and things are great.

    However, the file system library won't contain the low-level access for the device. That means, you'll have to provide at least tree funcitons: read sector, write sector, device info (total size and block size). It depends on the library you use.

    here you can write your code for accessing the SD card, or just write and read to/from an unised area of the onboard flash. Or route the requests through a serial connection for debugging.

    Allen Chuang said:
    I know the pins the sensors are connected to

    I hope that whoever has done the layout connected them to the right pins. :)
    For sampling analog values, only a certain number of pins is available. So the sensors need to be hooked to a pin that has an analog input function (A0..A15) assigned to the pin.
    Access to the SD card is best (and fastest) done using the internal SPI hardware. To do this, the card needs to be connected to one of the pins that are available as inputs and outputs for the SPI hardware. (SOMI, SIMO and SCL pins).

    If so, the access is handled in the hardware internally, you only have to switch the pin to module usage by setting the proper selection bits. So if the SOMI signal is available on pin P3.5, you'll need to set bit 5 in P3SEL register and then UART/USCI module can use this pin for the SPI.

    If you want to do the I/O by yourself, then a pin that is listed as Px.y is controlled by the bit y in the PxIN, PxOUT, PxDIR registers. See the 'digital IO' chapter in the users guide.

    Allen Chuang said:
    will this exceed the free version of the 16kb limited CCE

    Possible. I don't know. it depends on the file system library you use. YOu can try to switch to the unlimited and free MSPGCC compiler, however, the migration will require some effort. The good new is that once you have picked a FS library, you'll know how large it is and how much code space is left for your own project code.

**Attention** This is a public forum