Have code that uses multiple nested If-Then-Else-End If statements, from nests of two up to 16. Each group of nests generates a variable which is displayed on a 2x16 LCD. As I added more, larger groups of nests, the code would increasingly fail in that the PIC (16F88) would freeze, not displaying all 16 variables. Each time I reset the chip, a different number of variables would be displayed, rarely getting to all 16 variables. The code is using less than 50% of program memory, and less than 33% of RAM. This made me wonder if GCB just cannot handle all those Ifs. Any ideas appreciated.
Last edit: Anobium 2022-09-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you; code attached.
Project description: An external random number generator circuit feeds random bytes to PORTB, code checks for uniqueness, then displays bytes as printable ASCII characters.
Thanks very much! I have no formal computer science education, and your response led me to learn about how stacks work, and how deep recursion results in stack overflow.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium,
Substituting your code completely eliminated the problem with the PIC freezing. Now, the code completes to display 16 characters often, but stops most often at 14 characters, sometimes at 15, sometimes at 13. I thought that perhaps one of the ASCII codes might result in truncation of the
LCD display, but the range limitation (code 33-126 minus 92) seems appropriate. I tried adding time delays in the Display sub, but that didn't help. The randomness of the display has me foxed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am ignorant on how to ensure the stacks are not exceeded.
By stop, I mean that after the NewPWbutton is pushed, sometimes only 13, or 14, or 15 characters are displayed on the LCD. I get a new set of characters each time I press the button, and often will get all 16 characters the code asks for, but not each time.
Code attached. Thanks again for your help.
OK, I do not think it is the stacks at the moment.
So, as it is hard for me to simulate PortB input. My insight is that the Do While is never exiting. I have had add ccount .. my guess is that this will loop for ever. Does it ?
if 'rand <> aray(1)' where there are the equal the program will skip to four, leaving a char missing - hence the missing chars sometimes.
I think you need to rewrite. Use for-next loops to walk the array checking each element is not used.
Delete all the if-else's - try something like this. A proposed solution for you:
load the array with 16 chars
displays initial result
then loops thru the array until unique - using the flag valid. If a duplicate is found, swap it out, set the flag valid = 0 and reexamine.
display final result = unique
'load 16 chars... may not be unique but it is simply sets the initial valuesforxloop=1to16Newrandomaray(xloop)=randNextforxloop=1to16locate0,xloop-1printchr(aray(xloop))nextvalid=0Dowhilevalid=0valid=1'walk the array - changing duplicates until all are uniqueforxloop=1to15foryloop=2to16dowhile(aray(xloop)=aray(yloop))andyloop<>xloopNewrandomaray(yloop)=randvalid=0loopnextnextLoopforxloop=1to16locate1,xloop-1printchr(aray(xloop))nextwait5sclsforxloop=1to16printchr(aray(xloop))next
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I REALLY appreciate all the ideas and effort in helping with this project! Prior obligations require a few day hiatus in my work on this, but I look forward to trying out the change in approach, and I will post the entire and circuit when I have it working properly. Thanks again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Resolved. See https://sourceforge.net/p/gcbasic/discussion/579126/thread/e272106415/#44cc
Have code that uses multiple nested If-Then-Else-End If statements, from nests of two up to 16. Each group of nests generates a variable which is displayed on a 2x16 LCD. As I added more, larger groups of nests, the code would increasingly fail in that the PIC (16F88) would freeze, not displaying all 16 variables. Each time I reset the chip, a different number of variables would be displayed, rarely getting to all 16 variables. The code is using less than 50% of program memory, and less than 33% of RAM. This made me wonder if GCB just cannot handle all those Ifs. Any ideas appreciated.
Last edit: Anobium 2022-09-09
@Jack
Please post the code that fails.
Thank you; code attached.
Project description: An external random number generator circuit feeds random bytes to PORTB, code checks for uniqueness, then displays bytes as printable ASCII characters.
You are running out of stacks in Newrandom
You are calling and calling Newrandom . If you call recursively you must control the stacks.
Consider this.
Last edit: Anobium 2022-07-03
Thanks very much! I have no formal computer science education, and your response led me to learn about how stacks work, and how deep recursion results in stack overflow.
Pleasure. Your coding is great. And, we all learn each day from each other. :-)
Anobium,
Substituting your code completely eliminated the problem with the PIC freezing. Now, the code completes to display 16 characters often, but stops most often at 14 characters, sometimes at 15, sometimes at 13. I thought that perhaps one of the ASCII codes might result in truncation of the
LCD display, but the range limitation (code 33-126 minus 92) seems appropriate. I tried adding time delays in the Display sub, but that didn't help. The randomness of the display has me foxed.
How are you ensuring that the stacks are not exceeded?
When you say stop. .. do you mean there is no output?
Can you post your latest code, please.
I am ignorant on how to ensure the stacks are not exceeded.
By stop, I mean that after the NewPWbutton is pushed, sometimes only 13, or 14, or 15 characters are displayed on the LCD. I get a new set of characters each time I press the button, and often will get all 16 characters the code asks for, but not each time.
Code attached. Thanks again for your help.
OK, I do not think it is the stacks at the moment.
So, as it is hard for me to simulate PortB input. My insight is that the Do While is never exiting. I have had add
ccount
.. my guess is that this will loop for ever. Does it ?dim aray(17) ;will store random values
dim ccount as Word
aray = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;16 values with 0's as placeholders
if you dim aray(16) as byte then all elements will be 0
for n=1 to 16:aray(n)=random:next n..... 16 different numbers in aray()
@Jack,
This a hard nut to crack. What I thought would be a two minute job... was 2 hours.
There is something wrong with your approach. Consider your approach.
if 'rand <> aray(1)' where there are the equal the program will skip to four, leaving a char missing - hence the missing chars sometimes.
I think you need to rewrite. Use for-next loops to walk the array checking each element is not used.
Delete all the if-else's - try something like this. A proposed solution for you:
valid
. If a duplicate is found, swap it out, set the flag valid = 0 and reexamine.Oh my... using the password generator would provide 50 thousand trillion years until someone could crack the password...
Last edit: Anobium 2022-07-06
50 thousand trillion years until someone could crack the password...
Unless they had a Quantum Computer
This password application is a good idea.
Create password, store credentials in Progmem for later recall. A standalone password tool, very clever.
I REALLY appreciate all the ideas and effort in helping with this project! Prior obligations require a few day hiatus in my work on this, but I look forward to trying out the change in approach, and I will post the entire and circuit when I have it working properly. Thanks again.
I thought checking 16 numbers where different was easy... until you try it :)
Finally got this working well. Attached are the code, the complete circuit, and a bit of explanation on how the RNG portion of the circuit works.
A great complete project.
Well done.
May I move to the Demonstrations? You can edit and up date there.
Yes, and thank you for all your help with this project.
See https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/password_solutions for the completed and maintained project.