speed code
Dependencies: mbed
Diff: interupts.h
- Revision:
- 1:f4e3365155e1
diff -r e79700919e2e -r f4e3365155e1 interupts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interupts.h Sun Oct 18 18:23:58 2015 +0000 @@ -0,0 +1,103 @@ + +int HEPulse(int let,int num, int order) //tell us which hall effect HEA1= hall effect, (let, A=1, B=2), (num, 1/2), order (index possition to be filled alternates) +{ + float fA1; + float fA2; + float fB1; + float fB2; + int time; + time = timer.read_us(); //use to check for interrupt debounce + + if((tA1[0]-time<10)||(tA2[0]-time<10)||(tA1[1]-time<10)||(tA2[1]-time<10)) { + return 1; + } // if less than 10us from last interupt assume debouce and ignore + //find right thing to do for current hall effect + switch(order) { //check whether to fill index possition 0/1 + case(1) : + switch(let) { //check hall effect A/B + case(1): + + switch(num) { //check hall effect 1/2 + case (1): + tA1[0] = timer.read_us(); + distanceA += (wheelc/6); //increment distance + pulse_orderA = 2; //toggle index to be filled + break; + + case(2) : + tA2[0] = timer.read_us(); + pulse_orderA = 2; + break; + } + break; + + + case(2): //check hall effect A/B + + switch(num) { + case (1): + tB1[0] = timer.read_us(); + distanceB += (wheelc/6); + pulse_orderB = 2; + break; + + case(2) : + tB2[0] = timer.read_us(); + pulse_orderB = 2; + break; + } + break; + + } + case(2) : + switch(let) { + case(1): + + switch(num) { + case (1): + tA1[1] = timer.read_us(); + distanceA += (wheelc/6); + fA1 = 1.0f/(( fabsf(tA1[1]-tA1[0]) ) * (float)3.0E-6); + pulse_orderA = 1; + break; + + case(2) : + tA2[1] = timer.read_us(); + fA2 = 1.0f/(( fabsf(tA2[1]-tA2[0]) ) * (float)3.0E-6); + pulse_orderA = 1; + break; + } + break; + + + case(2): + + switch(num) { + case (1): + tB1[1] = timer.read_us(); + distanceB += (wheelc/6); + fB1 = 1.0f/(( fabsf(tB1[1]-tB1[0]) ) * (float)3.0E-6); + pulse_orderB = 1; + break; + + case(2) : + tB2[1] = timer.read_us(); + fB2 = 1.0f/((fabsf( tB2[1]-tB2[0]) ) * (float)3.0E-6); + pulse_orderB = 1; + break; + } + break; + + } + + float fA = (fA1 + fA2)*0.5f; //calculate average frequency of hall effect A + float fB = (fB1 + fB2)*0.5f; //calculate average frequency of hall effect B + speedA = fA/20.8f; //output speeds of motors by frequency/gear box ratio + speedB = fB/20.8f; + + return 1; + } + + + +