DrAzzy, I'm using timer 0 because that's the one I found the most information on as well as examples (again, this is for the ATTiny85). Most other help I found simply said "read the datasheet" or there were links to the datasheet; which is all good and well, but if you don't have a history with micros and their verbiage, then the information there might as well be in Mandarin. I would like to learn how it all works, but I have been unable to find a good source that explains the register bits and the various methods of setting them (because what I have found is there is more than one way).
Having said all of that, PWM is not my problem. The main problem still persists. I have stripped down my code and still have the issue (see below). Whats really bothering me is the fact that the error condition, when it works on the initial pass, still only flashes the LED once instead of twice and I know the delay I have set in there is plenty of time for me to be able to see the double flash. I even added a digital write to the start of the loop just to see if that had an effect. It did not. I will try your core and see if that makes a difference.
const int ledGrn = 0;
//const int outPin = 1;
int NbTopsFan; int Calc;
//The pin location of the sensor
int hallsensor = 2; typedef struct{
//Defines the structure for multiple fans and their dividers
char fantype;
unsigned int fandiv; }fanspec;
//Definitions of the fans
//This is the varible used to select the fan and it's divider,
//set 1 for unipole hall effect sensor and 2 for bipole hall
//effect sensor
fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 1;
// when using millis, 1 sec = 7812
//unsigned long interval = 31248; //this is 4s (7812 x 4)
unsigned long interval = 5000; //this is 5s (7812 x 4)
unsigned long curTime;
volatile bool cooling = true;
void setup() {
pinMode(ledGrn, OUTPUT);
// pinMode(outPin, OUTPUT);
pinMode(hallsensor, INPUT);
attachInterrupt(0, rpm, RISING);
digitalWrite(ledGrn, HIGH); // turn on green LED for control OK
delay(20); //500ms
}
void loop() {
// digitalWrite(outPin, HIGH);
if (cooling) {
if (millis() >= interval) {
interval = (millis() + 5000UL);
checkFan();
}
} else {
digitalWrite(outPin, LOW);
digitalWrite(ledGrn, LOW);
delay(800); // this equals 200ms (7812 x .2s)
digitalWrite(ledGrn, HIGH);
delay(400);
digitalWrite(ledGrn, LOW);
delay(400); // this equals 200ms (7812 x .2s)
digitalWrite(ledGrn, HIGH);
delay(400);
digitalWrite(ledGrn, LOW);
delay(1000);
checkFan();
}
}
void rpm() {
NbTopsFan++;
}
void checkFan() {
NbTopsFan = 0;
sei();
delay(1000);
cli();
Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
if (Calc >= 6500) {
cooling = true; // turn on green side of LED
digitalWrite(ledGrn, HIGH);
} else {
cooling = false;
digitalWrite(ledGrn, LOW);
}
}