Sorry for the missing declarations:
unsigned long timeold, timenew;
volatile long enc_count1=0;
bool set=false;
double rpm1=0;
double rpm_mittel1=0;
void setup() {
Serial.begin(115200);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), count1, CHANGE);
attachInterrupt(digitalPinToInterrupt(3), count1, CHANGE);
TCCR1B = TCCR1B & B11111000 | B00000001;
}
void loop() {
// put your main code here, to run repeatedly:
if(set==true){
timeold = timenew;
timenew = micros();
rpm1 = double(double(enc_count1) * double(333333.33 / (timenew - timeold))); //60000000/180=333333,33
set=false;
Serial.println(rpm1);
enc_count1=0;
}
analogWrite(6,100);
}
void count1()//ISR für den Hallsensor
{
set=true;
static int8_t lookup_table[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
static uint8_t enc_val1 = 0;
enc_val1 = enc_val1 << 2;
enc_val1 = enc_val1 | ((PIND & 0b1100) >> 2);
enc_count1 = enc_count1 + lookup_table[enc_val1 & 0b1111];
}