//ECE 476 Final Project // Yiyin Ma // Abby Lin // May 2007 #include #include #include #include //NOTE: We used 14-2 fixed point. #define begin { #define end } #define tdeb 30 #define tvel 30 #define xmax 27 #define ymax 15 //State machine state names #define NoPush 1 #define MaybePush 2 #define Pushed 3 #define MaybeNoPush 4 unsigned int count, counter; unsigned char idle, change; int firstNorm, min0, min1, min2, min3; unsigned char min0x, min0y, min1x, min1y, min2x, min2y, min3x, min3y; unsigned char currx, curry, lastx, lasty, oldx, oldy; signed int changex, changey; unsigned char x; unsigned char y; int temp[6]; int Ain[6]; unsigned char Aold3[6], Aold2[6], Aold1[6], Acurr[6]; //raw A to D number char unsigned char done; unsigned int timedeb, timevel; unsigned char draw, left, right, lastright, lastleft; //button flags unsigned char button, lastbut; unsigned char PushState; flash int record[xmax][ymax][6] = {//calibration matrix 4, 4, 8, 66, 8, 68, //x=0 4, 4, 8, 60, 8, 84, 4, 4, 8, 52, 12, 104, 4, 4, 8, 44, 12, 136, 4, 4, 7, 36, 16, 173, 4, 4, 4, 32, 17, 204, 4, 4, 4, 28, 20, 248, 4, 4, 4, 24, 24, 264, 8, 4, 4, 20, 28, 252, 8, 4, 4, 20, 33, 217, 8, 1, 4, 16, 41, 164, 8, 3, 4, 12, 48, 133, 8, 3, 4, 12, 56, 105, 8, 1, 4, 9, 64, 84, 8, 0, 0, 8, 68, 65, 4, 4, 8, 80, 8, 60, //x=1 4, 4, 8, 72, 9, 72, 4, 4, 8, 60, 12, 88, 4, 4, 8, 52, 13, 104, 4, 4, 8, 44, 16, 124, 4, 4, 8, 36, 20, 148, 4, 2, 4, 32, 24, 164, 8, 1, 4, 28, 28, 173, 8, 4, 4, 24, 32, 164, 8, 4, 4, 20, 40, 152, 8, 4, 4, 16, 48, 128, 8, 3, 4, 13, 54, 108, 8, 4, 4, 12, 64, 88, 8, 3, 4, 12, 72, 76, 8, 0, 3, 8, 84, 60, 4, 4, 8, 96, 8, 52, //x=2 4, 4, 8, 84, 12, 64, 4, 4, 8, 72, 12, 73, 4, 4, 8, 60, 16, 88, 4, 4, 8, 48, 17, 100, 6, 4, 8, 40, 22, 108, 8, 4, 8, 36, 24, 120, 8, 4, 8, 32, 28, 120, 8, 4, 4, 24, 36, 116, 8, 4, 4, 21, 44, 108, 12, 4, 4, 16, 56, 92, 12, 4, 4, 16, 64, 84, 12, 4, 4, 12, 80, 72, 12, 4, 4, 12, 96, 64, 12, 4, 4, 9, 116, 52, 4, 4, 12, 132, 8, 44, //x=3 4, 4, 12, 112, 12, 52, 4, 4, 12, 88, 12, 60, 7, 4, 12, 72, 16, 68, 8, 4, 9, 58, 20, 76, 8, 4, 8, 48, 24, 84, 8, 4, 8, 40, 28, 88, 8, 4, 8, 32, 32, 91, 8, 4, 8, 28, 40, 88, 12, 4, 5, 24, 48, 84, 12, 4, 4, 20, 59, 80, 12, 4, 4, 16, 72, 68, 12, 4, 4, 12, 92, 60, 12, 4, 4, 12, 112, 52, 13, 4, 4, 9, 144, 44, 4, 4, 13, 156, 10, 40, //x=4 6, 4, 16, 133, 12, 44, 8, 4, 12, 104, 12, 48, 8, 4, 12, 84, 16, 52, 8, 4, 12, 64, 20, 60, 8, 4, 12, 52, 24, 68, 8, 4, 8, 44, 28, 69, 12, 4, 8, 36, 36, 68, 12, 4, 8, 28, 43, 68, 12, 4, 8, 24, 52, 64, 12, 4, 7, 20, 68, 60, 12, 4, 4, 16, 84, 56, 16, 4, 4, 16, 101, 52, 16, 4, 4, 12, 148, 44, 16, 4, 4, 12, 188, 40, 4, 4, 16, 225, 8, 32, //x=5 4, 4, 16, 168, 10, 36, 8, 4, 16, 120, 12, 40, 8, 4, 16, 89, 16, 45, 8, 4, 13, 72, 20, 48, 8, 4, 12, 60, 24, 52, 9, 4, 12, 44, 28, 55, 12, 4, 12, 36, 36, 56, 12, 4, 8, 32, 44, 56, 12, 4, 8, 24, 56, 52, 16, 4, 8, 20, 72, 48, 16, 4, 7, 16, 92, 44, 16, 4, 5, 16, 116, 42, 20, 4, 4, 12, 172, 36, 20, 4, 4, 12, 268, 32, 4, 4, 20, 276, 9, 30, //=6 7, 8, 20, 192, 12, 36, 8, 8, 20, 144, 12, 36, 8, 8, 16, 100, 16, 40, 8, 4, 16, 72, 20, 40, 10, 4, 16, 60, 24, 44, 12, 4, 12, 48, 28, 44, 12, 4, 12, 38, 36, 44, 14, 4, 12, 32, 45, 44, 16, 4, 8, 24, 60, 40, 16, 4, 8, 20, 74, 40, 20, 4, 8, 17, 100, 38, 20, 4, 6, 16, 132, 36, 20, 4, 4, 12, 200, 32, 24, 4, 4, 12, 316, 28, 8, 4, 24, 320, 8, 24, //x=7 8, 4, 24, 200, 12, 28, 8, 4, 20, 132, 12, 32, 8, 4, 20, 104, 16, 32, 12, 4, 19, 76, 20, 32, 12, 4, 16, 61, 24, 36, 12, 4, 16, 48, 28, 36, 16, 4, 12, 40, 36, 36, 16, 4, 12, 32, 48, 36, 17, 4, 9, 25, 60, 36, 20, 4, 8, 20, 76, 35, 20, 4, 8, 16, 100, 32, 24, 4, 8, 16, 144, 28, 26, 4, 5, 12, 218, 28, 28, 4, 4, 10, 400, 24, 8, 4, 32, 304, 8, 20, //x=8 8, 8, 28, 208, 8, 24, 8, 8, 24, 140, 12, 28, 9, 4, 24, 100, 16, 28, 9, 4, 24, 100, 16, 28, 12, 4, 20, 60, 24, 28, 16, 4, 16, 48, 29, 28, 16, 4, 16, 36, 36, 28, 20, 4, 12, 32, 48, 28, 20, 4, 12, 24, 60, 28, 24, 4, 10, 20, 76, 28, 25, 4, 8, 16, 100, 24, 28, 4, 8, 16, 136, 24, 32, 4, 8, 12, 224, 24, 35, 4, 4, 12, 344, 20, 8, 4, 36, 252, 8, 20, //x=9 8, 8, 36, 180, 12, 20, 8, 6, 32, 130, 12, 20, 12, 4, 28, 92, 16, 24, 12, 8, 24, 72, 20, 24, 16, 8, 20, 56, 24, 24, 16, 8, 20, 44, 32, 24, 20, 8, 16, 40, 36, 24, 20, 8, 16, 32, 44, 24, 24, 6, 12, 26, 52, 24, 28, 8, 12, 20, 72, 24, 32, 8, 8, 16, 92, 23, 33, 4, 8, 16, 129, 20, 36, 4, 8, 12, 192, 20, 40, 4, 6, 11, 287, 16, 8, 8, 44, 220, 8, 16, //x=10 9, 8, 40, 148, 12, 16, 12, 8, 38, 112, 12, 16, 12, 8, 33, 88, 16, 20, 12, 8, 32, 72, 18, 20, 16, 8, 28, 56, 20, 20, 17, 8, 24, 48, 28, 20, 20, 8, 20, 40, 32, 20, 24, 8, 16, 28, 44, 20, 28, 8, 14, 24, 56, 20, 32, 8, 12, 20, 68, 20, 36, 8, 12, 16, 84, 20, 42, 8, 8, 15, 116, 16, 44, 8, 8, 12, 152, 16, 52, 8, 8, 12, 232, 16, 8, 8, 52, 145, 8, 12, //x=11 11, 8, 48, 120, 10, 16, 12, 8, 44, 92, 12, 16, 12, 8, 36, 76, 16, 16, 16, 8, 32, 61, 17, 16, 18, 20, 28, 48, 23, 28, 20, 8, 24, 40, 28, 16, 24, 8, 20, 32, 32, 16, 28, 8, 20, 28, 40, 16, 32, 8, 16, 24, 48, 16, 36, 8, 12, 20, 60, 16, 44, 8, 12, 16, 76, 16, 48, 8, 8, 16, 96, 16, 52, 8, 8, 12, 124, 15, 64, 8, 8, 9, 164, 12, 8, 8, 70, 124, 8, 12, 12, 10, 64, 100, 8, 12, //x=12 12, 11, 56, 80, 12, 12, 15, 12, 48, 68, 12, 12, 16, 12, 40, 56, 16, 13, 20, 12, 36, 44, 20, 12, 24, 12, 28, 36, 24, 16, 28, 12, 24, 32, 28, 16, 32, 12, 20, 28, 36, 16, 36, 12, 16, 24, 44, 16, 44, 12, 16, 20, 56, 13, 48, 12, 12, 16, 68, 13, 60, 8, 10, 12, 92, 12, 72, 8, 8, 12, 100, 12, 80, 8, 8, 11, 123, 12, 8, 12, 92, 96, 8, 10, //x=13 12, 12, 76, 80, 8, 11, 12, 12, 64, 68, 10, 12, 16, 12, 56, 58, 12, 12, 16, 12, 48, 49, 16, 12, 20, 12, 37, 40, 20, 12, 24, 12, 32, 36, 23, 12, 28, 12, 28, 28, 28, 12, 36, 12, 22, 24, 32, 12, 44, 12, 20, 20, 40, 12, 48, 12, 16, 18, 48, 12, 60, 12, 13, 16, 56, 12, 68, 12, 12, 12, 68, 12, 84, 12, 8, 12, 84, 9, 96, 8, 8, 10, 100, 8, 12, 12, 115, 72, 8, 8, //x=14 12, 12, 92, 68, 8, 8, 12, 12, 76, 60, 11, 8, 16, 12, 64, 48, 12, 8, 20, 16, 52, 44, 15, 9, 24, 16, 44, 36, 16, 11, 28, 16, 36, 32, 20, 10, 32, 16, 29, 28, 24, 10, 39, 13, 24, 24, 28, 12, 44, 16, 20, 20, 36, 12, 60, 13, 16, 16, 44, 9, 68, 13, 15, 16, 48, 9, 84, 12, 12, 12, 60, 9, 100, 12, 12, 12, 64, 8, 124, 12, 8, 9, 80, 8, 12, 12, 144, 60, 8, 8, //x=15 12, 13, 112, 56, 8, 8, 16, 16, 89, 48, 9, 8, 16, 16, 72, 40, 12, 8, 20, 16, 56, 36, 12, 8, 24, 16, 48, 32, 16, 8, 28, 16, 40, 28, 20, 8, 36, 16, 32, 24, 23, 9, 44, 16, 28, 20, 28, 8, 52, 16, 24, 16, 32, 8, 67, 16, 16, 16, 36, 8, 80, 16, 16, 14, 43, 8, 102, 16, 12, 12, 48, 8, 124, 16, 12, 9, 52, 8, 156, 12, 8, 8, 64, 8, 12, 16, 176, 50, 8, 8, //x=16 12, 16, 136, 44, 8, 8, 16, 16, 102, 40, 8, 8, 19, 20, 80, 36, 12, 8, 20, 20, 60, 32, 12, 8, 28, 20, 48, 28, 16, 8, 32, 20, 40, 24, 16, 8, 36, 20, 36, 21, 20, 8, 44, 20, 28, 20, 24, 8, 56, 20, 24, 16, 28, 8, 72, 20, 20, 15, 32, 8, 88, 20, 16, 12, 36, 8, 112, 20, 12, 12, 40, 8, 150, 16, 12, 8, 44, 8, 224, 16, 8, 8, 48, 8, 12, 16, 252, 41, 4, 4, //x=17 12, 20, 172, 40, 8, 5, 16, 20, 116, 32, 8, 8, 20, 24, 90, 32, 8, 8, 20, 24, 68, 28, 12, 8, 28, 24, 56, 24, 12, 8, 32, 24, 44, 20, 16, 8, 40, 24, 36, 20, 16, 8, 48, 24, 28, 16, 20, 8, 60, 24, 24, 16, 24, 8, 76, 24, 20, 12, 28, 8, 95, 24, 16, 12, 28, 8, 132, 20, 12, 12, 32, 8, 192, 20, 12, 8, 36, 8, 288, 20, 8, 8, 36, 4, 12, 20, 328, 32, 8, 4, //x=18 12, 24, 196, 32, 7, 4, 16, 24, 132, 28, 8, 4, 19, 28, 96, 28, 8, 4, 20, 28, 76, 24, 10, 4, 24, 28, 56, 20, 12, 5, 32, 28, 48, 20, 12, 4, 36, 30, 36, 17, 16, 4, 48, 32, 28, 16, 16, 5, 60, 28, 24, 13, 20, 4, 76, 28, 20, 12, 24, 4, 100, 28, 16, 12, 24, 4, 133, 24, 16, 8, 28, 4, 204, 24, 12, 8, 32, 4, 356, 24, 8, 8, 32, 4, 12, 24, 300, 28, 6, 4, //x=19 16, 28, 180, 28, 8, 4, 16, 28, 140, 24, 8, 4, 20, 32, 92, 24, 8, 4, 24, 32, 72, 20, 12, 4, 28, 36, 56, 20, 12, 4, 32, 36, 44, 16, 12, 4, 40, 36, 36, 16, 12, 4, 48, 39, 28, 12, 16, 4, 64, 36, 24, 12, 16, 4, 79, 36, 20, 12, 20, 4, 100, 32, 16, 12, 20, 4, 136, 32, 13, 8, 24, 4, 208, 28, 12, 8, 27, 4, 376, 28, 12, 8, 28, 4, 12, 32, 232, 24, 4, 4, //x=20 12, 32, 180, 22, 4, 4, 16, 36, 132, 20, 4, 4, 20, 40, 92, 20, 8, 4, 20, 40, 72, 16, 8, 4, 25, 44, 56, 16, 8, 4, 30, 45, 48, 16, 8, 4, 40, 48, 36, 12, 12, 4, 44, 44, 32, 12, 12, 4, 60, 44, 24, 12, 16, 4, 73, 40, 20, 11, 16, 4, 100, 40, 16, 8, 20, 4, 124, 36, 16, 8, 20, 4, 196, 32, 12, 8, 20, 4, 308, 32, 12, 8, 20, 4, 12, 36, 220, 20, 4, 4, //x=21 16, 40, 148, 20, 4, 4, 16, 44, 116, 19, 4, 4, 19, 48, 88, 16, 4, 4, 20, 52, 68, 16, 7, 4, 24, 56, 56, 16, 8, 4, 32, 56, 44, 12, 8, 4, 40, 56, 36, 12, 10, 4, 48, 56, 28, 12, 12, 4, 60, 56, 24, 11, 12, 4, 76, 52, 20, 8, 16, 4, 92, 48, 16, 8, 16, 4, 124, 44, 12, 8, 16, 4, 160, 44, 12, 8, 16, 4, 252, 36, 9, 8, 16, 4, 12, 40, 168, 16, 4, 4, //x=22 12, 48, 132, 16, 4, 4, 16, 52, 100, 16, 4, 4, 18, 60, 76, 15, 4, 4, 20, 64, 60, 12, 4, 4, 24, 68, 52, 12, 6, 4, 30, 72, 40, 12, 8, 4, 36, 72, 35, 12, 8, 4, 44, 68, 28, 9, 8, 4, 52, 70, 24, 8, 8, 4, 64, 64, 20, 8, 12, 4, 88, 58, 16, 8, 12, 4, 112, 52, 12, 8, 12, 4, 144, 44, 12, 5, 13, 4, 192, 40, 8, 5, 16, 4, 12, 48, 136, 16, 1, 4, //x=23 12, 56, 104, 12, 4, 4, 16, 64, 88, 12, 4, 4, 16, 72, 68, 12, 4, 4, 20, 80, 56, 12, 4, 4, 24, 88, 48, 12, 4, 4, 28, 96, 39, 10, 6, 4, 36, 96, 32, 11, 8, 4, 44, 89, 24, 8, 8, 4, 52, 91, 20, 8, 8, 4, 63, 84, 17, 8, 8, 4, 76, 72, 16, 8, 8, 4, 96, 61, 12, 6, 12, 4, 120, 52, 11, 4, 12, 4, 156, 44, 8, 4, 12, 4, 12, 56, 104, 12, 0, 4, //x=24 12, 64, 84, 12, 3, 4, 15, 76, 72, 12, 4, 4, 16, 88, 60, 12, 4, 4, 20, 100, 52, 12, 4, 4, 24, 114, 44, 10, 4, 4, 28, 124, 36, 8, 4, 4, 32, 124, 28, 8, 4, 4, 36, 120, 24, 8, 6, 4, 44, 112, 20, 8, 8, 4, 56, 100, 16, 8, 8, 4, 64, 88, 16, 6, 8, 4, 80, 76, 12, 4, 8, 4, 92, 64, 8, 4, 8, 3, 115, 52, 8, 4, 9, 3, 8, 60, 84, 12, 0, 4, //x=25 12, 76, 72, 12, 0, 4, 12, 92, 60, 9, 0, 4, 16, 112, 52, 8, 4, 4, 16, 132, 44, 8, 4, 4, 20, 156, 36, 8, 4, 4, 24, 176, 32, 8, 4, 4, 28, 184, 28, 8, 4, 4, 32, 172, 23, 8, 4, 4, 40, 156, 20, 8, 4, 3, 48, 135, 16, 7, 4, 4, 56, 112, 12, 4, 6, 4, 64, 92, 12, 4, 8, 3, 76, 76, 8, 4, 8, 4, 87, 60, 8, 4, 8, 0, 8, 68, 68, 8, 0, 2, //x=26 12, 84, 60, 8, 0, 1, 12, 107, 52, 8, 0, 3, 16, 140, 44, 8, 0, 0, 16, 176, 40, 8, 2, 0, 20, 220, 32, 8, 4, 0, 24, 272, 28, 8, 4, 3, 28, 300, 24, 8, 4, 2, 32, 284, 20, 4, 4, 0, 36, 224, 16, 7, 4, 4, 41, 184, 16, 4, 4, 0, 48, 144, 12, 4, 4, 1, 56, 109, 8, 4, 4, 4, 64, 84, 8, 4, 4, 2, 72, 68, 8, 4, 5, 0}; //tasks void debounce(void); void main(void) begin lastx=0; lasty=0; idle=0; count=0; counter=0; //init the A to D converter //channel zero/ left adj /EXTERNAL Aref //!!!CONNECT Aref jumper!!!! ADMUX = 0b01100000; //enable ADC and set prescaler to 1/128*16MHz=125,000 //and clear interupt enable //and start a conversion ADCSR = 0b11001111; //init PORTs for input/output DDRC = 0x00; PORTC=0xff; DDRB= 0xff; PORTB=0; PORTD=0; DDRD=0xff; DDRA= 0b11000000; PORTA = 0; //init button flags //connect left button to PINC0 // connect right button to pin c1 // connect center draw button to pin c2 draw = 0; left=0; right=0; lastright=1; lastleft=1; done=0; lastx=0; lasty=0; //init counters and state timedeb=tdeb; timevel=tvel; PushState=1; //set up timer 0 OCR0=249; //1 mSec TIMSK=2; //turn on timer 0 cmp-match ISR TCCR0=0b00001011; //prescalar to 64 and Clr-on-match #asm sei #endasm while (1) begin if(timedeb==0) debounce(); //change PORTA output if buttons change if(left!=lastleft) { PORTA = 0b01000000 & (left<<6); lastleft=left; } if(right!=lastright) { PORTA=0b10000000 & (right<<7); lastright=right; } if(done==1) //when ADC finished taking all 6 Hall values { //initial condition min0=3000; min0x=50; min0y=50; //sum up 4 cycles of ADC values Ain[0]=(int)Aold3[0]+(int)Aold2[0]+(int)Aold1[0]+(int)Acurr[0]; Ain[1]=(int)Aold3[1]+(int)Aold2[1]+(int)Aold1[1]+(int)Acurr[1]; Ain[2]=(int)Aold3[2]+(int)Aold2[2]+(int)Aold1[2]+(int)Acurr[2]; Ain[3]=(int)Aold3[3]+(int)Aold2[3]+(int)Aold1[3]+(int)Acurr[3]; Ain[4]=(int)Aold3[4]+(int)Aold2[4]+(int)Aold1[4]+(int)Acurr[4]; Ain[5]=(int)Aold3[5]+(int)Aold2[5]+(int)Aold1[5]+(int)Acurr[5]; for(x=0; x=16){ idle=1; } currx=min0x; curry=min0y; //calculate displacement if there wasa change if((currx!=lastx) || (curry!=lasty)){ if((oldx!=currx) && (oldy!=curry)){ //both change, calculate both displacements changex=(signed int) ((signed char) currx - (signed char) lastx); changey=(signed int) ((signed char) curry - (signed char) lasty); if(draw==0){//velocity mode if(idle==1){ changex=(signed int)((float) (changex<<6)/16.0); changey=(signed int)((float) (changey<<6)/16.0); counter=0; idle=0; } else{ //calculate velocity changex=(signed int)((float) (changex<<6)/(float) (counter)); changey=(signed int)((float) (changey<<6)/(float) (counter)); counter=0; } } else{ //absolute mode if(idle==1){ changex=changex<<3; changey=changey<<3; } //end idle if } //end else //output the x and y displacements PORTB=(signed char) changex; PORTD=(signed char) changey; oldx=lastx; oldy=lasty; } } lastx=currx; lasty=curry; done=0; ADCSR.6=1; //ready for another ADC } //end done end //end while end //end main //******************************************************* void debounce(void) { timedeb=tdeb; //reset the task timer //distinguish between the different buttons if(~PINC.0 == 1) button = 1; else if(~PINC.2 == 1) button = 2; else if(~PINC.1==1) button=3; else button = 0; switch (PushState) { case NoPush: if (button != 0) PushState=MaybePush; //button pressed else PushState=NoPush; break; case MaybePush: if (button != 0) { lastbut=button; if(button==3){ //toggle draw button if(draw==1){ draw=0; counter=0; } else{ draw=1; counter=0; } } PushState=Pushed; } else PushState=NoPush; break; case Pushed: if (button == lastbut) //button still pressed { if(button==1) left=1; else if(button==2) right=1; PushState=Pushed; } else PushState=MaybeNoPush; break; case MaybeNoPush: if (button == lastbut) PushState=Pushed; //button still pressed else { //clear flags, button not pushed if(lastbut==1) left=0; else if (lastbut==2) right=0; PushState=NoPush; } break; } //end switch } //****************************************************************** interrupt [ADC_INT] void adc_complete(void) { if(done==0){ switch (ADMUX) { case 0b01100000: //first Hall sensor Acurr[0]=ADCH-21; if(Acurr[0]>230) Acurr[0]=0; if(count==0){ //for averaging Aold3[0]=Acurr[0]; } else if(count==1){ Aold2[0]=Acurr[0]; } else if(count==2){ Aold1[0]=Acurr[0]; } ADMUX++; ADCSR.6=1; break; case 0b01100001: //2nd Hall sensor Acurr[1]=ADCH-2; if(Acurr[1]>230) Acurr[1]=0; if(count==0){ //for averaging Aold3[1]=Acurr[1]; } else if(count==1){ Aold2[1]=Acurr[1]; } else if(count==2){ Aold1[1]=Acurr[1]; } ADMUX++; ADCSR.6=1; break; case 0b01100010: //3rd Hall sensor Acurr[2]=ADCH-8; if(Acurr[2]>230) Acurr[2]=0; if(count==0){ //for averaging Aold3[2]=Acurr[2]; } else if(count==1){ Aold2[2]=Acurr[2]; } else if(count==2){ Aold1[2]=Acurr[2]; } ADMUX++; ADCSR.6=1; break; case 0b01100011: //4th Hall sensor Acurr[3]=ADCH-7; if(Acurr[3]>230) Acurr[3]=0; if(count==0){ //for averaging Aold3[3]=Acurr[3]; } else if(count==1){ Aold2[3]=Acurr[3]; } else if(count==2){ Aold1[3]=Acurr[3]; } ADMUX++; ADCSR.6=1; break; case 0b01100100: //5th Hall sensor Acurr[4]=ADCH-13; if(Acurr[4]>230) Acurr[4]=0; if(count==0){ //for averaging Aold3[4]=Acurr[4]; } else if(count==1){ Aold2[4]=Acurr[4]; } else if(count==2){ Aold1[4]=Acurr[4]; } ADMUX++; ADCSR.6=1; break; case 0b01100101: Acurr[5]=ADCH-7; if(Acurr[5]>230) Acurr[5]=0; if(count==0){ //for averaging Aold3[5]=Acurr[5]; count++; ADMUX=0b01100000; ADCSR.6=1; } else if(count==1){ Aold2[5]=Acurr[5]; count++; ADMUX=0b01100000; ADCSR.6=1; } else if(count==2){ Aold1[5]=Acurr[5]; count++; ADMUX=0b01100000; ADCSR.6=1; } else{ count=0; done=1; ADMUX=0b01100000; } break; } } } //******************************************************************** interrupt [TIM0_COMP] void timer0_compare(void) { //decrement times if(timedeb>0) timedeb--; if(timevel>0) timevel--; else if(timevel==0){ //reset time timevel=tvel; counter++; } }