I've been trying to build a vibration sensor with the PIC16F877. The sensor essentially has an tri-axis digital accelerometer using I2C or SPI, an serial EEPROM. The program works for fine for reading the accelerometer data and saving them into the EEPROM. So the most frequeny commands is I2CRead and I2CWrite. My problems is:
1. The sampling rate is two low...only around 100Hz, with reading three axis's data(six bytes), and saving them into the EEPROM with the time(two bytes), the cycle nearly takes 10ms..., I know EEPROM needs around 3~4ms for each writing cycle, so the best, is getting close to 200Hz at least.. So what I was wondering why these I2CReads and I2Cwrites should take such a long time? Where I could find room for Bandwidth improvement if still using EEPROM?
Sen_Re:
PORTB=$FF
while stop_f=0
I2CREAD DPIN,CPIN,SAD_W,XOUT_H,[X.BYTE1] ' Read Sensor's Register
I2CREAD DPIN,CPIN,SAD_W,XOUT_l,[X.BYTE0]
I2CREAD DPIN,CPIN,SAD_W,YOUT_H,[Y.BYTE1]
I2CREAD DPIN,CPIN,SAD_W,YOUT_L,[Y.BYTE0]
I2CREAD DPIN,CPIN,SAD_W,ZOUT_H,[Z.BYTE1]
I2CREAD DPIN,CPIN,SAD_W,ZOUT_L,[Z.BYTE0]
IF X_F || Y_F || Z_F THEN ' If one channel overflows threshold value
HIGH LED4 ' Flash LED4 for illustration
GOSUB SAVE
if add>64000 then stop_f=1
wend
return
SAVE: ' Save data to a 8bytes array
pointer=0
BUFF2[POINTER]=X.BYTE1
POINTER=POINTER+1
BUFF2[POINTER]=X.BYTE0
POINTER=POINTER+1
BUFF2[POINTER]=Y.BYTE1
POINTER=POINTER+1
BUFF2[POINTER]=Y.BYTE0
POINTER=POINTER+1
BUFF2[POINTER]=Z.BYTE1
POINTER=POINTER+1
BUFF2[POINTER]=Z.BYTE0
POINTER=POINTER+1
BUFF2[POINTER]=MINUTE
POINTER=POINTER+1
BUFF2[POINTER]=SECOND
I2CWRITE DPIN,CPIN,CON_B,ADD,[STR buff2\8] ' Write to EEPROM
add=add+8
RETURN
2. The second questions is: How to provide the system with a clock includes a precision to 1/100 second. Using the timer interrupt will generate much error, but most RTC chips only provide best to the second, so how to build a clock, also without using much physical room? I mean on circuit board(Because I am trying to shrink PCB's size)?
You comments and suggestions are greatly appreciated!!!!
Bookmarks