Assa teamet / Mbed 2 deprecated SixstepInInterrupt

Dependencies:   mbed

Revision:
0:8dc0f972a984
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 11 11:28:03 2014 +0000
@@ -0,0 +1,337 @@
+#include "mbed.h"
+// Att gora
+
+// Select pins for 
+// Kolla hur man gar fran string till binary
+
+InterruptIn event1(p15);
+InterruptIn event2(p16);
+InterruptIn event3(p17);
+
+InterruptIn stoppHallEvent1(p13);
+InterruptIn stoppHallEvent2(p14);
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+Ticker VoltStep;
+
+//Directions of rotation (rotor side)
+#define dirClock 0
+#define dirCounter 1
+
+
+int Frequency=100000; //Hz
+int X=0;
+int tim=0;
+char dir;
+int dutyPin;
+//IN funkar: int Voltage1[]={8,17,25,33,42,50,58,67,75,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,79,48,25,19,16,20,26,32,37,39,38,36,33,36,34,34,34,36,38,41,41,40,37,37,34,31,28,27,28,30,32,34,37,41,42,42,41,41,39,36,34,32,31,31,31,31,32,33,34,35,36,38,39,43,43,42,40,36,33,30,29,29,30,32,34,35,36,36,37,38,39,41,42,42,39,36,33,30,29,29,30,32,33,36,37,38,39,39,41,42,41,40,37,35,32,31,30,30,31,33,34,36,37,38,39,41,42,42,41,39,36,33,31,30,30,31,32,34,35,37,38,39,40,41,42,42,40,38,35,32,31,30,31,32,33,35,36,38,39,40,41,42,43,42,39,37,34,32,31,30,31,33,34,36,37,38,39,40,42,43,43,41,39,36,33,31,31,31,32,34,35,37,38,39,40,41,43,43,42,40,37,34,32,31,31,32,33,35,36,38,39,40,41,42,43,43,42,39,36,34,32,31,31,32,34,36,37,39,40,41,42,43,44,43,41,38,35,33,32,31,32,33,35,37,38,39,40,41,43,44,44,43,40,37,34,33,32,32,33,35,36,38,39,40,41,42,44,44,44,41,39,36,34,32,32,33,34,36,37,39,40,41,42,43,44,44,43,40,37,35,33,32,32,33,35,36,38,39,40,42,43,44,45,44,42,39,36,34,33,32,33,34,36,38,39,40,41,42,44,45,45,44,41,0,0,0,0};
+/*IN funkar ej*/ //int Voltage[]={50,58,67,75,83,92,97,92,87,83,82,81,79,77,75,75,77,79,79,78,77,75,73,71,68,66,64,64,64,64,64,64,64,64,64,62,63,65,66,66,66,66,66,66,66,63,63,63,63,64,64,64,64,64,63,62,62,63,64,64,64,64,64,64,64,62,62,62,63,63,63,63,63,63,63,61,62,62,63,63,63,63,63,63,63,61,61,62,62,62,62,62,62,62,62,61,61,62,63,63,63,63,63,63,63,61,61,62,62,63,63,63,63,63,63,61,61,62,62,62,62,62,62,62,62,60,60,61,61,62,62,62,62,62,61,60,60,60,61,61,61,61,61,61,61,59,60,60,60,61,61,61,61,61,61,59,59,60,60,60,60,60,60,60,60,59,59,60,60,60,60,60,60,60,60,59,59,60,60,60,60,60,60,60,60,59,59,60,60,60,60,60,60,60,60,59,59,60,60,61,11,11,11,11,11,9,9,10,10,10,10,10,10,10,10,9,9,9,10,10,10,10,10,10,10,9,9,9,9,10,10,10,10,10,10,8,8,9,9,9,9,9,9,9,9,8,8,8,9,9,9,9,9,9,9,7,7,8,8,8,8,8,8,8,8,7,7,8,8,8,8,8,8,8,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5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,2,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+/*OUT smooth;*/  //int Voltage[]={3,15,25,33,39,39,39,43,47,52,55,56,56,56,55,52,47,47,47,47,47,46,43,40,39,39,35,35,35,36,39,41,41,41,41,41,37,37,37,37,38,39,39,39,39,39,35,35,35,35,37,38,38,38,38,38,34,34,34,34,36,37,37,37,37,37,33,33,33,33,35,36,36,36,36,36,31,31,31,32,34,35,35,35,35,35,31,31,31,32,33,34,34,34,34,34,30,30,30,31,33,34,34,34,34,34,29,29,29,31,32,33,33,33,33,33,28,28,28,30,31,32,32,32,32,32,28,28,28,29,31,32,32,32,32,32,27,27,28,29,31,31,31,31,31,31,27,27,28,29,30,31,31,31,31,31,27,27,27,28,30,30,30,30,30,30,26,26,26,27,28,29,29,29,29,29,25,25,25,26,28,28,28,28,28,28,24,24,25,26,27,27,27,27,27,27,23,23,24,26,27,27,27,27,27,27,24,24,25,26,27,27,27,27,27,27,24,24,25,26,28,28,28,28,28,28,25,25,26,27,28,28,28,28,28,27,25,25,25,26,27,27,27,27,27,26,23,23,24,25,26,26,26,26,26,25,22,22,23,24,24,25,25,25,25,24,21,22,22,23,24,25,25,24,24,24,22,22,22,23,24,25,25,25,25,24,22,22,23,23,24,25,25,25,24,24,22,22,22,23,24,24,24,24,23,23,21,21,21,22,23,23,23,23,23,22,20,20,21,21,22,22,23,23,22,22,20,20,21,21,22,22,22,22,22,22,20,20,21,21,22,23,23,23,23,23,21,21,22,22,23,23,23,23,23,23,22,21,22,22,23,23,23,23,23,22,21,21,21,22,22,22,23,22,22,21,20,20,20,21,21,21,22,21,21,21,20,20,20,20,21,21,21,21,21,21,20,20,21,21,22,22,22,22,22,22,21,21,21,22,22,22,22,22,22,22,21,21,21,21,21,22,22,21,21,21,20,20,20,20,20,21,21,21,20,20,19,19,19,20,20,20,20,20,20,20,19,19,19,20,20,20,21,21,21,21,20,20,20,21,21,22,22,22,22,22,21,21,21,21,21,21,22,21,21,21,20,20,20,20,20,20,20,20,20,20,19,19,19,19,19,20,20,20,19,19,19,19,19,19,20,20,20,20,20,20,19,19,20,20,20,21,21,21,21,21,20,20,20,21,21,21,21,21,21,21,20,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19,19,19,19,19,19,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,19,19,20,20,20,20,20,21,20,20,20,20,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,19,19,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,18,18,18,18,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,13,13,12,11,10,10,10,10,11,10,9,8,8,7,6,6,6,6,7,7,7,7,7,7,7,7,6,6,7,7,7,7,7,7,7,6,5,4,6,6,6,6,6,6,6,5,4,4,5,5,5,5,5,5,5,4,4,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,4,6,6,6,6,6,6,6,5,4,4,5,5,5,5,5,5,5,4,3,3,4,4,4,4,4,4,4,3,3,2,3,3,3,3,3,3,3,3,2,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,0,0,0};
+//int Voltage[]={10,20,28,34,34,34,38,42,47,50,51,51,51,50,47,42,42,42,42,42,41,38,35,34,34,30,30,30,31,34,36,36,36,36,36,32,32,32,32,33,34,34,34,34,34,30,30,30,30,32,33,33,33,33,33,29,29,29,29,31,32,32,32,32,32,28,28,28,28,30,31,31,31,31,31,26,26,26,27,29,30,30,30,30,30,26,26,26,27,28,29,29,29,29,29,25,25,25,26,28,29,29,29,29,29,24,24,24,26,27,28,28,28,28,28,23,23,23,25,26,27,27,27,27,27,23,23,23,24,26,27,27,27,27,27,22,22,23,24,26,26,26,26,26,26,22,22,23,24,25,26,26,26,26,26,22,22,22,23,25,25,25,25,25,25,21,21,21,22,23,24,24,24,24,24,20,20,20,21,23,23,23,23,23,23,19,19,20,21,22,22,22,22,22,22,18,18,19,21,22,22,22,22,22,22,19,19,20,21,22,22,22,22,22,22,19,19,20,21,23,23,23,23,23,23,20,20,21,22,23,23,23,23,23,22,20,20,20,21,22,22,22,22,22,21,18,18,19,20,21,21,21,21,21,20,17,17,18,19,19,20,20,20,20,19,16,17,17,18,19,20,20,19,19,19,17,17,17,18,19,20,20,20,20,19,17,17,18,18,19,20,20,20,19,19,17,17,17,18,19,19,19,19,18,18,16,16,16,17,18,18,18,18,18,17,15,15,16,16,17,17,18,18,17,17,15,15,16,16,17,17,17,17,17,17,15,15,16,16,17,18,18,18,18,18,16,16,17,17,18,18,18,18,18,18,17,16,17,17,18,18,18,18,18,17,16,16,16,17,17,17,18,17,17,16,15,15,15,16,16,16,17,16,16,16,15,15,15,15,16,16,16,16,16,16,15,15,16,16,17,17,17,17,17,17,16,16,16,17,17,17,17,17,17,17,16,16,16,16,16,17,17,16,16,16,15,15,15,15,15,16,16,16,15,15,14,14,14,15,15,15,15,15,15,15,14,14,14,15,15,15,16,16,16,16,15,15,15,16,16,17,17,17,17,17,16,16,16,16,16,16,17,16,16,16,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,15,15,15,14,14,14,14,14,14,15,15,15,15,15,15,14,14,15,15,15,16,16,16,16,16,15,15,15,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,13,14,14,14,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,14,14,15,15,15,15,15,16,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,8,8,7,6,5,5,5,5,0,0,0};
+/*OUT no smooth*/ // int Voltage[]={27,55,83,83,83,83,83,83,83,61,12,0,83,83,83,61,20,0,0,0,0,0,83,83,83,83,59,18,0,0,0,0,83,83,83,82,41,4,0,0,0,0,83,83,83,80,40,4,0,0,0,0,83,83,83,72,34,0,0,0,0,0,83,83,83,67,30,0,0,0,0,0,83,83,83,61,25,0,0,0,0,0,83,83,83,57,22,0,0,0,0,2,83,83,83,53,20,0,0,0,0,0,83,83,83,50,17,0,0,0,0,0,83,83,79,47,16,0,0,0,0,0,83,83,77,46,15,0,0,0,0,0,83,83,74,44,14,0,0,0,0,1,83,83,73,43,14,0,0,0,0,5,83,83,70,41,13,0,0,0,0,2,83,83,63,35,10,0,0,0,0,7,83,80,59,32,7,0,0,0,0,9,83,77,56,30,7,0,0,0,1,10,80,75,55,30,8,0,0,0,3,12,78,73,54,30,9,0,0,0,5,15,77,72,53,30,9,0,0,0,8,23,75,72,54,32,13,0,0,1,9,26,72,67,50,29,10,0,0,1,9,25,68,64,48,28,10,0,0,1,9,26,65,61,46,27,10,0,0,2,9,17,62,58,44,26,11,1,0,4,11,19,62,58,44,26,12,1,0,4,12,19,60,57,44,27,13,4,1,6,13,20,57,53,41,26,12,4,2,6,12,20,55,51,40,25,12,3,2,5,12,18,52,49,38,25,12,4,2,5,12,21,49,47,37,24,13,5,3,7,12,18,48,46,36,24,13,7,5,8,14,19,47,46,37,25,15,9,7,10,15,20,45,43,34,24,15,9,7,10,14,26,43,42,34,24,14,8,7,9,13,24,41,40,33,23,14,9,7,9,13,18,39,38,31,23,15,10,8,10,14,21,39,38,31,23,16,11,9,11,15,21,39,38,32,24,17,13,11,14,17,20,38,36,30,22,15,12,11,12,15,22,35,34,29,21,15,11,10,12,15,19,34,33,28,21,15,12,11,12,15,18,33,32,27,21,16,12,12,13,16,19,33,32,28,22,17,14,13,15,17,20,34,33,29,24,19,15,14,15,16,19,31,30,26,21,17,14,13,14,16,18,30,29,25,20,16,13,13,14,16,18,29,28,24,20,16,13,13,14,16,22,29,28,25,21,17,15,14,15,17,22,29,29,26,22,19,16,16,17,18,20,29,27,24,21,17,15,14,15,17,20,27,26,23,20,17,14,14,14,16,20,26,25,23,19,16,14,14,15,16,20,25,25,23,20,17,15,14,15,17,20,26,25,23,21,18,16,16,17,18,20,27,27,25,22,19,17,16,16,17,20,24,24,22,20,17,16,15,15,16,18,23,23,21,19,17,15,15,15,16,18,23,22,21,19,17,15,15,16,17,18,23,23,22,20,18,16,16,17,18,19,24,24,23,21,19,18,18,19,19,20,23,22,21,19,17,16,16,16,17,19,22,22,20,18,17,16,15,15,16,17,21,21,20,18,17,16,16,16,17,18,21,21,20,19,17,17,16,17,18,20,22,22,21,20,19,18,18,18,19,20,23,23,21,20,18,17,17,17,17,18,21,21,20,18,17,16,16,16,16,17,20,20,19,18,17,16,16,16,16,18,20,20,19,18,17,17,16,17,17,18,21,21,20,19,18,18,18,18,19,19,22,22,22,21,19,18,18,18,18,18,20,20,19,18,17,17,16,16,17,18,19,19,19,18,17,16,16,16,16,17,19,19,18,18,17,16,16,16,17,17,19,19,19,18,18,17,17,18,18,19,21,21,21,20,20,19,19,19,19,19,20,19,19,18,17,17,17,17,17,17,19,18,18,17,17,16,16,16,16,17,18,18,18,17,17,16,16,16,17,17,18,19,18,18,18,17,17,17,18,18,20,20,20,19,19,19,19,19,19,20,20,20,19,18,17,17,17,17,17,17,19,18,18,17,17,16,16,16,16,17,18,18,17,17,17,16,16,16,16,17,18,18,18,17,17,17,17,17,17,18,19,19,19,18,18,18,18,18,19,19,20,20,20,19,19,18,17,17,17,17,18,18,18,17,17,17,16,16,16,16,17,17,17,17,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,20,20,20,19,19,19,18,18,17,18,18,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,17,17,17,17,16,16,16,16,16,17,17,17,17,17,17,17,17,17,18,18,19,19,19,19,19,19,19,19,19,18,18,18,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,17,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,19,19,18,18,17,17,17,16,17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,19,19,19,19,18,18,17,17,17,16,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,18,18,18,18,18,19,18,18,18,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,15,15,15,15,15,16,16,16,16,16,16,15,15,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,18,18,18,18,18,18,18,18,18,17,17,16,16,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,16,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,18,18,18,18,18,18,18,17,17,16,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,18,18,18,18,18,17,17,16,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,18,18,18,17,17,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,0,0,0,0,0,0,3,14,24,27,0,0,0,0,0,0,7,17,24,26,0,0,0,0,0,0,1,11,21,25,0,0,0,0,0,0,0,8,18,24,0,0,0,0,0,0,0,6,14,20,0,0,0,0,0,0,0,5,15,22,0,0,0,0,0,0,0,10,20,25,0,0,0,0,0,0,0,10,19,24,0,0,0,0,0,0,0,3,12,20,0,0,0,0,0,0,0,3,11,19,0,0,0,0,0,0,0,0,7,14,0,0,0,0,0,0,0,0,6,14,0,0,0,0,0,0,0,3,12,19,0,0,0,0,0,0,0,0,8,17,0,0,0,0,0,0,0,4,12,19,0,0,0,0,0,0,0,0,2,9,0,0,0,0};
+//int Voltage[]={0,8,17,17,17,17,17,17,17,17,17,17,25,33,42,47,42,37,33,32,31,29,27,25,25,27,29,29,28,27,25,23,21,18,16,14,14,14,14,14,14,14,14,14,12,13,15,16,16,16,16,16,16,16,13,13,13,13,14,14,14,14,14,13,12,12,13,14,14,14,14,14,14,14,12,12,12,13,13,13,13,13,13,13,11,12,12,13,13,13,13,13,13,13,11,11,12,12,12,12,12,12,12,12,11,11,12,13,13,13,13,13,13,13,11,11,12,12,13,13,13,13,13,13,11,11,12,12,12,12,12,12,12,12,10,10,11,11,12,12,12,12,12,11,10,10,10,11,11,11,11,11,11,11,9,10,10,10,11,11,11,11,11,11,9,9,10,10,10,10,10,10,10,10,9,9,10,10,10,10,10,10,10,10,9,9,10,10,10,10,10,10,10,10,9,9,10,10,10,10,10,10,10,10,9,9,10,10,11,11,11,11,11,11,9,9,10,10,10,10,10,10,10,10,9,9,9,10,10,10,10,10,10,10,9,9,9,9,10,10,10,10,10,10,8,8,9,9,9,9,9,9,9,9,8,8,8,9,9,9,9,9,9,9,7,7,8,8,8,8,8,8,8,8,7,7,8,8,8,8,8,8,8,8,7,7,8,8,8,8,8,8,8,8,7,7,8,8,8,8,8,8,8,8,7,7,8,8,9,9,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6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,2,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+/*Scope91*///int Voltage[]={6,17,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,25,16,9,6,6,8,12,15,19,25,23,19,15,11,9,9,10,12,14,20,20,18,15,12,10,10,10,12,13,18,18,16,14,13,11,11,11,12,13,18,18,17,15,13,12,12,12,13,14,18,18,17,16,15,14,14,14,15,15,18,18,17,15,14,13,12,13,13,14,16,16,15,14,13,12,12,12,12,13,15,15,15,14,13,12,12,12,12,13,15,15,14,14,13,13,12,12,13,13,15,15,15,14,14,14,13,14,14,15,16,16,16,15,15,15,15,15,15,15,16,16,15,14,14,13,13,13,13,14,14,14,14,14,13,13,13,12,13,13,14,14,13,13,13,13,12,12,13,13,13,14,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,13,13,13,13,13,13,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,13,13,13,13,13,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,15,15,15,15,15,14,14,14,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,15,15,15,14,14,14,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,13,13,13,13,12,12,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,13,13,13,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,13,13,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,14,14,13,13,13,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,11,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,12,12,12,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,13,13,13,13,12,12,12,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,12,12,12,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,11,11,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,11,11,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,11,11,11,10,10,10,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,9,9,9,8,8,8,8,8,8,8,8,0,0,0,0,0};
+//int Voltage[]= { 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,9,12,15,17,18,20,26,27,28,28,29,30,30,30,30,31,31,31,31,31,32,32,32,32,32,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,33,33,33,33,33,34,34,34,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,34,34,34,33,33,33,33,33,33,33,32,32,32,31,31,31,30,29,29,29,28,27,27,27,26,26,26,25,24,24,24,24,24,22,21,21,21,21,19,19,18,18,18,18,18,18,19,18,18,18,15,15,15,15,16,17,19,19,19,19,17,17,18,18,18,19,18,18,17,17,19,20,20,20,20,20,20,19,17,17,18,19,20,20,21,21,21,20,20,19,16,16,16,16,16,16,14,14,14,14,16,16,16,16,16,16,16,17,18,18,19,19,19,19,19,19,18,17,17,17,17,18,18,18,19,19,22,22,23,23,22,22,22,23,23,24,24,24,23,23,22,23,23,23,22,22,22,22,22,23,25,26,26,27,27,28,28,28,27,26,26,24,24,24,24,25,25,25,25,25,26,26,27,27,28,28,28,27,24,24,24,24,25,25,25,25,25,24,24,23,21,20,20,20,20,21,21,21,23,23,23,21,21,21,21,21,21,19,19,19,22,22,22,22,21,20,18,18,18,18,19,20,20,21,21,21,21,22,21,21,20,18,17,17,18,18,18,20,20,20,19,19,19,20,20,20,18,18,18,18,20,20,20,20,20,20,20,18,17,17,19,19,19,20,20,21,21,21,21,20,17,17,17,17,18,18,19,19,19,19,21,22,22,22,21,21,20,19,18,19,19,21,22,22,22,23,23,22,21,21,18,18,17,17,17,17,20,20,21,21,20,20,20,21,21,21,21,21,21,21,22,23,24,24,23,23,23,22,21,20,19,19,20,20,20,20,23,23,24,24,22,22,22,21,22,22,22,23,22,22,22,24,23,23,22,22,20,19,19,19,21,22,22,23,23,23,25,24,23,23,21,21,21,20,20,20,21,21,24,24,24,22,22,21,21,20,20,20,20,20,22,22,22,22,22,22,22,20,21,21,21,22,22,22,22,22,22,22,22,22,19,19,19,20,21,22,21,21,20,20,22,22,22,23,23,22,22,20,19,18,19,19,20,20,21,21,21,21,21,21,21,21,21,22,22,23,23,23,25,25,25,28,28,28,28,28,28,27,27,27,30,31,31,31,31,31,31,29,28,28,26,26,26,26,26,26,26,26,26,26,23,22,22,22,22,22,21,20,20,19,22,22,22,22,22,22,22,20,19,18,19,20,20,21,21,21,21,20,20,20,18,18,18,18,18,19,19,20,21,21,21,21,21,20,20,20,20,20,20,20,22,22,22,22,22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,19,19,20,20,21,21,21,21,21,21,21,21,21,21,21,21,20,18,18,18,20,20,20,21,21,21,21,21,21,21,21,22,22,23,23,23,24,24,24,24,25,26,26,27,27,27,26,25,25,25,29,29,29,29,29,28,28,26,25,25,25,25,25,25,26,26,26,26,26,26,22,22,21,21,22,22,22,21,21,21,23,24,24,24,23,23,23,21,20,20,23,23,24,24,24,24,24,23,23,23,21,20,20,20,20,21,21,22,24,24,24,24,24,24,24,24,22,22,22,22,25,25,25,24,24,24,24,23,23,23,25,25,26,26,26,27,27,27,26,26,25,23,23,23,23,23,23,23,23,23,24,25,25,26,26,26,26,24,23,23,24,24,25,25,25,25,24,24,24,24,23,23,23,23,23,24,24,25,28,28,27,27,27,27,27,28,28,28,27,27,28,28,29,29,28,28,27,27,27,27,28,28,28,28,28,28,28,28,28,28,26,25,25,25,25,25,23,22,21,20,19,19,18,18,18,17,16,15,13,13,13,13,13,13,13,13,12,12,12,12,12,11,11,11,11,11,11,10,9,9,9,9,8,8,8,8,8,8,7,7,6,6,6,6,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0};
+//int Voltage[]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,15,16,16,17,17,18,18,19,19,20,20,20,21,21,22,22,22,23,23,24,24,24,25,25,25,25,26,26,26,27,27,27,27,28,28,28,28,29,29,29,30,30,30,30,30,31,31,31,31,31,32,32,32,32,32,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,33,33,33,33,33,34,34,34,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,34,34,34,33,33,33,33,33,33,33,32,32,32,31,31,31,30,29,29,29,28,27,27,27,26,26,26,25,24,24,24,24,24,22,21,21,21,21,19,19,18,18,18,18,18,18,19,18,18,18,15,15,15,15,16,17,19,19,19,19,17,17,18,18,18,19,18,18,17,17,19,20,20,20,20,20,20,19,17,17,18,19,20,20,21,21,21,20,20,19,16,16,16,16,16,16,14,14,14,14,16,16,16,16,16,16,16,17,18,18,19,19,19,19,19,19,18,17,17,17,17,18,18,18,19,19,22,22,23,23,22,22,22,23,23,24,24,24,23,23,22,23,23,23,22,22,22,22,22,23,25,26,26,27,27,28,28,28,27,26,26,24,24,24,24,25,25,25,25,25,26,26,27,27,28,28,28,27,24,24,24,24,25,25,25,25,25,24,24,23,21,20,20,20,20,21,21,21,23,23,23,21,21,21,21,21,21,19,19,19,22,22,22,22,21,20,18,18,18,18,19,20,20,21,21,21,21,22,21,21,20,18,17,17,18,18,18,20,20,20,19,19,19,20,20,20,18,18,18,18,20,20,20,20,20,20,20,18,17,17,19,19,19,20,20,21,21,21,21,20,17,17,17,17,18,18,19,19,19,19,21,22,22,22,21,21,20,19,18,19,19,21,22,22,22,23,23,22,21,21,18,18,17,17,17,17,20,20,21,21,20,20,20,21,21,21,21,21,21,21,22,23,24,24,23,23,23,22,21,20,19,19,20,20,20,20,23,23,24,24,22,22,22,21,22,22,22,23,22,22,22,24,23,23,22,22,20,19,19,19,21,22,22,23,23,23,25,24,23,23,21,21,21,20,20,20,21,21,24,24,24,22,22,21,21,20,20,20,20,20,22,22,22,22,22,22,22,20,21,21,21,22,22,22,22,22,22,22,22,22,19,19,19,20,21,22,21,21,20,20,22,22,22,23,23,22,22,20,19,18,19,19,20,20,21,21,21,21,21,21,21,21,21,22,22,23,23,23,25,25,25,28,28,28,28,28,28,27,27,27,30,31,31,31,31,31,31,29,28,28,26,26,26,26,26,26,26,26,26,26,23,22,22,22,22,22,21,20,20,19,22,22,22,22,22,22,22,20,19,18,19,20,20,21,21,21,21,20,20,20,18,18,18,18,18,19,19,20,21,21,21,21,21,20,20,20,20,20,20,20,22,22,22,22,22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,19,19,20,20,21,21,21,21,21,21,21,21,21,21,21,21,20,18,18,18,20,20,20,21,21,21,21,21,21,21,21,22,22,23,23,23,24,24,24,24,25,26,26,27,27,27,26,25,25,25,29,29,29,29,29,28,28,26,25,25,25,25,25,25,26,26,26,26,26,26,22,22,21,21,22,22,22,21,21,21,23,24,24,24,23,23,23,21,20,20,23,23,24,24,24,24,24,23,23,23,21,20,20,20,20,21,21,22,24,24,24,24,24,24,24,24,22,22,22,22,25,25,25,24,24,24,24,23,23,23,25,25,26,26,26,27,27,27,26,26,25,23,23,23,23,23,23,23,23,23,24,25,25,26,26,26,26,24,23,23,24,24,25,25,25,25,24,24,24,24,23,23,23,23,23,24,24,25,28,28,27,27,27,27,27,28,28,28,27,27,28,28,29,29,28,28,27,27,27,27,28,28,28,28,28,28,28,28,28,28,26,25,25,25,25,25,23,22,21,20,19,19,18,18,18,17,16,15,13,13,13,13,13,13,13,13,12,12,12,12,12,11,11,11,11,11,11,10,9,9,9,9,8,8,8,8,8,8,7,7,6,6,6,6,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0};
+//int Voltage[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,15,16,16,17,17,18,18,19,19,20,20,20,21,21,22,22,22,23,23,24,24,24,25,25,25,25,26,26,26,27,27,27,27,28,28,28,28,29,29,29,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,0,0,0,12,0,13,0,19,0,23,0,8,0,1,0,0,0,0,0,0,0,3,0,1,0,0,0};
+//int Voltage[]={0,3,3,5,5,7,7,9,9,10,10,12,12,13,13,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,22,22,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,27,27,27,28,28,28,28,28,28,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,32,32,32,32,31,31,31,31,30,30,30,30,29,29,29,29,28,28,28,28,27,27,27,27,26,26,26,26,25,25,25,25,24,24,24,24,23,23,23,23,22,22,22,22,21,21,21,21,20,20,20,20,19,19,19,19,18,18,18,18,17,17,17,17,16,16,16,16,15,15,15,15,14,14,14,14,13,13,13,13,12,12,12,12,11,11,11,11,10,10,10,10,9,9,9,9,8,8,8,8,7,7,7,7,6,6,6,6,5,5,5,5,4,4,4,4,3,3,3,3,3,0,0,0,0,0,0};
+/* Sparat volt simulering IN*/   //int Voltage[]={0,0,2,2,4,4,6,6,7,7,9,9,10,10,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,19,19,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,25,25,26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,29,29,29,29,28,28,28,28,27,27,27,27,26,26,26,26,25,25,25,25,24,24,24,24,23,23,23,23,22,22,22,22,21,21,21,21,20,20,20,20,19,19,19,19,18,18,18,18,17,17,17,17,16,16,16,16,15,15,15,15,14,14,14,14,13,13,13,13,12,12,12,12,11,11,11,11,10,10,10,10,9,9,9,9,8,8,8,8,7,7,7,7,6,6,6,6,5,5,5,5,4,4,4,4,3,3,3,3,2,2,2,2,1,1,1,1,0,0,0};
+/* Sparat volt simulering UT*/ int Voltage[]={0,5,5,9,9,12,12,14,14,16,16,17,17,18,18,18,18,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1};
+
+int voltage=Voltage[tim];
+int vlen=sizeof(Voltage)/sizeof(Voltage[0]);
+//int pos;
+char check;
+char Hall[3];
+int o=0;
+char guard=1;
+
+void init_PWM()
+{
+    LPC_SC->PCONP |= 1 << 6; // enable power for PWM1 
+    
+    int prescaler=1;
+    LPC_SC->PCLKSEL0 |= prescaler << 12 ; //PCLK = CCLK = 96MHz
+    // Prescalers: 0 cclk/4, 1 cclk/1, 2 cclk/2, 3 cclk/8
+       
+    LPC_PWM1->TCR = 0x00;             //Timer control reg
+    LPC_PWM1->CTCR = 0x00;            //Count control reg
+    LPC_PWM1->MCR = 0x00;             //Match control
+    LPC_PWM1->CCR = 0x00;             //Capture control 
+    LPC_PWM1->PCR = 0x00;             //PWM control reg
+    LPC_PWM1->LER = 0x00;             //Load enable reg
+    LPC_PWM1->PR = 1 - 1;             //Prescale
+    
+    LPC_PINCON->PINSEL4 = (1<<0)|(1<<2)|(1<<4)|(1<<6)|(1<<8)|(1<<10); //output to pin 2.0 - 2.5
+    LPC_PINCON->PINMODE4 =(2<<0)|(2<<2)|(2<<4)|(2<<6)|(2<<8)|(2<<10); //pull down
+    
+        
+    int Frequency=100000; //Hz
+    
+
+    int mr0=(96000000/prescaler)/Frequency;
+    
+    LPC_PWM1->MR0 = mr0;  //set clock cycles for PWM. PWM freq = PCLK/MR0 (?)
+    LPC_PWM1->MR1 = 0; // DIP 26
+    LPC_PWM1->MR2 = 0; // DIP 25
+    LPC_PWM1->MR3 = 0; // DIP 24
+    LPC_PWM1->MR4 = 0; // DIP 23  
+    LPC_PWM1->MR5 = 0; // DIP 22
+    LPC_PWM1->MR6 = 0; // DIP 21
+       
+    LPC_PWM1->LER = (1 << 0) | (1 << 1) ; //Apply changes
+    LPC_PWM1->MCR |= (1 << 1) ; // interrupt on match0.Reset timer on Match0;
+    LPC_PWM1->PCR = (1<<9)|(1<<10)|(1<<11)|(1<<12)|(1<<13)|(1<<14); //--- PWM1 output
+    LPC_PWM1->TCR = (1<<0)|(1<<3);    
+}
+
+void dutyC(int dutyy, int pin) //dutyy is the input dutycycle (0-100), input in "pin" (1-6) which PWM pin that one wants to change.
+{   
+    int mr00=(96000000)/Frequency;
+     
+    LPC_PWM1->TCR = (1<<1)|(1<<0);
+
+    LPC_PWM1->MR0 = 0; 
+    LPC_PWM1->TCR = (0<<1); 
+    LPC_PWM1->MR0 = mr00; 
+   
+    if      (pin==1){LPC_PWM1->MR1 = mr00*dutyy/100;} // DIP 26
+    else if (pin==2){LPC_PWM1->MR2 = mr00*dutyy/100;} // DIP 25
+    else if (pin==3){LPC_PWM1->MR3 = mr00*dutyy/100;} // DIP 24
+    else if (pin==4){LPC_PWM1->MR4 = mr00*dutyy/100;} // DIP 23
+    else if (pin==5){LPC_PWM1->MR5 = mr00*dutyy/100;} // DIP 22
+    else if (pin==6){LPC_PWM1->MR6 = mr00*dutyy/100;} // DIP 21
+    LPC_PWM1->LER = (1 << 0) | (1 << 1) ; //Apply changes
+    LPC_PWM1->TCR = (1<<0)|(1<<3);
+}
+
+void Sixstepswitch(int En1, int En2, int En3, int Sw1, int Sw2, int Sw3) //En = enable switches //Sw set positive or negative direction (1pos, 0neg)
+{  
+    dutyC(En1,1);   //Enable switch 1
+    dutyC(Sw1,4);   //switch 1    
+    dutyC(En2,2);   //Enable switch 2
+    dutyC(Sw2,5);   //switch 2
+    dutyC(En3,3);   //Enable switch 3
+    dutyC(Sw3,6);   //switch 3
+}
+
+
+void stopHall1() 
+{
+    if (guard==1)
+    {
+        VoltStep.detach();
+        voltage=Voltage[tim];
+        o=100;    //tim=0;
+        X=100;
+        Voltage[tim]=100;
+
+    
+        //Sixstepswitch(100,100,100,  100,100,100);
+        //wait(2);
+        dir=dirClock;
+        check=1;
+        tim=0;
+        //pos=0;
+        guard=2;
+    }
+}
+void stopHall2() 
+{
+    if (guard==2)
+    {
+        VoltStep.detach();
+        voltage=Voltage[tim];
+        o=100;    //tim=0;
+        X=100;
+        Voltage[tim]=100;
+    
+        
+        //Sixstepswitch(100,100,100,  100,100,100);
+        //wait(2);
+        dir=dirCounter;
+        check=1;
+        tim=0;
+        
+        //led1=0;
+        //led2=0;
+        //led3=0;
+        //pos=0;
+        guard=1;
+    }
+
+}
+
+void Hall1r()
+{
+    if      (dir==dirClock)  {Sixstepswitch(100,o,100,  o,X,Voltage[tim]); dutyPin=6;} 
+    else if (dir==dirCounter){Sixstepswitch(100,100,o,  o,Voltage[tim],X); dutyPin=5;}
+}
+void Hall2r()
+{
+    if      (dir==dirClock)  {Sixstepswitch(100,100,o,  Voltage[tim],o,X); dutyPin=4;}
+    else if (dir==dirCounter){Sixstepswitch(o,100,100,  X,o,Voltage[tim]); dutyPin=6;}
+}
+void Hall3r()
+{
+    if      (dir==dirClock)  {Sixstepswitch(o,100,100,  X,Voltage[tim],o); dutyPin=5;}
+    else if (dir==dirCounter){Sixstepswitch(100,o,100,  Voltage[tim],X,o); dutyPin=4;}
+}   
+void Hall1f()
+{
+    if      (dir==dirClock)  {Sixstepswitch(100,o,100,  Voltage[tim],X,o); dutyPin=4;}
+    else if (dir==dirCounter){Sixstepswitch(100,100,o,  Voltage[tim],o,X); dutyPin=4;}
+}     
+void Hall2f()
+{
+    if      (dir==dirClock)  {Sixstepswitch(100,100,o,  o,Voltage[tim],X); dutyPin=5;}
+    else if (dir==dirCounter){Sixstepswitch(o,100,100,  X,Voltage[tim],o); dutyPin=5;}
+}     
+void Hall3f()
+{
+    if      (dir==dirClock)  {Sixstepswitch(o,100,100,  X,o,Voltage[tim]); dutyPin=6;}
+    else if (dir==dirCounter){Sixstepswitch(100,o,100,  o,X,Voltage[tim]); dutyPin=6;}
+}  
+
+void Vstep() 
+{
+     //if (Voltage[tim]==0);
+     //   {check=1}
+     //else{
+    if(check==0)
+    {    
+        if (dir==dirClock)
+        {
+             dutyC(Voltage[tim],dutyPin);
+            tim++;
+            if (tim>=vlen){VoltStep.detach(); /*check=0;*/__disable_irq(); led2=1; wait(1); __enable_irq(); tim=0;}  
+        }
+        else if(dir==dirCounter)
+        {
+            voltage=35;
+            tim=0;
+            Voltage[tim]=voltage;
+            dutyC(voltage,dutyPin);
+        }
+        else if (dir==dirClock+2)
+        {
+            voltage=17;
+            tim=0;
+            Voltage[tim]=voltage;
+            dutyC(voltage,dutyPin);    
+        }
+    }
+}
+
+int main(void)
+{
+    event1.rise(&Hall1r); // rise p15
+    event2.rise(&Hall2r); // rise p16
+    event3.rise(&Hall3r); // rise p17
+    
+    event1.fall(&Hall1f); // fall p15
+    event2.fall(&Hall2f); // fall p16
+    event3.fall(&Hall3f); // fall p17
+ 
+    stoppHallEvent1.fall(&stopHall1); //StoppEvent P18
+    stoppHallEvent2.fall(&stopHall2); //StoppEvent p19
+      
+    init_PWM();
+    wait_ms(100);
+    dir=dirCounter;
+    check=1;   
+    int tickertime=500;//440;
+    NVIC_SetPriority(TIMER3_IRQn, 4);       // Timer priority
+    VoltStep.attach_us(&Vstep, tickertime);        // Voltage step interrupt timer and frequency  
+    VoltStep.detach(); 
+    
+    /*int offset=2;
+    int p=0;
+    while (p<=vlen-1)
+    {
+        Voltage[p]=Voltage[p]+offset;
+        if (Voltage[p]<0)
+        {
+            Voltage[p]=0;   
+        }
+    p++;
+    }*/
+
+    
+    while(1)
+    {   
+    led1=0;
+        if (check==1)//Init state
+        {
+            __disable_irq();
+            led4=1;
+            Sixstepswitch(100,100,100,  0,0,0);
+            
+            wait(2);
+            o=0;
+            X=0;
+            Voltage[tim]=voltage;
+            
+            
+            Sixstepswitch(0,0,0,  0,0,0);
+            wait(1);
+            //attat
+            
+            
+            if(event1>=0.5) {Hall[0]=1; led1=1;} else {Hall[0]=0; /*led1=0;*/}
+            if(event2>=0.5) {Hall[1]=1; led2=1;} else {Hall[1]=0; /*led2=0;*/}
+            if(event3>=0.5) {Hall[2]=1; led3=1;} else {Hall[2]=0; /*led3=0;*/}
+            __enable_irq();
+            //six steps Start
+            if (dir==dirClock)
+            {                
+                /*if      (Hall[0]==1 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(100,0,100,   0,X,Voltage[tim]); dutyPin=6;} 
+                else if (Hall[0]==1 && Hall[1]==0 && Hall[2]==0){Sixstepswitch(0,100,100,   X,0,Voltage[tim]); dutyPin=6;}
+                else if (Hall[0]==1 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(100,100,0,   Voltage[tim],0,X); dutyPin=4;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(100,0,100,   Voltage[tim],X,0); dutyPin=4;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==1){Sixstepswitch(0,100,100,   X,Voltage[tim],0); dutyPin=5;}
+                else if (Hall[0]==0 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(100,100,0,   0,Voltage[tim],X); dutyPin=5;}*/
+                
+                if      (Hall[0]==1 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(100,0,100,   o,X,0); dutyPin=6;} 
+                else if (Hall[0]==1 && Hall[1]==0 && Hall[2]==0){Sixstepswitch(0,100,100,   X,o,0); dutyPin=6;}
+                else if (Hall[0]==1 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(100,100,0,   o,0,X); dutyPin=4;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(100,0,100,   o,X,0); dutyPin=4;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==1){Sixstepswitch(0,100,100,   X,o,0); dutyPin=5;}
+                else if (Hall[0]==0 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(100,100,0,   0,o,X); dutyPin=5;}               
+        
+
+            }
+            else if (dir==dirCounter) 
+            {
+                /*if      (Hall[0]==1 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(0,100,100,  X,Voltage[tim],0); dutyPin=5;} 
+                else if (Hall[0]==1 && Hall[1]==0 && Hall[2]==0){Sixstepswitch(100,100,0,  0,Voltage[tim],X); dutyPin=5;}
+                else if (Hall[0]==1 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(100,0,100,  0,X,Voltage[tim]); dutyPin=6;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(0,100,100,  X,0,Voltage[tim]); dutyPin=6;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==1){Sixstepswitch(100,100,0,  Voltage[tim],0,X); dutyPin=4;}
+                else if (Hall[0]==0 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(100,0,100,  Voltage[tim],X,0); dutyPin=4;}*/
+                
+                if      (Hall[0]==1 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(0,100,100,  X,o,0); dutyPin=5;} 
+                else if (Hall[0]==1 && Hall[1]==0 && Hall[2]==0){Sixstepswitch(100,100,0,  0,o,X); dutyPin=5;}
+                else if (Hall[0]==1 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(100,0,100,  0,X,o); dutyPin=6;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==0){Sixstepswitch(0,100,100,  X,0,o); dutyPin=6;}
+                else if (Hall[0]==0 && Hall[1]==1 && Hall[2]==1){Sixstepswitch(100,100,0,  o,0,X); dutyPin=4;}
+                else if (Hall[0]==0 && Hall[1]==0 && Hall[2]==1){Sixstepswitch(100,0,100,  o,X,0); dutyPin=4;}
+          
+            }
+            //__enable_irq();
+            check=0;
+            tim=0;
+            VoltStep.attach_us(&Vstep, tickertime);        // Voltage step interrupt timer and frequency
+            led4=0;
+            
+ 
+
+           
+        }
+        
+    }
+}
\ No newline at end of file