display and save number

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

display and save number

Post by siliconchip »

hi i have a random counter that displays 3 different numbers at short intervals, how can i save these numbers to look at again also how can i alter the number ie random number no higher than 60
Attachments
random.fcf
(5 KiB) Downloaded 257 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: display and save number

Post by medelec35 »

Hi siliconchip,
This should work.
There appears to be a bug in the simulation.
On hardware numbers generated are 1 to 60.
I have added a note on the flowchart, how to changed highest and lowest random number generated.
in Flowcode simulator numbers generated are 1 to 255.
I have also added a function to store the 3 numbers generated.
All three numbers will be displayed for 2 seconds after all 3 numbers have been generated.
Attachments
random_Modified.fcf
(6.5 KiB) Downloaded 275 times
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: display and save number

Post by siliconchip »

hi medelec thanks for the reply, it works great now only thing is the numbers repeat every time it is powered up, is there a way to make it random every time on power up

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: display and save number

Post by medelec35 »

Yes I have noticed that. I just made a Lottery Number Generator. That does the same thing.
Currently to get round the non randomness at switch on, I have included a switch that randomly generates 6 numbers, whist held down.
So holding switch down for different lengths of time will even a few ms difference will generate different numbers from start up.
Thinking about it, unless someone can come up with a better idea (please :-) ), I will set up Lottery Number Generator so the random() function, will be within a loop that is determined by reading value of timer0 register. My theory is timer0 reg will increase by 1 every 4 clock cycles. since delays are not 100% precise. by the time the value of timer0 is read, in theroy will have a different value each time. I will post the Lottery Number Generator when successful, then you can use that idea to generate a different random number on switch on for your project (if works of course :P ).
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: display and save number

Post by siliconchip »

ok medelec thanks i will look forward to that and thanks for your help

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: display and save number

Post by medelec35 »

Can you let me know if this version works please.
Attachments
random_Modified2.fcf
(8 KiB) Downloaded 251 times
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: display and save number

Post by siliconchip »

hi medelec it seems to be random after repeated power ups but when the lcd repeats the 3 numbers it allways comes up with 3 totally different numbers ie 1st=255 2nd= 64 3rd=255 and these numbers will repeat every time until you reset then it will be random again from the time before but when you get to the first second third number they repeat constant

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: display and save number

Post by medelec35 »

Sorry, have got several versions, as i'm testing on a 18F4455. I just posted a wrong version.
This should work the way you want it to.
Attachments
random_Modified3.fcf
(8.5 KiB) Downloaded 285 times
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: display and save number

Post by siliconchip »

hi it seems to be okay but im running a lp 32.768KHz crystal on my board and the delay times need to be altered , i have altered them but some parts such as start up take a while while actually displaying the 3 numbers go quick i will need to juggle more with the times to get it right

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: display and save number

Post by medelec35 »

siliconchip wrote:hi it seems to be okay but im running a lp 32.768KHz crystal on my board
Very odd?
You have set the target osc frequency for 3.2MHz not 32 KHz. I'm surprised you can see any chars on the display.
Also timer 1 is working on the assumption your osc is running at 3.2MHz, + if ur delays are set for 900ms, I am guessing this will slow down everything as well since osc is running 100 times slower than flowcode thinks it is?
so delay will probably be 900ms*100 = 90 seconds, is that the case?
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: display and save number

Post by siliconchip »

hi medelec my erroe :oops: i had not changed my crystal on my developement board from an earlier project, i needed to use the 32.768khz crystal to get a delay for a second whilst i was writing a delay using assembler code, nothing to do with flow code, i am now using a 4Mhz crystal with great results

Post Reply