Detected Iteration Above Threshold in Unit Time. Check if Frequency (iteration count in Unit time) above Threshold. CATION. max interval is 0xfff0: 65,520ms. max iter threshold is 0xffff. (threfore, using 131KB with span[0xffff].)

Dependencies:   myTimer

Committer:
AkinoriHashimoto
Date:
Fri Oct 09 07:39:13 2015 +0000
Revision:
1:6ab4e8504d60
Parent:
0:7672973d6bed
1st publish.; test term.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkinoriHashimoto 0:7672973d6bed 1 #include "DetectFreqAboveTH.h"
AkinoriHashimoto 0:7672973d6bed 2
AkinoriHashimoto 1:6ab4e8504d60 3 //extern DigitalOut led[];
AkinoriHashimoto 0:7672973d6bed 4
AkinoriHashimoto 0:7672973d6bed 5 DetectFreqAboveTH::DetectFreqAboveTH(int time_ms, int iter)
AkinoriHashimoto 0:7672973d6bed 6 {
AkinoriHashimoto 1:6ab4e8504d60 7 // led[0]= 1;
AkinoriHashimoto 0:7672973d6bed 8 unitTime= time_ms;
AkinoriHashimoto 0:7672973d6bed 9 iterThreshold= iter;
AkinoriHashimoto 0:7672973d6bed 10 span= new unsigned short[iter];
AkinoriHashimoto 0:7672973d6bed 11 //init
AkinoriHashimoto 0:7672973d6bed 12 for(id= 0; id < iterThreshold; id++)
AkinoriHashimoto 0:7672973d6bed 13 span[id]= 0xffff;
AkinoriHashimoto 0:7672973d6bed 14 this->timer.start(true);
AkinoriHashimoto 0:7672973d6bed 15 id= 0;
AkinoriHashimoto 1:6ab4e8504d60 16 // led[1]= 1;
AkinoriHashimoto 0:7672973d6bed 17 }
AkinoriHashimoto 0:7672973d6bed 18
AkinoriHashimoto 0:7672973d6bed 19 DetectFreqAboveTH::~DetectFreqAboveTH()
AkinoriHashimoto 0:7672973d6bed 20 {
AkinoriHashimoto 0:7672973d6bed 21 delete [] span;
AkinoriHashimoto 0:7672973d6bed 22 }
AkinoriHashimoto 0:7672973d6bed 23
AkinoriHashimoto 0:7672973d6bed 24
AkinoriHashimoto 0:7672973d6bed 25 bool DetectFreqAboveTH::chkAbove()
AkinoriHashimoto 0:7672973d6bed 26 {
AkinoriHashimoto 0:7672973d6bed 27 int tmpSpan= this->timer.read_ms(); //reset
AkinoriHashimoto 0:7672973d6bed 28
AkinoriHashimoto 0:7672973d6bed 29 if(tmpSpan > 0xfff0) // 65,520ms.
AkinoriHashimoto 0:7672973d6bed 30 tmpSpan= 0xffff;
AkinoriHashimoto 0:7672973d6bed 31
AkinoriHashimoto 0:7672973d6bed 32 span[id]= tmpSpan;
AkinoriHashimoto 0:7672973d6bed 33 id++;
AkinoriHashimoto 0:7672973d6bed 34 id %= iterThreshold;
AkinoriHashimoto 0:7672973d6bed 35 if(tmpSpan == 0xffff)
AkinoriHashimoto 0:7672973d6bed 36 return false;
AkinoriHashimoto 0:7672973d6bed 37
AkinoriHashimoto 0:7672973d6bed 38 unsigned int sum= 0, tmp;
AkinoriHashimoto 0:7672973d6bed 39 for(int i= 0; i < iterThreshold; i++) {
AkinoriHashimoto 0:7672973d6bed 40 tmp= span[i];
AkinoriHashimoto 0:7672973d6bed 41 if(tmp == 0xffff) // under threshold iter count.
AkinoriHashimoto 0:7672973d6bed 42 return false;
AkinoriHashimoto 0:7672973d6bed 43 sum += tmp;
AkinoriHashimoto 0:7672973d6bed 44 if(sum >= unitTime)
AkinoriHashimoto 0:7672973d6bed 45 return false;
AkinoriHashimoto 0:7672973d6bed 46 }
AkinoriHashimoto 0:7672973d6bed 47 // sumが単位時間未満なので、発生回数(/単位時間)は閾値以上。
AkinoriHashimoto 0:7672973d6bed 48 return true;
AkinoriHashimoto 0:7672973d6bed 49 }
AkinoriHashimoto 0:7672973d6bed 50
AkinoriHashimoto 0:7672973d6bed 51 // EOF