Electronic Dice VHDL Program

I did an electronic dice game ( 3 die ) program in VHDL. Basically , the program has 216 different dice values combinations which was simply assigned by me. The dice has 3 segment displays . I defined the

3 displays as output " seg " . However , I can't figured out any idea to write this electronic dice ( 3 die )program using the function " Random Number Generator " where the dice can get random combinations randomly which means I don't have to assign the 216 dice combintions . Anyone have any idea how to write the program ? Perhaps write the beginning part of the program so that I could roughly have an idea to continue from there. I appreciate your help.

Thanks a lot .

Below is my program:

--------------------------------------------------------------------------------

library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity dice is port( reset,clk : in std_logic; seg: out std_logic_vector (20 downto 0)); end dice;

architecture archdice of dice is type dice_states is (s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17, s18,s19,s20,s21,s22,s23,s24,s25,s26,s27,s28,s29,s30,s31,s32, s33,s34,s35,s36,s37,s38,s39,s40,s41,s42,s43,s44,s45,s46,s47, s48,s49,s50,s51,s52,s53,s54,s55,s56,s57,s58,s59,s60,s61,s62, s63,s64,s65,s66,s67,s68,s69,s70,s71,s72,s73,s74,s75,s76,s77, s78,s79,s80,s81,s82,s83,s84,s85,s86,s87,s88,s89,s90,s91,s92, s93,s94,s95,s96,s97,s98,s99,s100,s101,s102,s103,s104,s105, s106,s107,s108,s109,s110,s111,s112,s113,s114,s115,s116,s117, s118,s119,s120,s121,s122,s123,s124,s125,s126,s127,s128,s129, s130,s131,s132,s133,s134,s135,s136,s137,s138,s139,s140,s141, s142,s143,s144,s145,s146,s147,s148,s149,s150,s151,s152,s153, s154,s155,s156,s157,s158,s159,s160,s161,s162,s163,s164,s165, s166,s167,s168,s169,s170,s171,s172,s173,s174,s175,s176,s177, s178,s179,s180,s181,s182,s183,s184,s185,s186,s187,s188,s189, s190,s191,s192,s193,s194,s195,s196,s197,s198,s199,s200,s201, s202,s203,s204,s205,s206,s207,s208,s209,s210,s211,s212,s213, s214,s215,s216); signal sm: dice_states; begin

process (sm,clk) begin if reset = '1' then sm

Reply to
Amstel
Loading thread data ...

You're nearly done.

You don't need any kind of random number generator. Just make the clock run very fast (100 MHz ???) and add one more input, an "Enable". Inside the state machine, wrap your case statement in an "if" block:

if enable = '1' then case sm ......... lots of stuff end case; end if;

Now connect "Enable" to a pushbutton. While this button is down, the dice will roll - far too fast for the eye to follow. When the button is released, the dice will stop at a point which is essentially random, controlled only by the exact moment of release of the button.

OK, that's the homework done. For a bit more credit, you need to do two things:

(1) make your design and coding a lot more stylish; at the moment, it's about as ugly as a sea cucumber's backside. (2) think very, very carefully about why the "enable button" scheme doesn't work well, and needs a lot of fixing.

The thread that you stimulated a couple of weeks ago, but never contributed to again, would be a useful starting point.

Small children, nursing mothers and others of nervous disposition should avert their gaze at this point.

--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223                    mail: jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573                           Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
Reply to
Jonathan Bromley

I was going some comment about metastability, but maybe it's more fun to try to demonstrate setup/hold glitches. It would be like real life when one of the die leans against another one.

How would you build a system to maximize the chances of screwing up? I think you want a state machine with lots of illegal states and maybe lots of transitions with many bits changing.

--
The suespammers.org mail server is located in California.  So are all my
other mailboxes.  Please do not send unsolicited bulk e-mail or unsolicited
commercial e-mail to my suespammers.org address or any of my other addresses.
These are my opinions, not necessarily my employer's.  I hate spam.
Reply to
Hal Murray

Somehow , I'm required to write this electronic dice game program using the function " Random Number Generator " . It's part of a project assignment and I have no choice . I really need help on how to write the program using the " Random Number Generator " . Please . Anyone have any solutions ?

Thanks a lot .

Reply to
Amstel

Hi,

If you look back over the previous thread on this subject, when you asked for help about two weeks ago, you will see lots of very interesting discussion about how to use a random number generator for this problem, and why it's somewhat difficult. You will also find some very frivolous posts from me and others!

What kind of random number generator? I have already offered a suggestion for one way to make a random number generator, based on human-driven sampling of a very fast counter. It works well - I made an electronic die like this back in 1976 using four LSTTL chips, and seven LEDs. It even had a touch-pad that you could press to roll the die - I think I used a FET-input op amp for that.

OK, here goes.

1) Make a nice big linear-feedback shift register to create a pseudo-random stream of bits. 2) To roll the 3 dice, clock the shift register 8 times to get 8 random bits. (You can pick these bits from the top 8 flip-flops of the shift register; there's no need for separate storage.) 3) If the numeric value of the 8 random bits is greater than 215, go back to step 2 and keep trying until you get
Reply to
Jonathan Bromley

Jonathan - do you happen to know how fasible it is to generate a random stream by sampling white noise with an A->D converter. By feasible I mean a reasonable cost level and a reasonable component count, though I guess qualifying the resulting circuit is really the expensive part of the job.

Somewhere in "The Art of Computer Programming" Knuth points out that you cannot generate random numbers by randomly choosing an algorithm ;-)

Reply to
Tim

hi Tim,

sorry to disappoint but I have no experience of doing this. I do know that people have used various kinds of active device (zener diodes are a good candidate) to generate noise that can be used to control a process randomly. But I'd be very frightened that the sampling process would introduce some systematic bias that I didn't know about, and as you say the verification would be a nightmare.

Grin.

-- Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK Tel: +44 (0)1425 471223 mail: snipped-for-privacy@doulos.com Fax: +44 (0)1425 471573 Web:

formatting link

The contents of this message may contain personal views which are not the views of Doulos Ltd., unless specifically stated.

Reply to
Jonathan Bromley

What is this function, and how is it called ( params in /out) ?

In terms of applying RNG to your code, you could use a script to generate 'next state' in a (semi) random basis ( it does need to be a monotonic thread )

You could also additionally 'randomize' the LED Table lookups you have, but will again need to ensure a smoothed average ( all numbers 1-6 need to have equal ROM frequency )

Q: Will the resulting code create a 'better dice' ?

It would be more useable at lower clock frequencies.

-jg

Reply to
Jim Granville

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.