Personal G-Force Meter
Reply
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
Thanks,
Eric
-
- PyroElectro Admin
- Posts: 1181
- Joined: Mon Nov 12, 2007 9:24 pm
- Location: Earth
- Contact:
hi. i'm getting this strange error when compiling the source code:
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?
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?
-
- PyroElectro Admin
- Posts: 1181
- Joined: Mon Nov 12, 2007 9:24 pm
- Location: Earth
- Contact:
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.
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.

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

-
- PyroElectro Admin
- Posts: 1181
- Joined: Mon Nov 12, 2007 9:24 pm
- Location: Earth
- Contact:
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 ...
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
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
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

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
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--;
}
}
}
-
- PyroElectro Admin
- Posts: 1181
- Joined: Mon Nov 12, 2007 9:24 pm
- Location: Earth
- Contact:
-
- PyroElectro Admin
- Posts: 1181
- Joined: Mon Nov 12, 2007 9:24 pm
- Location: Earth
- Contact:
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 ?
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 ?
-
- PyroElectro Admin
- Posts: 1181
- Joined: Mon Nov 12, 2007 9:24 pm
- Location: Earth
- Contact:
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.
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.
Who is online
Users browsing this forum: No registered users and 1 guest