Do you download and read the User's guide?The outputs are explained and there is even sample code for the BASIC stamp. Use this code to learn what you need to do and then rewrite it for the Axon.The Accel's outputs are digital so they can be connected to any digital input on the Axon. The acceleration is the ratio of the high to period of the output pulse as shown in figure 1 of user's guide. The code needs to time the the pulse period and the high pulse length then calculate the G if needed.

I'm sorry but I still dont really get what you mean. I dont see anything about "cycles" in the axon source code

A 'cycle' is the length of time one instruction (assembler) takes to execute, also called an instruction cycle.This time is dependent on the clock frequency set by the processor's XTAL (crystal).

Now look again at Figure 2 in the accelerometer's user's guide and the equation under the figure. A(g) = ((T1 / T2) - 0.5) / 12.5%The period time and the high pulse time are a ratio in the equation so the absolute times (in seconds) are not required (the units of time cancel). Just count the length of each and divide the time (count) of the high pulse by the time (count) of the period.

t2 is counting how long the input is low but the equation in the user's guide is the length of the high pulse divided by the total length of the high plus the low (length of the period). So change the last line of code to:int acceleration = ((t1/(t1+t2)) - .5)/.125; //find acceleration

Now there is a second problem with this code. acceleration is an int and the math to calculate the acceleration requires floating point math. t1/(t1+t2) is always less than 1 (it'll be a faction). Also 0.5 & 0.125 are less than 1. One could using floating point values but this takes up a lot more code space and execution time.

The easy way out of this is to multiple t1 by 100 and use the equation:t1 = t1 *100;int acceleration = ((t1/t2) - 50)*8; // find acceleration * 100The acceleration value is now greater than zero and is also 100 times the true 'G' value but is easy to deal with.

I see you are examining the BASIC code in the User's guide, good.The code you posted is the output to a UART to display the data in a terminal program on a PC.'x input' is x raw, the actual measured time of the high pulse. See the "Read_G_Force:" subroutine.'g force' is the actual g calculated from the pulse width. See the "Read_G_Force:" subroutine.'x tilt' is the calculated tilt of the x-axis. See the "Read_Tilt:" subroutine.

Do notice the equation used in the "Read_G_Force:" subroutine. xRaw is 1000 times larger so that 500 is subtracted from it. The result is 1/1000 g per 1 value (exp: if xmG calc's to be 1000 this is 1g, if xmG calc's be be 50 then g = 0.05).

One way to deal with fractional numbers is to use the ‘ */ ’ operator. It has the effect ofmultiplying a value by a whole number and a fraction. This operator places the wholenumber portion in the upper byte, multiplies the fractional part by 256 and places theresult in the lower byte.For example, if multiplying value with 1.8, using the ‘ */ ’ would mean 0.8 * 256 = 204.8 =205 and therefore:Upper byte : 01Lower byte : CD

ok I've switched to WebbotLib method, but all it does is give me haywire messagescode:

Quote

void read_accelerometer () {

while(pin_is_high(F5)) //while pin is high.... t1++; //count how long it is high while(pin_is_low(F5) ) //while pin is low... t2++; //count how long it is low acceleration = ((t1/(t1+t2)) - 500)* 8; } //find acceleration

yes, I did initallize F5 as an inputis it possible that my accelerometer is faulty?