Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
while( pin is high){//increment counter}//do math as shown in users guide
I'm sorry but I still dont really get what you mean. I dont see anything about "cycles" in the axon source code
int t1 = 0;int t2 = 0;while(bit_is_set(PIND,4)) //while pin is high....t1++; //count how long it is highwhile(!(bit_is_set(PIND,4))) //while pin is low...t2++; //count how long it is lowint acceleration = ((t1/t2) - .5)/.125; //find acceleration
DEBUG CRSRXY, 0, 3DEBUG "X Input... ",DEC (xRaw / 1000), ".", DEC3 xRaw, " ms",CLREOL, CR,"G Force... ", (xmG.BIT15 * 13 + " "),DEC (ABS xmG / 1000), ".", DEC3 (ABS xmG), " g",CLREOL, CR,"X Tilt.... ", (xTilt.BIT15 * 13 + " "),DEC ABS xTilt, DegSym, CLREOLDEBUG CRSRXY, 0, 7
here is kind of pseudocode:Code: [Select]int t1 = 0;int t2 = 0;while(bit_is_set(PIND,4)) //while pin is high....t1++; //count how long it is highwhile(!(bit_is_set(PIND,4))) //while pin is low...t2++; //count how long it is lowint acceleration = ((t1/t2) - .5)/.125; //find acceleration
xmG = ((xRaw / 10) - 500) * 8
xRaw = xRaw */ Scale
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
so you use it if multiplying with floats basically?
while(bit_is_set(PIND,4))
../experimental2.c: In function 'read_accelerometer':../experimental2.c:20: error: 'PIND' undeclared (first use in this function)../experimental2.c:20: error: (Each undeclared identifier is reported only once../experimental2.c:20: error: for each function it appears in.)make: *** [experimental2.o] Error 1Build failed with 3 errors and 0 warnings...
#define bit_is_set ( sfr, bit ) (_SFR_BYTE(sfr) & _BV(bit))
## General FlagsPROJECT = experimental2MCU = atmega640TARGET = experimental2.elfCC = avr-gcc.exe
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