/****************************************************************************** * main() ******************************************************************************/ void main() { Initial(); // Initialize everything while(1) { AccelMeter(); displayAccel(); Delay10KTCYx(25); // Sit here forever } }/******************************************************************************
//polls at 125 hz, fills array and runs fft + display when full void TimerIntHandler () { signed char c; char s[20]; int i, maxIndex, f, num; float fl; if(dataCount < 128) x[dataCount++]= signedByteAccelRead(0x06); else { //create windowing function 0Q16 (0.5 =32768 0.99998 =65535) for (i=0;i<NN/2;i++) w[i]=0xffff; //0.99998 //clear output array for (i=0;i<NN;i++) y[i]=0; Window16to32b_real( x, w, NN); //or just expand to 32 bits with 1/2 scale FFT128Real_32b(y,x); for(i=0;i<NN;i++) magnitude32_32bIn(&y[2],NN/2-1); for (i=0;i<=NN;i+=2) y[i+1]=0; //zero imag part of original complex frequency for (i=0;i<=NN;i+=2) y[i]=((y[i]+16384)>>15); //2Q30 converted to 17Q15 and rounded dataCount = 0; maxIndex = findMax(y); fl = maxIndex; fl = (fl/128) * (125/2); if(fl*60 < 2500 && fl*60 > 219) rpm = fl *60; sprintf(s, "%d ", rpm); RIT128x96x4StringDraw(s, 0, 60, 15); displayAccel(); if(desiredRpm != -1) { if(rpm && desiredRpm - rpm > 219) changelessSpin(-100); if(rpm && desiredRpm - rpm < -219) changelessSpin(100); } } TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); }