Personal G-Force Meter

Questions and Comments on All Projects
Tudy
Newbie Pyro
Posts: 4
Joined: Wed Mar 07, 2012 10:13 pm

Re: Personal G-Force Meter

Postby Tudy » Thu Mar 08, 2012 6:22 pm

Hi Tudy,

Sorry about that. I thought that tutorial did a 3-axis example...my memory is fading I guess.


Heh, no problem.

The easiest way to get acceleration data from 2 different outputs is to connect each output to a seperate A/D. So for example if you connect X acceleration out to ADC0/RA0 and Y acceleration out to ADC1/RA1.


I know and already done that.

Then in your firmware/software you will have to switch between channels 0 and 1 to get data from the different ADC input pins on the PIC.


Don't know what to do at all...

What it ends up looking like, is duplicating the existing connections and firmware for the single axis you already have for this 2nd axis of acceleration that you want to measure.


Can you tell me where and which exactly cod lines should I add in existing software for one axis?

Looking at the schematic and source code, the 7 segments are common-cathode [CC].


Thanke you for this info.

with regards, Tudy

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: Personal G-Force Meter

Postby ThePyroElectro » Thu Mar 08, 2012 8:01 pm

Hi Tudy,

For the firmware change you have two options.

[1]
You can open and close the ADC for when you need it and change the ADC_CHX channel through that point:

Code: Select all

int x_axis_accel=0;
int y_axis_accel=0;

//Open Channel_0 (ADC0/RA0)  And Get Data
OpenADC( ADC_FOSC_32
      & ADC_RIGHT_JUST
      & ADC_8ANA_0REF,
      ADC_CH0 & ADC_INT_OFF );
Delay10TCYx(5);
ConvertADC();
while( BusyADC() );
   x_axis_accel = ReadADC();
CloseADC();

//Open Channel_1 (ADC1/RA1)  And Get Data
OpenADC( ADC_FOSC_32
      & ADC_RIGHT_JUST
      & ADC_8ANA_0REF,
      ADC_CH1 & ADC_INT_OFF );
Delay10TCYx(5);
ConvertADC();
while( BusyADC() );
   y_axis_accel = ReadADC();
CloseADC();


[2]

You can use the SetChanADC() API function (found in the MPLAB C18 Libraries PDF) to switch between the currently MUX'd ADC channel. This is probably the cleaner way of doing it, depending upon if you want the ADC always enabled or not, I doubt it matters for your project.

Code: Select all

int x_axis_accel=0;
int y_axis_accel=0;

//Open ADC
OpenADC( ADC_FOSC_32
      & ADC_RIGHT_JUST
      & ADC_8ANA_0REF,
      ADC_CH0 & ADC_INT_OFF );

//Set Channel 0 And Get Data
SetChanADC( ADC_CH0 ); //This Is Redundant -- Added For Clarity
Delay10TCYx(5);
ConvertADC();
while( BusyADC() );
   x_axis_accel = ReadADC();

//Set Channel_1 And Get Data
SetChanADC( ADC_CH1 );
Delay10TCYx(5);
ConvertADC();
while( BusyADC() );
   y_axis_accel = ReadADC();

CloseADC();


These are the two methods that come to mind for getting the data from the ADC0/ADC1 pins. I haven't tested them out, but hopefully you can navigate your way around them to get what you need out of the PIC.

Tudy
Newbie Pyro
Posts: 4
Joined: Wed Mar 07, 2012 10:13 pm

Re: Personal G-Force Meter

Postby Tudy » Thu Mar 08, 2012 9:11 pm

Thanks a lot, I'll keep in touch with you.

ryhammad
Newbie Pyro
Posts: 1
Joined: Thu May 16, 2013 6:48 pm

Re: Personal G-Force Meter

Postby ryhammad » Thu May 16, 2013 7:01 pm

Hey,
Im working on your project right now but i need a little help if thats ok!

Firstly, i corrected part of the code coz i didnt know which program you used so i used MikroC, heres the code now can u make sure its still correct.

Code: Select all

#define gravity_ss 512
#define display_divider 20

//PORTD - 0bBGCDHAEF
#define one         0b10100000
#define two         0b11010110
#define three         0b11110100
#define four         0b11100001
#define five         0b01110101
#define six         0b01110111
#define seven         0b10100100
#define eight         0b11110111
#define nine         0b11110101
#define zero         0b10110111
#define blank   0b00000000

void update_char_display(int *char_disp)
{
        int i=0;
        int all_digits[11] = {zero, one, two, three, four, five, six, seven, eight, nine};
        for(i=0;i<3;i++)
        {

                switch(i)
                {
                case 0 :        PORTB = all_digits[char_disp[i]] + 0b1000;
                        break;
                case 1 :        PORTD = all_digits[char_disp[i]];
                        break;
                case 2 :        PORTC = all_digits[char_disp[i]];
                        break;
                default :
                        break;
                }
        }

}

void main(void)
{

int char_disp[3];

int current_result=0;
int past_result = 0;
int g_val, temp = 0;

int i=0;

TRISA = 0xFF;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
                                //Turn All Displays Off Initially
PORTB = blank;                //PORTB -> Display 1
PORTC = blank;                //PORTC -> Display 2
PORTD = blank;                //PORTD -> Display 3

                                        //Initialize A/D Converter
OpenADC
while(1){

update_char_display(char_disp);
Delay_ms(250);


Delay_ms(5);

while( 1 );
        current_result = ADC_read(1);
temp = current_result - past_result;

        if( temp > 2 || temp < -2 )
        {
        past_result = current_result;
        g_val = current_result - gravity_ss;
        g_val = g_val << 5;
        g_val = g_val / display_divider;

        if(g_val < 0)
                g_val = g_val * -1;

        i = 2;
        }
        while(i!= 255)
        {
                char_disp[i]=g_val%10;
                g_val = g_val/10;
                i--;
        }

}



}


Secondly, Im trying to run this program on proteus to make sure it works but there is no accelerometer. Do u use a different program please share!

I also wanted to know if i can use an alternate accelerometer im not sure they sell the adxl320 where i live.

Finally(sorrry!!) I couldnt find that specific kind of 7 segment LED, so the pin configuration is different. Can you please help me with that?
Its a chinese LED called GY5101AB

Sorry i know im a noob! Some of the questions are a bit much u dont have to answer them all sorrryyy. Appreciate the help!!!

Xlchaos
Newbie Pyro
Posts: 3
Joined: Sat Nov 30, 2013 6:51 pm

Re: Personal G-Force Meter

Postby Xlchaos » Sat Nov 30, 2013 6:58 pm

I know this thread has been dead for a bit but i am having a few issues.

I got the pic18 programmed and hooked up. Everything was working, the 7-segments, the accelerometer....except for 1 little issue. i have common anode 7-segment. So i reprogrammed the pic for the common anode (switched 0s to 1s and 1s to 0s) for the display. hooked it all back up and now nothing works. i even tired putting the original program on and i still nothing works. I am how ever getting 5vs out pin 31, Vss (ground). I double checked. The pin is grounded but its reading almost 5v. So i thought the chip might be fried, but i can still read, program and verify.

Any suggestions on what might be wrong :(

Xlchaos
Newbie Pyro
Posts: 3
Joined: Sat Nov 30, 2013 6:51 pm

Re: Personal G-Force Meter

Postby Xlchaos » Tue Jan 21, 2014 2:26 pm

Hi guys. So i got the 1 axis working but i have a few questions. When you guys did the code for 2 axes, does it only display one output number? Also how add would it be to include a 3rd axes? Thanks :)

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: Personal G-Force Meter

Postby ThePyroElectro » Sat Feb 15, 2014 6:21 pm

Xlchaos wrote:Hi guys. So i got the 1 axis working but i have a few questions. When you guys did the code for 2 axes, does it only display one output number? Also how add would it be to include a 3rd axes? Thanks :)


Hello,

For this project we only display the absolute value of the X axis.

If you want to display a single number for 2 or 3 axis, you're talking about showing an acceleration vector. In that cause you would want to get the magnitude of the 2 or 3 vectors. This is a matter of grabbing the data of the other axes you want to include and some calculation.


Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests