Personal G-Force Meter

Questions and Comments on All Projects
eh2k8
Newbie Pyro
Posts: 3
Joined: Tue Apr 29, 2008 7:33 pm

Reply

Postby eh2k8 » Tue Apr 29, 2008 8:14 pm

Yeah thats exactly what I suspected but since I don't know how to program I though maybe... just maybe... the programming might have worked that out... but obviously not! So anyway is there any chance when you get a free moment or two could you just insert the new code and post it as I cant stress enough how little programming knowledge I have and it's almost guranteed to get mucked up if I try to do it, it'd be much appreciated!

Thanks,
Eric

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

Postby ThePyroElectro » Tue Apr 29, 2008 8:19 pm

I can put something up later on today, but it will be untested code which is good for guiding you but might not work the way you expect. :shock:

eh2k8
Newbie Pyro
Posts: 3
Joined: Tue Apr 29, 2008 7:33 pm

Postby eh2k8 » Tue Apr 29, 2008 8:22 pm

ah that'd be excellent, seeing that I'll be heading to bed soon seeing its nearly nite over here, and I don't think I'll have the whole thing running until a week or so as the AD chip will take a bit to get my hands on, other then that chip I'll get the rest done soonish!!

Thanks again!

nite
Newbie Pyro
Posts: 10
Joined: Wed May 21, 2008 7:07 pm

Postby nite » Wed May 21, 2008 7:10 pm

hi. i'm getting this strange error when compiling the source code:

Code: Select all

MPLAB C18 v3.20 (demo)Copyright 1999-2005 Microchip Technology Inc.Days remaining until demo becomes feature limited:  58
C:\PIC\Projects\TEST1\g_force_meter.c:66:Error [1105] symbol 'ADC_8ANA_0REF' has not been defined
C:\PIC\Projects\TEST1\g_force_meter.c:66:Error [1203] too few arguments in function callHalting build on first failure as requested.


it's defined in adc.h which is in the included in the main program. i had to change p18f452.h to p18f4520.h since i use this uC. maybe that's the problem?

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

Postby ThePyroElectro » Wed May 21, 2008 8:09 pm

The different microcontroller should make no difference when compiling the code.

I've come across this error before as there are multiple ways to use the OpenADC(...) function.

Check out the C18 Library Documentation file. The OpenADC function is documented very well. One of the example forms for using it should fit for the device/compiler.

This is one error I haven't found a good answer for other than using another form of OpenADC as seen in the documentation for the C18 functions.

Good luck. :D

nite
Newbie Pyro
Posts: 10
Joined: Wed May 21, 2008 7:07 pm

Postby nite » Thu May 22, 2008 7:53 am

thx, the build succeeds. now i'm just waiting for my pic burner :)

nite
Newbie Pyro
Posts: 10
Joined: Wed May 21, 2008 7:07 pm

Postby nite » Fri Jun 06, 2008 9:38 pm

hmm, it's displaying ~2.15 when lying flat
it's displaying total crap on the first digit when tilting it 90° (second and third digit are displaying around 12) - tilting it 90° the other side results in 2.89
i assume i have to do some calibrations?

i got to say my sensors looks different, i had to solder it myself ...

i would post a picture if the antispam protection would allow me :)

edit Image

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

Postby ThePyroElectro » Sat Jun 07, 2008 4:23 pm

Hmm that sounds strange.

If you're using the same sensor I used then it should be 2.5v when laying flat. If it's a different one, then the output might be different.

So maybe you have calibrations to do? I'd have to see the datasheet for your device. What's the part number?

nite
Newbie Pyro
Posts: 10
Joined: Wed May 21, 2008 7:07 pm

Postby nite » Sat Jun 07, 2008 6:12 pm

it's an adxl320
i got about 2,45 volts when lying flat
and i'm using a rc-oscillator instead of a 20mhz crytal
http://at.rs-online.com/web/search/sear ... 20&x=0&y=0
there's a data sheet on that page

edit: seems to be the output ...
if i use
char_disp[i]=0;
2.00 is displayed ...

Code: Select all

#include <p18f452.h>
#include <delays.h>
void main(void){
TRISB = 0;
PORTB = 0;

    while(1){
        PORTB = 0;
        Delay10KTCYx(90);
        PORTB = 0xFF;
        Delay10KTCYx(90);
    }
}


everything is blinking except rb5
the cabling is ok, happens on 2 pics!

edit: ok found the problem with rb5. LVP needs to be disabled to use RB5 as an output :evil:

edit: i think it's working now
0.01-0.04 flat
0.97-1.04 on right side
1.05-1.10 on left side

nite
Newbie Pyro
Posts: 10
Joined: Wed May 21, 2008 7:07 pm

Postby nite » Thu Jun 12, 2008 8:30 am

here's the modified code for using both axis on the first two ADC channels

Code: Select all

#include <p18f452.h>
#include <delays.h>
#include <adc.h>
#include <math.h>

#define gravity_ss 509
#define gravity_ss_y 505

#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, past_result = 0, current_result_y, past_result_y = 0;
int g_val, temp = 0, g_val_y, temp_y = 0, g_val_t, temp2;

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( ADC_FOSC_RC
      & ADC_RIGHT_JUST
      & ADC_8ANA_0REF,
      ADC_CH0 & ADC_INT_OFF );

while(1){

update_char_display(char_disp);
Delay1KTCYx(1);

SetChanADC(ADC_CH0);
ConvertADC();
while( BusyADC() );
   current_result = ReadADC();

temp = current_result - past_result;

SetChanADC(ADC_CH1);
ConvertADC();
while( BusyADC() );
   current_result_y = ReadADC();

temp_y = current_result_y - past_result_y;


   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;
   }

   if( temp_y > 2 || temp_y < -2 )
   {
   past_result_y = current_result_y;
   g_val_y = current_result_y - gravity_ss_y;
   g_val_y = g_val_y << 5;
   g_val_y = g_val_y / display_divider;
   
   if(g_val_y < 0)
      g_val_y = g_val_y * -1;

   i = 2;
   }

   temp2 = g_val * g_val + g_val_y * g_val_y;
   g_val_t = sqrt(temp2);


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

}



}

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

Postby ThePyroElectro » Mon Jun 16, 2008 3:05 pm

Sorry I haven't been getting back to you, I don't have internet at my new place.

How well did this code work?

nite
Newbie Pyro
Posts: 10
Joined: Wed May 21, 2008 7:07 pm

Postby nite » Mon Jun 16, 2008 10:03 pm

very good. if i rotate the gmeter the whole 360° it keeps displaying around 1G
the only problem i get is that one side of one axis is a bit off
displays 1,2G when the gmeter is standing on the right side.
1.0 on the left side and 0.0x when lying flat :(

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

Postby ThePyroElectro » Tue Jun 17, 2008 3:07 pm

Hmm, strange. I can't think of a reason for why it might do that. :?

You could fix it up in software but the sensor should be working appropriately. Other than that, pretty cool you got it working :D.

cyber
Newbie Pyro
Posts: 1
Joined: Tue Jul 08, 2008 9:30 pm

Postby cyber » Tue Jul 08, 2008 9:38 pm

hi

this my be a stupid/inappropriate question but something isnt realy clear to me,
the ADXL320 Accelerometer does it only measure the acceleration or realy measure G

for example:
i place this Accelerometer in a centrifugal machine (where astronauts are trained in) and i let it spin at a constant velocity, does the ADXL320 measure something ?

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

Postby ThePyroElectro » Wed Jul 09, 2008 12:14 am

Hey Cyber,

The ADXL320 accelerometer measures acceleration which is the same as measuring 'G'. It can naturally then measure earth's gravity see the video here:

http://www.pyroelectro.com/projects/car ... heory.html

If the sensor were in a centrifugal machine it would detect the acceleration applied. If it is at constant velocity, no acceleration should be detected.


Return to “Projects”

Who is online

Users browsing this forum: No registered users and 7 guests