Pages: [1]   Go Down
Author Topic: Timer and LCD problems but not basic. Need a pro.  (Read 403 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley

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.

The second problem is I'm using an lcd menu. Simple crap coded one but very effective. You guys helped with it it actually. I added the eeprom functions to save/load everything and its working.  I'm finally adding the sketches together and I'm having a problem going from loop() to MENU states. Whats happening is I setup the IDLE menu in loop() function.  When I load the REFLOW_STATE_IDLE state I tried to simply clear the lcd before hand but it keeps redrawing. I figured that I should go straight to REFLOW_STATE_IDLE THEN setup the lcd menu but then none of my buttons worked. How it is now, if I press the edit menu button it writes the menu over top the existing idle lcd setup.  if I'm in a menu and press cancel I have it setup to go to idle but it works fine that way with a simple lcd.clear();
]
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.....
« Last Edit: February 06, 2013, 01:06:32 am by noobdude » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Every time through loop() you do a lot of writing to the LCD:
Code:
  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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12534
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 19
Posts: 362
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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. smiley
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged

Pages: [1]   Go Up
Jump to: