Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help fixing problems in the vhdl Sudoku code

Status
Not open for further replies.

Ms.Friday

Newbie level 3
Joined
May 20, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
33
Hello,

I chose a Sudoku code to implement it under Cyclone II - FPGA
I'm converting this java code to vhdl:


Code Java - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public static void initializeBoard()
    {
                int counter = 0;
                board = new int[9][9];
                allowedSets = new int [9][9];
 
        // Since no moves have been made, any number can go anywhere.
        // Start the sets out with all possibilities.
        for(int i = 0; i < 9; i++){
                    for( int j = 0; j < 9; j++){
                        allowedSets[i][j] = counter;
                        counter = counter + 9;
                    }
                }
 
                for (int i = 0; i < sudoku_array.length; i++){
                        sudoku_array[i] = true;
                    }
 
    }



my vhdl code:


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
library ieee;
use ieee.std_logic_1164.all;
 
type board_ array is array of (0 to 8, 0 to 8) of integer;
type allowedSets_array is array of (0 to 9, 0 to 9) of integer;
 
--Board_array is array (0 to 8, 0 to 8) of Byte;
--allowedSets_array is array (0 to 8, 0 to 8) of Byte;
 
 
entity initalizeBoard is 
port (
clk: in std_logic;
Counter: in integer;
i: in integer;
j: in integer
);
 
end entity;
 
architecture FA of initalizeBoard is 
 
board: integer Board_array;
allowedSets: integer allowedSets_array;
variable a = sudoku_array'LENGTH;
 
begin 
clock : process (clk) 
Loop1: for i in 0 to 9 LOOP
Loop2: for j in 0 to 9 LOOP
allowedSets(i)(j)<=counter;
counter<=counter+9;
 
end Loop1;
end Loop2;
 
Loop3: for i in i to a LOOP;
a(i)<=true;
 
end Loop3;
 
 
end FA;



when I run it their is problems with the array :(
plz help me to make it correct
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,805
Helped
1,809
Reputation
3,628
Reaction score
1,768
Trophy points
1,393
Location
USA
Activity points
58,912
Re: Help fixing problems in the vhdl code

Loops are unrolled in VHDL (i.e. they are just a shorthand way of replicating logic). They don't work the same way as loops in software.

You instead have to use an FSM and counters to cycle through the array.
 

Ms.Friday

Newbie level 3
Joined
May 20, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
33
Re: Help fixing problems in the vhdl code

^
So you advice me to do an FSM for the code and from the fsm I write the code , correct?

+ another qs is my array implementation correct?
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,805
Helped
1,809
Reputation
3,628
Reaction score
1,768
Trophy points
1,393
Location
USA
Activity points
58,912
Re: Help fixing problems in the vhdl code

^
So you advice me to do an FSM for the code and from the fsm I write the code , correct?

+ another qs is my array implementation correct?

What I suggested is to use counters to index the array (row, column) and an FSM to control everything.

I'm not an expert in VHDL but the array doesn't look like it's defined as a 2D array. Take a look at the following discussion on this thread.
 

Ms.Friday

Newbie level 3
Joined
May 20, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
33
Re: Help fixing problems in the vhdl code

^
thanks I'll try and I hope that it will work with me
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
48,268
Helped
14,224
Reputation
28,709
Reaction score
12,917
Trophy points
1,393
Location
Bochum, Germany
Activity points
279,533
Various detail errors, e.g. wrong array size, wrong loop range, missing type and signal definitions.

I'm not an expert in VHDL but the array doesn't look like it's defined as a 2D array. Take a look at the following discussion on this thread.
2D (as shown) or 1D*1D array definition are both valid options. The difference matters if you want to access complete array rows at once. Single cells can be accessed with both variants. Because you didn't show relevant Sudoko code except for an (almost trivial) initialization part, we don't know if it's relevant for your code.
 

Ms.Friday

Newbie level 3
Joined
May 20, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
33
^
how can I identify the array size
I did this because that what I knew from the internet

+
Im confused do I use vector or no need
cuz its a 1 integer
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,805
Helped
1,809
Reputation
3,628
Reaction score
1,768
Trophy points
1,393
Location
USA
Activity points
58,912
It should be a 9x9 grid of integers so 0 to 8 in both dimensions with an integer range of 1 to 9

So you want a array and the values in the array you would make a type that only has a range of 1 to 9.

Since sudoku checks both row and columns for every digit I'm not sure having the array built by rows or columns would help as you will have to index through all elements of a row or column to check the array.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top