extra display mumbers

Hi am building a frequency counter have a code that I am working from all goes well.
I have turned it into a tachometer code. the problem I have is I want to eliminate the decimal point and last 2 digits for example at my operating speed the display reads 62000.00 witch is correct I want to eliminate the decimal point and last 2 numbers so it will read just 62000
attached is a copy of the code I am using any Ideas on removing the last digits

Thanks DAS

amt_turbine.ino (1.07 KB)

you're using floats. that's fine. your application may require them. but, your final division is into a float and it's that's what you print. not fine.

frequency=30000000/pulseTotal;
lcd.print(frequency);

since this is the only time you use frequency make it an int. you may also need to cast pulseTotal as an int.

int frequency = 30000000/(int)pulseTotal;

hope this helps

Hi All

Thanks that does work but then the reading will only go to 32000 then it displays a minus and then counts backwards to zero at 0HZ input the display reads 0 at 1000HZ reads 32000 after 1000hz it goes-30000 at 2000hz its back to zero.Had the same problem with a lot of the tach programs I found they will not read correctly at higher frequencys allways go into minus numbers

Thanks any other suggestions?

the 32000 number you reference is a dead give-away, since it's so close to 32767. i checked the language ref. an int, is defined as a 2-byte int. max positive value of 32767. any add to that value will wrap to negative. use unsigned long. it's 4 byte int with a max value of a crap load. check the ref.

unsigned int, 0 to 65535, (2^16)-1
unsigned long, 0 to (2^32)-1

hi again

real close now

with this sketch I get 42949667295 with no input frequency after about 50HZ reads perfect way past 65000rpm

pulseTotal = pulseHigh + pulseLow; // Time period of the pulse in microseconds

unsigned long frequency = 30000000/(int )pulseTotal;

lcd.setCursor(2,2);
lcd.print("RPM ");
lcd.print(frequency );

with this sketch I get 0 rpm reading at 0 HZ just like it should be but then from about 5HZ to 45 HZ I get the multi numbers on the display after about 45 to 50HZ again reads perfect.

pulseTotal = pulseHigh + pulseLow; // Time period of the pulse in microseconds

unsigned long frequency = 30000000/(float )pulseTotal;

lcd.setCursor(2,2);
lcd.print("RPM ");
lcd.print(frequency );