HEY GUYS, I AM NEW TO ARDUINO , AND I AM TRYING TO MAKE A TACHOMETER .
I FOUND A CODE THAT CODE HELP BUT I CANT UNDERSTAND THE LOGIC IMPLEMENTED
HERE IS THE LINK TO THAT CODE Arduino Tachometer - Software | PyroElectro - News, Projects & Tutorials
I AM HAVING PARTICULAR TROUBLE WITH THE BELOW GIVEN PART!
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
}
IF SOME COULD EXPLAIN THIS CODE TO ME I WOULD BE VERY GRATEFUL
THANKYOU
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
}
Take the time now ("micros()" and subtract the last time recorded, and assign the difference to the variable "time".
Set the variable "time_last" to the time now.
(Personally, I'd've called "micros()" just once, and assigned the value to another variable, and used that throughout, but that's splitting hairs.)
Please don't SHOUT. It's rude.
A call to the function "micros()" gives you the number of microseconds since the Arduino started and a call to "millis()" give the number of milliseconds since the program started.
...R
trusted47:
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
}
IF SOME COULD EXPLAIN THIS CODE TO ME I WOULD BE VERY GRATEFUL THANKYOU
This is a single function definition - the name implies that its designed to be
an interrupt handler for a computer fan speed/tacho signal, ie it gets called
for every pulse on the fan's output signal - presumably the idea is to measure
the fans speed by timing the signals.
The first line has unnecessary parentheses and could more simply be written:
time = micros() - time_last ;
Somewhere the variables time and time_last will be declared, probably as
unsigned long time = 0L ; // long integer constant.
unsigned long time_last = 0L ;
The two separate calls to micros() means that its going to be a bit out since
time passes between the two calls that cannot be accounted for. A better
way to calculate this is:
void fan_interrupt()
{
time = micros() - time_last ;
time_last += time ;
}
The variable time will keep a value that is the period of the pulse waveform is
microseconds.
(or half the period if the interrupt is on every edge).
trusted47:
HEY GUYS, I AM NEW TO ARDUINO
Why are you SHOUTING?
Where are your code tags?