Go Down

### Topic: Timer and LCD problems but not basic. Need a pro. (Read 898 times)previous topic - next topic

#### noobdude

##### Feb 06, 2013, 07:02 amLast Edit: Feb 06, 2013, 07:06 am by noobdude Reason: 1
Hi guys, I feel really bad like a leech here but I'm in no position to help anyone 'yet'. When I am in that position I will. Your help is greatly appreciated!

I started this sketch before I knew anything really(still don't tbh). Finished about 50% before I even knew about arrays. I just used simple example type code and went on from there. It works but its very crappy how I coded it. Even I know that.  I really don't want to redo this now. Its almost done and I learned from it. I want to learn to code properly after this.

I'm having two problems I need some help with.. The first is a timer. In my original sketch I used millis() and another variable previousmillis as a seconds counter. Very simple. When millis() > previousmillis by 1000 it updates counter variable then resets previousmillis. This worked great although I need to use smaller increments of time like increments of .25 all the way up to 9.00.

The weird thing is the .25 isn't .25 seconds. It actually ends up being 4 seconds. There's another variable that is a setpoint that needs to ramp up at that rate(by .25 a degree by a second). I really hope that makes sense.

.25 = 4000 milliseconds
.50 = 2000 milliseconds
1 = 1000 milliseconds

If that doesn't make sense I'll wait until tomorrow to explain I'm sure it'll sound better.

]
Any help would be greatly appreciated on either problem.

Its about 40k of code so I uploaded it to mediafire.  Its still a work in progress with other problems but these are most important now. I also have other variables and another finite state machine that aren't used yet.  Again, I know the code is whack but I'm like a first grader trying to do this. Its working so far and I really am planning on learning to code the right way. Just my first project.

http://www.mediafire.com/?5qekavq11aeveeb

EDIT:For timer problem open sketch and search for REFLOW_STATE_STEP_1_RAMP.  For LCD problem search for void loop() and go from there. Thanks again I'm really stuck on these problems.....

#### johnwasser

#1
##### Feb 06, 2013, 03:08 pm
Every time through loop() you do a lot of writing to the LCD:
Code: [Select]

lcd.setCursor(1, 1);
lcd.print("PTN:");
lcd.print(currentProfile);
lcd.setCursor(13, 1);
lcd.print("STEP:");
lcd.print(currentStep);
lcd.setCursor(1, 2);
lcd.print("TH");
lcd.setCursor(5, 2);
lcd.print("SV:");
lcd.setCursor(13, 2);
lcd.print("PV:");
lcd.setCursor(1, 3);
lcd.print("BH");
lcd.setCursor(5, 3);
lcd.print("SV:");
lcd.print(sv2);
lcd.setCursor(13, 3);
lcd.print("PV:");

Unless that part of the display is common to every state, you should probably draw it only in the states where it is needed.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### PeterH

#2
##### Feb 06, 2013, 04:08 pm

The first is a timer. In my original sketch I used millis() and another variable previousmillis as a seconds counter. Very simple. When millis() > previousmillis by 1000 it updates counter variable then resets previousmillis. This worked great although I need to use smaller increments of time like increments of .25 all the way up to 9.00.

The weird thing is the .25 isn't .25 seconds. It actually ends up being 4 seconds. There's another variable that is a setpoint that needs to ramp up at that rate(by .25 a degree by a second). I really hope that makes sense.

.25 = 4000 milliseconds
.50 = 2000 milliseconds
1 = 1000 milliseconds

If that doesn't make sense I'll wait until tomorrow to explain I'm sure it'll sound better.

To save everyone wading through 40K+ of source code, I suggest that you extract your timing code into a separate small sketch that demonstrates the problem in the simplest way you can, and post that here.

#### Jimmy60

#3
##### Feb 06, 2013, 06:14 pm
Just an observation. I looked through the code but couldn't find these timing problems, but:

.25 seconds = 250 millis

1 second = 1000 millis

1000 / .25 = 4000
1000 * .25 = 250

That may be the source of one of your problems.

#### noobdude

#4
##### Feb 06, 2013, 07:29 pm
@John Yes, that's the problem exactly.  I tried to make it go straight to IDLE state from loop then pasted that code to setup LCD but buttons wouldn't work after? Weird huh?  I'm going to try again in a different smaller sketch and see how I can make it work.

@Peter  Yes. Its a weird situation to me too.  I'm not sure how to make a timer to convert .25 to 1 degree every 4 seconds VS 250ms.  It works perfectly for 1 second increments of course but I need slower than that. I will write up a different sketch so its not so rough to go through and read etc. I didn't even use comments really...

@jimmy  Good call! I'll / instead of * . I think that's the ticket actually!!!

Thanks for the replies guys. This is so close to being done.

#### noobdude

#5
##### Feb 07, 2013, 08:24 am
@jimmy60 You're a genuis! Totally worked first try. All I did was when I went

if currentMillis - previousMillis > 1000 / rampRateStep1//(.25 first try)
previousMillis = currentMillis;
counter = counter + 1
setpointRamp = startTemp + counter;//actually updates setpoint here.

WORKS PERFECT! Thanks again!

+ karma for all you guys.

Go Up