Pages: [1]   Go Down
Author Topic: LCD Value does not getting updatet after 5 seconds ??  (Read 457 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey everyone,

got a littler problem with my project. I want to display the rpm on a LCD.
I have a Hall Sensor with works fine. The whole programm works and the RPM gets displayed very well.

But: After some time running (around 5 seconds) the value on the Display does not get updatet anymore. i don't find a solution
Seems that the arduino fails or something..

Please help

Regards Phil



Code:
// read RPM
 #include <LiquidCrystal.h>
 int half_revolutions = 0;
 int rpm = 0;
 unsigned long lastmillis = 0;
 int led = 13;
 LiquidCrystal lcd(12, 11, 5, 4, 3, 8);
 
 void setup(){
 Serial.begin(9600);
 attachInterrupt(0, rpm_fan, FALLING);
 pinMode(led, OUTPUT);
 lcd.begin(16, 2); // set up the LCD's number of columns and rows:
 }
 void loop(){
 if (millis() - lastmillis == 333){ //Uptade every 1/3 second, this will be equal to reading  1/3 frecuency (Hz).
 detachInterrupt(0);//Disable interrupt when calculating
 rpm = half_revolutions * 6; // Convert frecuency to RPM, note: 6 because 1/3 frequency and multiplied by 2 because of half recolutions 6 = 2 * 3.

if(rpm < 10){
  lcd.clear();
  lcd.setCursor(0, 2);
  lcd.print(rpm);
}
if(rpm > 10){
  lcd.setCursor(0, 2);
  lcd.print(rpm);
 }
if(rpm > 100){
  lcd.clear();
  lcd.setCursor(0, 2);
  lcd.print(rpm);
  }
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(){
  half_revolutions++;
   }
 
Logged

BCC AZ USA
Offline Offline
Edison Member
*
Karma: 35
Posts: 1212
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int half_revolutions = 0;

variables used in interrupt service routines need to be declared volatile.  And an int might be overflowing, try it with long instead.

volatile int half_revolutions = 0;
« Last Edit: February 22, 2014, 11:31:14 am by groundfungus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,

i changed to volatile and long... But the problem is still aviable. hmm

Regards Phil
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's probably not a good idea to check that the time interval is exactly 333 milliseconds.  Try replacing
if (millis() - lastmillis == 333)
   with
if (millis() - lastmillis >= 333)

I don't know your hardware set-up so I tried using your IF loop condition in this simple code
Code:
unsigned long lastmillis = 0;
void setup()
{  Serial.begin(9600);
}
void loop()
{  if (millis() - lastmillis >= 333)
  {   Serial.println(lastmillis);
      lastmillis = millis(); // Uptade lasmillis
  }
}

When I used "==" instead of ">=", it latched up at just under 13 seconds.  I'm not sure why I didn't duplicate your 5 seconds.  Maybe it's due to differences in the test configuration or maybe your estimate wasn't precise.  I know there was no need for precision here.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34118
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

While
Code:
detachInterrupt(0);//Disable interrupt when calculating
there is no need to keep attaching and detaching interrupts.
See:-
http://arduino.cc/en/Reference/Interrupts#.Uwl_rl6prdU
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,

problem solved! it was the =>

smiley Thanks to you all!
Logged

Pages: [1]   Go Up
Jump to: