OK also mein Chef wollte das ich den Code abändere. Er wollte das ich die Bit-shift anweisungen im Interrupt rausnehme da für jedes ein CPU Cycle nötig ist und dafür eine Switch Case Anweisung reinmache. das sieht dann so aus
ISR(PCINT0_vect)
{
// You have to write your own interrupt handler. Don't change the name!
// This code will be called anytime when PCINT356 switches high to low,
// or low to high. This is for INT1 and INT2 and INT3 (all Port B)
byte PVal; // Port value (8 Bits)
byte IRQ1ActVal; // Actual IRQ1 value
byte IRQ2ActVal; // Actual IRQ2 value
byte IRQ3ActVal; // Actual IRQ3 value
long unsigned IRQ1ActTime;
long unsigned IRQ2ActTime;
long unsigned IRQ3ActTime;
switch(PINB&0x70)
{
case(ROT):
IRQ1ActVal=1;
IRQ1ActTime=millis(); // Read actual millis time
if(IRQ1ActTime - IRQ1PrevTime > bounceTime) // No bouncing anymore:
{
// No contact bouncing anymore:
if(IRQ1PrevVal==0 && IRQ1ActVal==1) // Transition 0-->1
{
// Place your command for rising signal here...
counter1++;
timeForOneRev=millis();
if(counter1>12) {
revolutionsCounter++;
counter1 = 1;
timeForOneRev2=timeForOneRev/1000;
}
IRQ1PrevTime=IRQ1ActTime;
IRQ1PrevVal=IRQ1ActVal;
irqFlag=1;
IRQ1ActVal=0;
}
if(IRQ1PrevVal==1 && IRQ1ActVal==0) // Transition 1-->0
{
// Place your command for falling signal here...
IRQ1PrevVal=IRQ1ActVal;
}
}
break;
case(HOME):
IRQ2ActVal=1;
IRQ2ActTime=millis(); // Read actual millis time
if(IRQ2ActTime - IRQ2PrevTime > bounceTime) // No bouncing anymore:
{
// No contact bouncing anymore:
if(IRQ2PrevVal==0 && IRQ2ActVal==1) // Transition 0-->1
{
// Place your command for rising signal here...
//old Code
if(timeForAntiClockwise < 50) antiClockFlag=1;
counter2++;
if (counter2==1) {
startState=homeState-counter1;
if (startState < 0) {
startState=homeStateHelp-startState;
}
}
if(counter2>255) counter2 = 0;
IRQ2PrevTime=IRQ2ActTime;
IRQ2PrevVal=IRQ2ActVal;
irqFlag=1;
IRQ2ActVal=0;
}
if(IRQ2PrevVal==1 && IRQ2ActVal==0) // Transition 1-->0
{
// Place your command for falling signal here...
timeForClockwise=millis();
IRQ2PrevVal=IRQ2ActVal;
}
}
break;
case(DIRECTION):
IRQ3ActVal=1;
IRQ3ActTime=millis(); // Read actual millis time
if(IRQ3ActTime - IRQ3PrevTime > bounceTime) // No bouncing anymore:
{
// No contact bouncing anymore:
if(IRQ3PrevVal==0 && IRQ3ActVal==1) // Transition 0-->1
{
// Place your command for rising signal here...
counter3++;
if(timeForClockwise < 50){
clockFlag = 1;
}
if(counter3>255) counter3 = 0;
IRQ3PrevTime=IRQ3ActTime;
IRQ3PrevVal=IRQ3ActVal;
irqFlag=1;
IRQ3ActVal=0;
}
if(IRQ3PrevVal==1 && IRQ3ActVal==0) // Transition 1-->0
{
// Place your command for falling signal here...
timeForAntiClockwise=millis();
IRQ3PrevVal=IRQ3ActVal;
}
}
break;
}
}
Ganz oben habe ich dann noch
#define ROT 0x10
#define HOME 0x20
#define DIRECTION 0x40
definiert. Jetzt zu meinem Problem er bemekt bei schnellen impulsen nicht jedes HIGH. Also die ausgabe sieht dann manchmal so aus
Counter1 = 12, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 3, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 4, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 5, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 6, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 7, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 9, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 10, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 11, Counter2 = 1, Counter3 = 0, Time for one Revolution = 67 seconds, Round no. 6, Start Position at: 7
Counter1 = 2, Counter2 = 1, Counter3 = 0, Time for one Revolution = 68 seconds, Round no. 7, Start Position at: 7
Normalerweise sollte der Counter 1 immer von 1-12 zählen und dann auf 1 zurück gehen
Edit: hoffentlich war es nicht schlimm das ich einen Doppelpost gemacht habe
also da ja der Counter trotzdem hochzählt ist nur die Serial. ausgabe zu langsam. aber da am ende ja keine Seriele ausgabe gefordert ist ist es nicht so schlimm