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

siliconchip
Posts: 240
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 71 times
Been thanked: 22 times
Contact:

display and save number

Postby siliconchip » Sat Jan 15, 2011 8:51 pm

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 106 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8334
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2382 times
Been thanked: 3393 times
Contact:

Re: display and save number

Postby medelec35 » Sun Jan 16, 2011 11:46 am

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 119 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

siliconchip
Posts: 240
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 71 times
Been thanked: 22 times
Contact:

Re: display and save number

Postby siliconchip » Sun Jan 16, 2011 1:23 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8334
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2382 times
Been thanked: 3393 times
Contact:

Re: display and save number

Postby medelec35 » Sun Jan 16, 2011 2:51 pm

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 ).
These users thanked the author medelec35 for the post:
siliconchip (Sun Jan 16, 2011 3:13 pm)
Rating: 5.56%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

siliconchip
Posts: 240
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 71 times
Been thanked: 22 times
Contact:

Re: display and save number

Postby siliconchip » Sun Jan 16, 2011 3:13 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8334
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2382 times
Been thanked: 3393 times
Contact:

Re: display and save number

Postby medelec35 » Sun Jan 16, 2011 3:45 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

siliconchip
Posts: 240
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 71 times
Been thanked: 22 times
Contact:

Re: display and save number

Postby siliconchip » Sun Jan 16, 2011 6:53 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8334
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2382 times
Been thanked: 3393 times
Contact:

Re: display and save number

Postby medelec35 » Sun Jan 16, 2011 7:27 pm

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 127 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

siliconchip
Posts: 240
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 71 times
Been thanked: 22 times
Contact:

Re: display and save number

Postby siliconchip » Sun Jan 16, 2011 8:33 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8334
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2382 times
Been thanked: 3393 times
Contact:

Re: display and save number

Postby medelec35 » Sun Jan 16, 2011 8:41 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

siliconchip
Posts: 240
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 71 times
Been thanked: 22 times
Contact:

Re: display and save number

Postby siliconchip » Mon Jan 17, 2011 2:31 pm

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