CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

few samples with ADXL213??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fbighouse



Joined: 11 Jan 2007
Posts: 2
Location: Brazil

View user's profile Send private message MSN Messenger

few samples with ADXL213??
PostPosted: Thu Jan 18, 2007 8:19 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 19, 2007 3:00 pm     Reply with quote

Look at the CCS example file which shows how to two CCP modules
to measure a pulse width:
c:\program files\picc\examples\ex_ccpmp.c

There is a Microchip Tips 'n Tricks article that describes how to do it
with one CCP module by switching to detect the falling edge after the
rising edge has been detected:
http://ww1.microchip.com/downloads/en/DeviceDoc/41214a.pdf
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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