 |
 |
View previous topic :: View next topic |
Author |
Message |
kein
Joined: 23 Jul 2007 Posts: 103
|
Sorry PCM Programmmer |
Posted: Tue Sep 11, 2007 7:00 pm |
|
|
Sorry for mistakenly connecting with that source code. I'm suppose to be asking icesynth who posted here: http://www.ccsinfo.com/forum/viewtopic.php?t=31907&highlight=
PCM programmer, mate I went and exactly learn C programming for 3 weeks as you instructed me. I'm well with the syntax now. Thanks alot for that ...It had helped me alot.
Lastly with regards to my use of fix point math. Do you think I should go a head that method?
icesynth, please fill me in with regard to your addition of 1.5 as shown here ins your post.
f Code: | ( Voltage > 1.55V )
{
Calibrated Output = (( Vin - 1.55V ) * MA ) + 1.5V
}else if( Voltage == 1.55V ){
( Calibrated Output = 1.55V
}else if( Voltage < 1.55V ){
Calibrated Output = 1.55V - ((Vin - 1.55V ) * MB )
} |
Thanks for your input and time.  |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 11, 2007 11:55 pm |
|
|
Can you post the absolute minimum requirements necessary to finish
the ADXL330 portion of your project ? For example, if you need two
routines, then say that.
State what C functions you need, and state what the input to these
functions will be, and what the desired output should be.
Give examples of the inputs and outputs, in terms of numbers.
Don't worry about discussing the internal code in the functions.
Just post the expected range of input values to the functions, and
your desired outputs from the functions.
---------
Also, describe your hardware in detail. Is the ADXL330 chip mounted
on a pre-built board, that you bought from Sparkfun, or did you
build the whole thing yourself ? If you built it, describe all the circuits
in detail. Describe any opamp buffer circuits used with the ADXL330
and any other circuits. |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
Thanks PCM Programmer |
Posted: Wed Sep 12, 2007 7:25 am |
|
|
I need two routines one for calibrating (getting zero g values) and the routine for filling three arrays with scaled gs i.e.
Quote: | State what C functions you need, and state what the input to these
functions will be, and what the desired output should be.
|
Code: |
float g_x[16], g_y[16], g_z[16]; /* these should be filled with gs or real acceleration values*/
void calibratexyz()
{
}
void FillArray_Gs(){
while(i++ <16 ){
g_x[i] =??//int16 g[16];
g_y[i] =???
g_z[i] =??? //g values
}
} |
Quote: | Give examples of the inputs and outputs, in terms of numbers. |
expected results:
inputs x,y,z obtained from various orientations:
[ Xmax, X0g, Xmin ] = [ 608, 512, 396] ;
[ Ymax, Y0g, Ymin ] = [ 612, 512, 396] ;
[ Zmax, Z0g, Zmin ] = [ 606, 512, 396] ;
expected would be adc values subtract zero g values from then convert to gs that should be saved in arrays of length 16 as shown above.
i.e adcDiff = (adcValue - ZeroG_values) then convert to gs.
if adxl330 board sits flat on the table, it should read +1g and -1g if turn upside down.
Since I want to use this device for measuring vibrations it should be fairly accurate.
Hardware specs:
My accelerometer adxl330 is set firmly on the board I made myself. I've connected three capacitors 0.01uf to set filter parameters.
It's powered by 3.3v
VRef+ = 3.3V
Quote: | setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_64); // setup_adc(ADC_OFF); |
PIC16f877A is used with AN0, AN1, AN2 set for analogue inputs with adc set to 10 bits.
No OPAMP used. adxl330 is connected directly to the analogue pins.
Thank you for your time. |
|
 |
Ttelmah Guest
|
|
Posted: Wed Sep 12, 2007 9:35 am |
|
|
Code: |
struct readings {
signed int16 min;
signed int16 sum;
signed int16 max;
};
struct {
signed int16 zero;
float counts_per_g;
} cal_data[3];
void calibrate(void) {
struct readings gval[3];
int ctr,axis;
signed int16 temp;
//First you must clear the array
for (axis=0;axis<3;axis++) gval[axis].min=gval[axis].max = gval[axis].sum=0;
//Now you need to take all the readings
for (ctr=0;ctr<6;ctr++) {
switch (ctr) {
case 0:
//Ask user to orient the device to position 1 here
//Once they have indicated this is done, proceed
break;
case 1:
//ask user to orient to position 2 here. Again wait, then proceed
break;
case 2:
//ask user to select position 3 here. Again wait, then proceed
break;
case 3:
//ask user to orient to position 4 here. Again wait, then proceed
break;
case 4:
//ask user to select position 5 here. Again wait, then proceed
break;
case 5:
//ask user to select position 6 here. Again wait, then proceed
break;
}
for (axis=0;axis<3;axis++) {
temp = //read the axis value here
if (temp<gval>gval[axis].max) gval[axis].max=temp;
gval[axis].sum+=temp;
}
}
//Now you have read x,y,z values for the six orientations (Xup,
//Xdown, Yup, Ydown, Zup, Zdown)
//and stored from the eighteen readings, the sum of the values,
//and the lowest and highest values recorded, for each axis.
//Now extract the calibration data.
for (axis=0;axis<3;axis++) {
gval[axis].sum-=gval[axis].min;
gval[axis].sum-=gval[axis].max;
//Extract the min and max values, from the sum (since these are for
//+/-1g, not the zero value.
cal_data[axis].zero=gval[axis].sum/4;
//generate the average of the zero points
cal_data[axis].counts_per_g=gval[axis].max-gval[axis].max/1960.0;
//calculate the counts per g.
}
}
//Routine to return the calbrated int16 result in milli-g, from the current reading
signed int16 g_reading(signed int16 adc_reading,int8 axis) {
return((adc_reading-cal_data[axis].zero)/cal_data[axis].counts_per_g);
}
|
You need to add the routines to prompt the user to orientate the device, read the actual data in each position, and the main code to call the routines, but this (assuming I have not made too many typing errors -
untested...), gives an idea of how to calibrate the unit.
Obviously, EEPROM storage of the calibrated values would also be worthwhile.
Best Wishes |
|
 |
Ttelmah Guest
|
|
Posted: Wed Sep 12, 2007 9:46 am |
|
|
Spot the first error. The .min values, need to be initialised 'above' the top of the ADC's maximum range, or they'll never update...
Best Wishes |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
Thanks but values aren't different |
Posted: Fri Sep 14, 2007 9:33 pm |
|
|
I've obtained the same values with your method. It seems the problem is the analysis
Code: | [ Xmax, X0g, Xmin ] = [ 608, 512, 396] ;
[ Ymax, Y0g, Ymin ] = [ 612, 512, 396] ;
[ Zmax, Z0g, Zmin ] = [ 606, 512, 396] ; |
Can you please send me a code (returning g values) using the above values as the zero g values.
I'll appreciate. |
|
 |
Ttelmah Guest
|
|
Posted: Sat Sep 15, 2007 2:15 am |
|
|
So what you you get, if you call the 'g_reading' routine, with an ADC value, and the axis selected, after the calibration?.
Best Wishes |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
|
Posted: Tue Sep 18, 2007 6:35 am |
|
|
I'm getting the following values:
Code: | For Z-Axis
{ x, y, z } = { 603, 512, 397 } ------------->YOUT = 0g
ZOUT = 0g
XOUT = +1g
{ x, y, z } = { 401, 500, 512 } ------------->YOUT = 0g
ZOUT = 0g
XOUT = -1g
for Y-Axis
{ x, y, z } = { 500, 612, 512 } ------------->YOUT = 0g
ZOUT = +1g
XOUT = 0g
{ x, y, z } = { 502, 393, 512 } ------------->YOUT = 0g
ZOUT = -1g
XOUT = 0g
for X-Axis
{ x, y, z } = { 608, 508, 512 } ------------->YOUT = +1g
ZOUT = 0g
XOUT = 0g
{ x, y, z } = { 397, 496, 512 } ------------->YOUT = -1g
ZOUT = 0g
XOUT = 0g |
Hope this is what you wanted me to do.
Thanks |
|
 |
kein
Joined: 23 Jul 2007 Posts: 103
|
|
Posted: Wed Sep 19, 2007 6:41 am |
|
|
hi Ttelmah?
Isn't this what you have asked for?
Cheers mate. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 19, 2007 11:06 am |
|
|
Quote: | I've obtained the same values with your method.
[ Xmax, X0g, Xmin ] = [ 608, 512, 396] ;
[ Ymax, Y0g, Ymin ] = [ 612, 512, 396] ;
[ Zmax, Z0g, Zmin ] = [ 606, 512, 396] ; |
Does this mean that you like those results ? Are they the results
that you want to get ?
Quote: | It seems the problem is the analysis. |
What 'analysis' are you referring to ? Are you referring to additional
code of your own (that's not been posted), that operates on these
values ?
If so, you need to post the 'analysis' code. Post a small test program
that calls the analysis function. Show all variable declarations, and
set the input variables for the analysis function to the values above.
Then run the test program and post the output of the program.
If the output of the 'analysis' function is unsatisfactory, then tell us
explicitly what you want it to be. Post the numbers.
Do you see what I'm getting at ? What I've been trying to do, is to
teach you how to trouble-shoot a problem. First I asked you to use a
volt-meter and verify that the ADXL chip itself was working. You did that.
Then the next step was to write the low-level driver code and test it.
Ttelmah gave you the code for that. The next step for you was to
incorporate and test Ttelmahs driver code. Unfortunately, the
answer that you gave was ambiguous (at least to me). It would help
if you would come forward and say "your code works great". "This is
the exact output that I wanted to see".
So assuming that Ttelmah's code works well for you, the next step is
to test your 'analysis' code. That's the next module to debug. That's
why I've asked you to post it in a test program, and report the input and
output values of the analysis routine, and to report whether or not
they are satisfactory to you.
This is a modular approach to testing and debugging.
1. Verify the physical chip has the expected output.
2. Write a low-level driver.
3. Write the higher level 'analysis' code and display the results.
Do each step, one at a time. |
|
 |
Ttelmah Guest
|
|
Posted: Thu Sep 20, 2007 2:59 am |
|
|
As a 'carry on', 'no', that was not "what I asked for". I asked what you actually get from the routine. Since the value will be in mG, you won't get a number like '1'. Also,what do you mean 'for Z axis'.
However, looking at what you have posted, it appears to be working absolutely perfectly, except you have got the axes misnamed. If by 'for Z axis', you mean, with Z up, then down, then you have the exact reading you expect, but on X. Similarly, your 'Y' value is on Z etc..
All you are doing, is at some point, you have got the order you read the three channels scrambled...
Best Wishes |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|