fezder
Well-Known Member
Right, topic says quite well trouble now, i managed to start using that BLDC motor from computer hdd, and now came the part i've been waiting for....sort of, because i just don't have much coding experience at all, but i've progressed at least hehe...
But, issue now is, for start, how can i calculate correct timing when to flash led's, even one colour for now like say in 90 degrees section/place? no need to jump to fancy clock hands yet, i think i'll get the hang of that once i understand how this timing must be done. So i do have reliable trigger to tell micro (arduino uno) when rounds come and go, tested it for 120 rounds per second and was reliable.
Now then, the code i have putted together: actually it's just fan rpm counter but i figured it would be great foundament to start building.
that led is purely for debugging purposes....as well as serial
What i'm thinking is that i should write the code like so that arduino calculates degrees/second from RPM value and from there the correct delay needed from new rotation-start?
Now, i dont't ask the answer, more likely clue/hint so i can think, like a bone to a blind dog: can smell but can't see it, if you see my meaning...
But, issue now is, for start, how can i calculate correct timing when to flash led's, even one colour for now like say in 90 degrees section/place? no need to jump to fancy clock hands yet, i think i'll get the hang of that once i understand how this timing must be done. So i do have reliable trigger to tell micro (arduino uno) when rounds come and go, tested it for 120 rounds per second and was reliable.
Now then, the code i have putted together: actually it's just fan rpm counter but i figured it would be great foundament to start building.
that led is purely for debugging purposes....as well as serial
What i'm thinking is that i should write the code like so that arduino calculates degrees/second from RPM value and from there the correct delay needed from new rotation-start?
Now, i dont't ask the answer, more likely clue/hint so i can think, like a bone to a blind dog: can smell but can't see it, if you see my meaning...
C:
int const ledPin = 13;
int half_revolutions = 0;
int state = LOW;
int rpm = 0;
unsigned long lastmillis = 0;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fan, FALLING);
pinMode (ledPin, OUTPUT);
}
void loop(){
if (millis() - lastmillis == 1000){ //Uptade every one second, this will be equal to reading frecuency (Hz).
detachInterrupt(0);//Disable interrupt when calculating
rpm = half_revolutions * 60; // Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use half_revolutions * 30.
Serial.print("RPM =\t"); //print the word "RPM" and tab.
Serial.print(rpm); // print the rpm value. Serial.print("\t Hz=\t"); //print the word "Hz".
half_revolutions = 0; // Restart the RPM counter
lastmillis = millis(); // Uptade lasmillis
attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
}
}
// this code will be executed every time the interrupt 0 (pin2) gets low.
void rpm_fan()
{
digitalWrite (ledPin, state);
(state = !state);
half_revolutions++;
}
Last edited: