Page 1 of 1

Beginners Error?

Posted: Sat Jul 24, 2010 10:50 am
by Dutchie_World_Wide
Hi guys,

Received my flow code last week and started writing project almost immediately.
I have to say that writing programs with flow code is a lot easier then i anticipated.


I wrote a program for a clock with keypad and 2 push buttons.
The idea of the program is:
The 2 push buttons are "HOURS" and MINUTES", ones one of these is pressed, the keypad is used to enter a new time.
If a time is entered which is not correct (Example 25 Hours or 73 minutes) this should show on the display and ask you to re-enter.
When I reset my PIC16F877A, everything starts up nicely, the time is 00:00:00
When i press the "Hours" button, all is still fine, the new hours can be entered. Same as with minutes.
But this only goes well, when i enter the new hours or minutes quickly ("like dialing a phone number on your mobile" quickly)
When i wait a bit longer, my PIC crashes. I ran the simulation tool, but it always works on there, it only crashes on my 16F877A.

I have some Siemens PLC experience, but this is my first attempt in programming PIC's, so if i miss something......

Any input from you guys would be great because i am getting lost. :oops:
I attached the Flowcode file <Keypad_Clock)

Dutchie

Re: Beginners Error?

Posted: Sat Jul 24, 2010 5:11 pm
by medelec35
Hello Dutchie_World_Wide.
The problem of chip freezing is caused by stack overflow.
see:
http://www.matrixmultimedia.com/mmforum ... 06&p=17293

When you compile to hex or compile to chip, take a look and any messages appearing in the information window. If you want to recheck for errors or warnings after you have closed the message window, then you have have a look at project_name.msg.txt. In your case Keypad01.msg.txt
it will show a warning

Code: Select all

Building CASM file

Serious Warning: Call stack usage exceeds:8!



Call Stack Usage Report

=======================

 main and Task(s): hw used:7, exceeded by:0

 interrupt: hw used:2, exceeded by:0
As you can see maximum allowed is 8.
You have 7 + 2 = 9

I don't believe the simulation will take into account number of stacks, so you could way too many , and simulation will run OK.
You have several options available to you.
1) Alter your coding, to reduce amount of stacks required. E.g. Avoid calling macros within macros etc.
In your case you can have the switch inputs in main, then if switch activated, calls the Set_hours or Set_minutes macro's. that will reduce stack for a start.
2) Increase number of software stacks available (see the link I posted above).
3) Buy a chip with a lager amount of hardware stacks.

Hope this helps

Re: Beginners Error?

Posted: Sat Jul 24, 2010 11:42 pm
by medelec35
Made some minor corrections for you.
Corrected so instead of changing from 23:59:59 to 24:00:00, now changes to 00:00:00
Remove the stack exceeded issue.
Try this on your hardware, and would you mind letting me know if solves the issue of freezing please.

Re: Beginners Error?

Posted: Sun Jul 25, 2010 2:12 am
by Dutchie_World_Wide
Hi Medelec35,

I uploaded it to the board, and problem solved.
I noticed the changes you made, including the: (Hours_Single>=4) AND (Hours_Tens >1)
I guess i have to get out of PLC thinking and use the IF functions a bit better.
Thanks for that

So if i understand this right, i can not use more then 6 macro's and 2 interrupts or any other combination as long as it is not more then 8?
Thats a bummer.
I actually started with most of the program in MAIN, but thought that by putting it in macros, might clean it up a bit :lol:
Anyway, lesson learned

Thanks allot Medelec35

Re: Beginners Error?

Posted: Sun Jul 25, 2010 2:46 am
by medelec35
Your welcome.
Dutchie_World_Wide wrote:Hi Medelec35,
So if i understand this right, i can not use more then 6 macro's and 2 interrupts or any other combination as long as it is not more then 8?
As stated in my previous post, you can use more. If you don't want to change hardware, then you can increase the amount of software stacks to above 8, then problem can be solved that way.
You are of course correct, using macros does clean program up. You can still use macros, but you need to remember, components like LCD's Delays and interrupts also use stacks up. So if you call a macro from main which calls another macro, which calls for a a LCD, which calls a macro, which call a delay that interns calls macro, then INT from timer 2 calls a macro etc. You can see how the 8 lvl stack can be exceeded.
Any way glad it's now working. Thank you for letting us know.

I believe you may like this version even better.
I have modified Flowcode even further to include an automatically changing Day of the week, Date and Month.
E.g if clock shows:
Fri 31 Jan 2010
23:59:59
then 1 second later it will show:
Sat 1 Feb 2010
00:00:00

The reason I made the Day, date and Month work is because I noticed you had a string variable, with a Day, date and Month which is shown on LCD.
It is not finished yet, I have not put all the month changing conditions in, only the 1st few. Also you would need to add Day,Date, Month and year adjustment( thats of course if you want to go down that route). By altering the program your self, could aid your learning experience. I have not had a chance to get the year to change automatically, but included the year, so leap year Feb date can change correctly.
Keypad01_modified2.jpg
Keypad01_modified2.jpg (10.45 KiB) Viewed 12736 times

Re: Beginners Error?

Posted: Sun Jul 25, 2010 8:13 am
by Dutchie_World_Wide
Hi Medelec,

You are 1 step further then I am :lol:
http://www.youtube.com/watch?v=9Nx_1O3uWK4

I'll download your program and see how you did it.
I gotta say; ones you get the hang off it, it gets addictive.
You wanna put more and more features in it.

Now I'm gonna study your program, it's always nice to see how other do it.
It keeps you from thinking in circles.

Thanks

Re: Beginners Error?

Posted: Sun Jul 25, 2010 9:17 am
by medelec35
For you saying your a beginner of Flowcode, I am really impressed! For the short time you have been using Flowcode, you have certainly achieve a lot. Well done!
Demonstration on you tube looks great, and thank you for sharing it with the forum.
I'm sure there are people on here that was be very interested on using your program.
Dutchie_World_Wide wrote: I gotta say; ones you get the hang off it, it gets addictive.
You wanna put more and more features in it.
That is very true!
A Couple of things.
You have used count part of loops, so you could always to this:
Loops_New.jpg
Loops_New.jpg (17.3 KiB) Viewed 12728 times
You could also use conditional loops for keypad detection.

Re: Beginners Error?

Posted: Mon Jul 26, 2010 1:09 am
by Dutchie_World_Wide
Thank you,
I think my PLC background has helped me allot,
Step7 for Siemens PLC is not much different then Flowcode.
Although it's a bigger program with more options.
And you don't have to think about writing a function twice or more times in a program if you want to continue using it while the program is in a conditional loop. (Accept STL Language in Step7).
And a PLC reads all the inputs before it starts it cycle and writes all the output on the end of the cycle.

I made the change you suggested and attached the (for me) final program.
I want to start over and use what you said, use loops for the keypad.
Perhaps read/write the variables before a Macro is called and write them to the Eeprom after the Macro is finished. So i can use the same Macro for more then 1 function.

Anyway, enough brainfarts.

Medelec35, thanks for you help and ideas.
I attached the Flowcode file for if someone wants to use it.

Dutchie

Re: Beginners Error?

Posted: Wed Oct 12, 2011 6:01 pm
by drolkida99
why is it that when i run your flowcode program it does not run...im using flowcode 4

Re: Beginners Error?

Posted: Thu Oct 13, 2011 7:20 am
by medelec35
Hi drolkida99,
The most common cause for programs not to work is configuration or component settings.
This is especially true if the target device has been changed.

The most commons errors is watchdog timer, osc speed and type and low voltage programming left as enabled.

Take a look at:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

If you are still struggling after, then if your program is not commercially sensitive can you please post the flowchart, so we can take a look for you.


Martin

Re: Beginners Error?

Posted: Thu Oct 13, 2011 3:32 pm
by drolkida99
I downloaded the Keypad_Clock.fcf above as it is then i run it, but unfortunately it did not run.
i mean the counter did not run...the seconds did not count

Re: Beginners Error?

Posted: Thu Oct 13, 2011 4:30 pm
by medelec35
Hi drolkida99,
The reason it does not simulate, is because Timer 2 (TMR2) interrupt is used for timing of seconds.
Timer 1 & timer 2 do not simulate, but if loaded on a chip, it will work.
To resolve this you can change timer 2 interrupt to timer 0 (TMR0), since timer 0 simulates OK.
I have done this for you.

Martin

Re: Beginners Error?

Posted: Thu Oct 13, 2011 6:18 pm
by drolkida99
thank you for the time of modifying the program and explaining why it does not work.
So if i dont change the program and burn it will work on a real time basis? am i correct?

Re: Beginners Error?

Posted: Thu Oct 13, 2011 6:42 pm
by medelec35
drolkida99 wrote:thank you for the time of modifying the program and explaining why it does not work.
Your welcome.
drolkida99 wrote:So if i dont change the program and burn it will work on a real time basis? am i correct?
The actual program is created by Dutchie_World_Wide.
Since I have not tested it I can't guarantee it will run on real hardware. There is no reason for it not to.
If it does not, then let us know.



Martin