AnsweredAssumed Answered

Repurposing ADXL345 Inertial Sensor Development Board

Question asked by 33chen on Apr 9, 2013
Latest reply on Apr 30, 2013 by venkat

Dear folks,

 

I am a newbie to this forum and is recommended to post my question here. Really hope folks can give me some suggestions. I am a mechanical engineering student  and never does programming in c before and often use matlab.

 

I am using a ADXL345 inertial sensor datalogger and development board. As you all know, it can measure acceleration in x,y,z directions and output the data file in .txt format. As I read its user guide (UG-065), i can even repurpose the board using Keil Microvision software.

 

So the project at my hand is: I would like to add a regular potentiometer to this board (by basically hardwiring one into the board). So this board can measure both acceleration(from already existed ADXL345 accelerometer) and voltage (from the newly added pot). I will use the voltage in my algorithm for displacement representation. What I want to achieve is that I can reconfigure the board to let it ouput a file that not just has x,y,z acceleration data but also has voltage data. So I guess the most important thing I need to do is to reprogram the microcontroller to produce a new configuration file in .hex format. And then I can upload to the board which, once is powered on, can measure voltage data in pot and output the data in .txt file.I have discarded the idea that displacement data can be obtained by double integration of acceleration data from accelerometer itself. So now my questions are two:

 

1. how can I physically hardwire the pot to the development board, especially the signal line. I guess I can solder the power line and GND to the header pins of switch for AAA batteries. But what about the signal line? Where should I solder it to?

 

2. I am able to down all the necessary files and Keil microvision program (uversion 4) onto my computer. I can open datalogger.uvproj on the uversion environment. I assume I need to make some change in the c code for microcontroller. How should I modify this code to add a variable for my pot signal and recompile it to generate a new .hex file for configuration of the board

 

Thanks a lot.

 

Ji

 

/*****************************************************************************\
*              efs - General purpose Embedded Filesystem library              *
*          --------------------- -----------------------------------          *
*                                                                             *
* Filename : aduc702x_spi.c                                                     *
* Description : This file contains the functions needed to use efs for        *
*               accessing files on an SD-card connected to an LPC2xxx.        *
*                                                                             *
* This program is free software; you can redistribute it and/or               *
* modify it under the terms of the GNU General Public License                 *
* as published by the Free Software Foundation; version 2                     *
* of the License.                                                             *
                                                                              *
* This program is distributed in the hope that it will be useful,             *
* but WITHOUT ANY WARRANTY; without even the implied warranty of              *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
* GNU General Public License for more details.                                *
*                                                                             *
* As a special exception, if other files instantiate templates or             *
* use macros or inline functions from this file, or you compile this          *
* file and link it with other works to produce a work based on this file,     *
* this file does not by itself cause the resulting work to be covered         *
* by the GNU General Public License. However the source code for this         *
* file must still be made available in accordance with section (3) of         *
* the GNU General Public License.                                             *
*                                                                             *
* This exception does not invalidate any other reasons why a work based       *
* on this file might be covered by the GNU General Public License.            *
*                                                                             *
*                                                                             *
\*****************************************************************************/
/*****************************************************************************/
#include "interfaces/aduc702x_spi.h"
#include "interfaces/sd.h"
#include "config.h"
#include "debug_printf.h"
/*****************************************************************************/
#ifdef chris
// For the chris board
 #define NSSPIN 2<<16
 #define SELECT_CARD()   GP3CLR = NSSPIN
 #define UNSELECT_CARD() GP3SET = NSSPIN
#else
// for the multi-demo board
 #define NSSPIN 128<<16
 #define SELECT_CARD()   GP1CLR = NSSPIN
 #define UNSELECT_CARD() GP1SET = NSSPIN
#endif
#define SPI_PRESCALE_MIN  4 /* SPIDIV = 5 ==> 3.482MHz (highest to spec), SPIDIV = 3 ==> 5.22Mhz (works) */
esint8 if_initInterface(hwInterface* file, eint8* opts)
{
 euint32 sc;
 
 if_spiInit(file); /* init at low speed */
 
 if(sd_Init(file)<0) {
  DBG("Card failed to init, breaking up...\n");
  return(-1);
 }
 if(sd_State(file)<0){
  DBG("Card didn't return the ready state, breaking up...\n");
  return(-2);
 }
 
 // file->sectorCount=4; /* FIXME ASAP!! */
 
 sd_getDriveSize(file, &sc);
 file->sectorCount = sc/512;
 if( (sc%512) != 0) {
  file->sectorCount--;
 }
#ifdef FS_DEBUG_DEFINE
 DEBUG_PRINTF("Drive Size is %lu Bytes (%lu Sectors)\n", sc, file->sectorCount);
#endif
 
  /* increase speed after init */
 if_spiSetSpeed(SPI_PRESCALE_MIN);
#ifdef FS_DEBUG_DEFINE
 DBG("Init done...\n");
#endif
 return(0);
}
/*****************************************************************************/ 
esint8 if_readBuf(hwInterface* file,euint32 address,euint8* buf)
{
 return(sd_readSector(file,address,buf,512));
}
/*****************************************************************************/
esint8 if_writeBuf(hwInterface* file,euint32 address,euint8* buf)
{
 return(sd_writeSector(file,address, buf));
}
/*****************************************************************************/ 
esint8 if_setPos(hwInterface* file,euint32 address)
{
 return(0);
}
/*****************************************************************************/ 
// Utility-functions which does not toogle CS.
// Only needed during card-init. During init
// the automatic chip-select is disabled for SSP
static euint8 my_if_spiSend(hwInterface *iface, euint8 outgoing)
{
 euint8 incoming;
 SPITX = (euint8) outgoing;
 while((SPISTA & 0x08) != 0x08);
  incoming = (euint8) SPIRX;
 
 return(incoming);
}
/*****************************************************************************/ 
void if_spiInit(hwInterface *iface)
{
        int i; 
 unsigned long gpmode;
 // setup GPIO
 gpmode = GP1CON; // setup pins for SCK, MISO, MOSI
 GP1CON = (gpmode & 0xf000ffff) | 0x02220000;
#ifdef chris
 gpmode = GP3CON; // setup pins for CS
 GP3CON = gpmode & 0xffffff0f;  // make it GPIO
 gpmode = GP3DAT;
 GP3DAT = gpmode | 0x02020000; // make bit 2 output and high
#else
 gpmode = GP1CON; // setup pins for CS
 GP1CON = gpmode & 0x0fffffff;  // make it GPIO
 gpmode = GP1DAT;
 GP1DAT = gpmode | 0x80800000; // make bit 2 output and high
#endif
 // set Chip-Select high - unselect card
 UNSELECT_CARD();
 //configure the SPI
        SPICON = 0x1043; //enable, master CPOL=0 CPHA=0
 // low speed during init
 if_spiSetSpeed(20); // 1 mhz 
 /* Send 20 spi commands with card not selected */
 for(i=0;i<21;i++) {
   my_if_spiSend(iface,0xff);
 }
 
}
/*****************************************************************************/
void if_spiSetSpeed(euint16 speed)
{
 if ( speed < SPI_PRESCALE_MIN  ) speed = SPI_PRESCALE_MIN ;
 SPIDIV = speed;
}
/*****************************************************************************/
euint8 if_spiSend(hwInterface *iface, euint8 outgoing)
{
 euint8 incoming;
 SELECT_CARD();
 SPITX = (euint8) outgoing;
 while((SPISTA & 0x08) != 0x08);
  incoming = (euint8) SPIRX;
 UNSELECT_CARD();
 return(incoming);
}
/*****************************************************************************/

Outcomes