fbighouse
Joined: 11 Jan 2007 Posts: 2 Location: Brazil
|
few samples with ADXL213?? |
Posted: Thu Jan 18, 2007 8:19 pm |
|
|
I tried to write a lite code for measure a vibration...the acceleration data shows a sinewave... but when the frequency of vibration grows to around of 300Hz, it seems that some points are lost...so for lower frequency, there are more samples per cycle of sinewave and for high frequency, there are few sample per sinewave. Follow below a part of code, I use a calibration function to estimate the total period (high + low level = 1mS)(the total period is always the same), meas() lite code (I think) for measure (30 samples) of high level (duty cycle variation) and write this data in matrix. I don't use timers or ccp to do this, because I think be worst.??
I appreciate some idea to improve measure in high frequency.
#include <16F877A.h>
#include <input.c>
#include <string.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOWRT
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N)
float period;
long hi_level[30];
char x[10], on[3], meas[5], ver[4], cal[4];
short int vib_stat=0;
/***************************************************************************/
// VIBRATION MEAS
/***************************************************************************/
void meas_vib ()
{
int i;
for (i=0;i<30;i++) { // record in matrix 30 samples of rise time
long hi_temp=0;
while( input(PIN_C4)) {} // wait fall edge on C4
while( !input(PIN_C4)) {} // wait rise edge on C4
while( input(PIN_C4)) // while HI count+1
{
hi_temp++;
}
hi_level[i]=hi_temp; // record in matrix
}
}
/***************************************************************************/
// CALIBRATION
/***************************************************************************/
void calibration() // calibration of period
{
long hi_temp=0, low_temp=0;
while( input(PIN_C4)) {} // wait fall edge on C4
while( !input(PIN_C4)) {} // wait rise edge on C4
while( input(PIN_C4)) // while HI count+1
{
hi_temp++;
}
while( !input(PIN_C4)) // while LOW count+1
{
low_temp++;
}
period=(low_temp+hi_temp); // period is sum of increments in hi and low |
|