system
January 21, 2014, 8:21am
1
Hi
i'm trying to get a code running.
for some reason i cannot get it to run stable. it keeps on freezing.
i'm using arduino Uno. maybe a memory issue?
please help
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 10, 6, 5, 4, 3);
int RxCell1 = A0;
int RxCell2 = A1;
int IgnPack = A2;
int RunningLed = 12;
int MotorRevLed = 13;
double curmicros = 0;
double lastmicros = 0;
int deltamicros = 0;
double lastmillis = 0;
int MotorRpmVal = 0;
boolean Running = false;
boolean MotorRev = false;
void setup() {
pinMode(RunningLed, OUTPUT);
pinMode(MotorRevLed, OUTPUT);
digitalWrite(MotorRevLed, LOW);
digitalWrite(RunningLed, LOW);
lcd.begin(16, 2);
attachInterrupt(0, motor_rpm, FALLING);
}
void loop() {
if (millis() - lastmillis == 1000){
detachInterrupt(0);
MotorRpmVal = (( (double)(1000000) / (double)(deltamicros))) *60;
lcd.clear();
lcd.print (MotorRpmVal);
digitalWrite(RunningLed, Running);
Running = !Running;
lastmillis = millis();
attachInterrupt(0, motor_rpm, FALLING);
}
}
void motor_rpm(){
curmicros = micros();
//deltamicros = 4000;
deltamicros = curmicros - lastmicros;
lastmicros = curmicros;
digitalWrite(MotorRevLed, MotorRev);
MotorRev = !MotorRev;
}
system
January 21, 2014, 8:24am
2
tried this loop with the same results:
void loop() {
if (millis() - lastmillis == 1000){
detachInterrupt(0);
MotorRpmVal = (1000000 / deltamicros) * 60;
lcd.clear();
lcd.print (MotorRpmVal);
digitalWrite(RunningLed, Running);
Running = !Running;
lastmillis = millis();
attachInterrupt(0, motor_rpm, FALLING);
}
}
system
January 21, 2014, 8:34am
3
if (millis() - lastmillis == 1000){
And if it misses a millisecond?
system
January 21, 2014, 8:35am
4
hmmm.. never thought of that.
what do you suggest?
system
January 21, 2014, 9:04am
6
Generally for time, ">=" is better than "==".
system
January 21, 2014, 12:42pm
7
double curmicros = 0;
double lastmicros = 0;
micros does not return a double. Storing the unsigned long that it does return in a double is not smart.
double lastmillis = 0;
Ditto for millis().
system
January 21, 2014, 7:19pm
8
Hey sorry being nosy, but i am looking for a function that will run a stepper for a duration then stop - maybe even ramp speed up and then down.
What exactly does this do?
void loop() {
if (millis() - lastmillis == 1000){
detachInterrupt(0);
MotorRpmVal = (1000000 / deltamicros) * 60;
lcd.clear();
lcd.print (MotorRpmVal);
digitalWrite(RunningLed, Running);
Running = !Running;
lastmillis = millis();
attachInterrupt(0, motor_rpm, FALLING);
}
}