I am having problems setting the number of samples to be captured after and before event in triggered fifo mode.
For example if I put adxl372_Configure_FIFO(&adxl372, 300, TRIGGERED, X_FIFO); I get a total of 300 samples after the trigger and not 212 before and 300 after as it should be the case according to the datasheet. (For example if the FIFO_SAMPLE is set to 12, there are 500 samples before the trigger and 12 after the trigger.)
adxl372_Set_Op_mode(&adxl372, STAND_BY); adxl372_Set_Autosleep(&adxl372, false); adxl372_Set_BandWidth(&adxl372, BW_3200Hz); adxl372_Set_ODR(&adxl372, ODR_6400Hz); adxl372_Set_WakeUp_Rate(&adxl372, WUR_52ms); adxl372_Set_Act_Proc_Mode(&adxl372, LOOPED); adxl372_Set_InstaOn_Thresh(&adxl372, ADXL_INSTAON_HIGH_THRESH); adxl372_Disable_Hpf(&adxl372, true); adxl372_Disable_Lpf(&adxl372, true); adxl372_Configure_FIFO(&adxl372, 300, TRIGGERED, X_FIFO); /* Set activity/inactivity threshold */ //adxl372_Set_Activity_Threshold(&adxl372, ACT_VALUE, true, true); //adxl372_Set_Inactivity_Threshold(&adxl372, INACT_VALUE, true, true); /* Set activity/inactivity time settings */ //adxl372_Set_Activity_Time(&adxl372, ACT_TIMER); //adxl372_Set_Inactivity_Time(&adxl372, INACT_TIMER); adxl_write_reg(&adxl372,0x33,0xE3); //0.7g activity treshold int2 pinu adxl_write_reg(&adxl372,0x3C,0x20); //motion warning int2 /* Set instant-on interrupts and activity interrupts */ adxl372_Set_Interrupts(&adxl372); /* Set filter settle time */ adxl372_Set_Filter_Settle(&adxl372, FILTER_SETTLE_16); adxl372_Set_Op_mode(&adxl372, INSTANT_ON);
Can somebody tell me what could go wrong with this?
Sorry for the late reply. When you set 300 to FIFO_SAMPLE register in triggered mode, you should get 300 samples after the trigger event and 212 before the trigger. You said you have 300 samples after the trigger, it seems correct, but is that a typo?
Yeah but how do I get the 212 samples before the trigger. If I understand crrectly I should get in total of 512 samples which of them 300 are after the trigger. Whhen I read fifo on watermark interrupt I only get total of 300 samples after the trigger...
Watermark interrupt is based on FIFO_SAMPLE, so when the interrupt triggers, there's only 300 samples in the FIFO. If you want to read the entire FIFO content, you have to wait until the FIFO is filled, you can use FIFO Overrun interrupt in this case.
So the FIFO FULL interrupt is irrelevant if you are using an activity triggered mode? Say I write FIFO_SAMPLE with 100, this means that there will be 100 samples stored in the FIFO after the activity trigger occurs. But I end up getting the FIFO FULL interrupt (when enabled) all the time since it stores 412 samples for the pre trigger buffer (And since it is >= FIFO_SAMPLE it triggers the interrupt). So I think I will take your advice and just use the FIFO overrun interrupt. In triggered mode, when that FIFO overrun interrupt occurs, this means that new data has overwritten the oldest data in the FIFO? My goal is to be able to detect the activity interrupt, detect the FIFO is full, then read all the data from the FIFO. If I want to preserve as much data as possible, should I put it in standby mode as soon as I get the overrun interrupt? I am wanting to use triggered mode, but have the FIFO stop when it is full (maybe this is how it works?)
In the datasheet I did not see anything about this, but I assume the axes are stored X,Y,Z in the fifo, with the high byte stored first for each axis. I also saw that I need to leave at least one sample (if the device is in multi axes mode) in the FIFO when reading to prevent data corruption.
Update: So I am getting the overrun interrupt continuously while I am waiting for activity. I guess this is expected since the FIFO will fill up in the "trigger mode", if you think of it like a scope trigger. Then when activity comes in, it will fill the samples after the trigger. To alleviate this I think I will need to disable the overrun interrupt , and then enable it when I get the activity interrupt. After I read the data from the FIFO, disable the overrun interrupt again.