![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
nicer code
Dependencies: mbed
Fork of 161015 by
interupts.h
- Committer:
- benparkes
- Date:
- 2015-10-18
- Revision:
- 1:f4e3365155e1
File content as of revision 1:f4e3365155e1:
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; }