Can Register Values Be Used To Access Array Values In Verilog
Welcome to EDAboard.com
Welcome to our site! EDAboard.com is an international Electronics Word 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 demand to annals. Registration is free. Click hither to register now.
- Digital Blueprint and Embedded Programming
- PLD, SPLD, GAL, CPLD, FPGA Design
Y'all should upgrade or utilise an culling browser.
Verilog: read two values from an array at the same fourth dimension.
- Thread starter Pastel
- Kickoff date
- Condition
- Not open up for farther replies.
- #1
I take successfully made a first version of a signal generator, and now I would like to make it dual channel.
If I make an arbitrary signal table, and want to read information technology from 2 different points at the same fourth dimension, is information technology possible,
or do I have to setup 2 tables?
For case if I utilise one table, can I have access to 2 elements of an array at the aforementioned fourth dimension?
something like this
chan1 <= array[i]; chan2 <= array[i+stage]; Thanks for any hint.
Pastel
- #ii
If your array are individual registers or if it is a dual port SRAM you may acces them at the same time.
If your array is a simple SRAM architecture, so you lot tin't acces them at the same time
But usually SRAM is fast ... yous may read 2 items 1 after the other .... and you are free to process or output them at the aforementioned time, so it may have the same effect than reading them at the same time.
Klaus
- #3
- #iv
- Joined
- Feb 16, 2015
- Messages
- i,089
- Helped
- 307
- Reputation
- 614
- Reaction score
- 303
- Bays points
- 83
- Action points
- 8,730
- #5
Thanks for your replies.
In the meantime, I tried, and could accept the upshot I wanted.
I fabricated a table of 1024 16-bit values:
reg[15:0] sine[1023:0];
Then I made a script to fill them all, and if I admission sine and sin[i + stage], then I get a sine and a cosine
on the telescopic (I take wired MAX5875 DAC at the output of the FPGA).
So patently it doesn't eat "cpu cycles" and by the style, I'm not certain I was articulate plenty, information technology'south a verilog implementation,
not a C program, so at that place is no loop every bit such, there is only an always@(posedge clk) block, then yep, information technology's a kind of hardware
loop. And then I simply suppose the two signals are changing on the same clock only every bit I'm a existent beginner in the FPGA world, I'thou
non sure of anything.
What I become:
- The FPGA clock is at 100 MHz. But as I accept to ready the data, on clock rising edge, and then the DAC clock at the next
rising edge, then the DAC clock is fifty MHz, which should yield 50 MSamples per second. As the table length is 1024, and then
I should get l kHz or a little bit less.
- At the output, I tin encounter the sine and cosine signals of this unproblematic experiment. I was expecting 50M / 1024 = 48.828
kHz, only my sine waves are at 97 kHz, and I don't understand why for the time being.
Here is the core of what I'grand doing. I skip what I do with the LEDs, which is basically lighting them or not. So I send information to
the DAC, and I generate the corresponding clock. So on 1 rising border of clk, I check if the dac clock (max_clk) is 0, in which
example I strobe the input data by setting it to one. If it'southward already 1, I set the DA and DB to the DAC input and I rearm the clock
to 0 for the next clk ascension edge.
- Tin anybody explain me why I get 97 kHz instead of 48?
- Is in that location a way to put my sine array to a dedicated file and keep the top level object reasonably small-scale?
Thanks
Pastel
module test190803(DA, DB, max_clk, red_led, blue_led, clk) brainstorm output reg[15:0] DA, DB; // Data of the DAC output reg max_clk; // Clock of the DAC output reg red_led, blue_led; // Some leds for bank check; input clk; // FPGA 100 MHz input clock // Some variables reg[fifteen:0] sine[0:1023]; reg[9:0] sinindex; reg[ix:0] cosindex; // Initialization initial begin sin[0] = xxxxxx; // Long sequence of 1024 initializations sinindex = 0; cosindex = 256; end always@(posedge clk) begin // Increase the stage counters which volition automatically roll back to 0 afterward overflow. sinindex <= sinindex+1; cosindex <= cosindex+1; // Ready the dac clock loftier, or set the input data and set it low. if(max_clk == 0) begin max_clk <= i; end else begin DA <= Sine[sinindex]; DB <= Sine[cosindex]; max_clk <= 0; end end endmodule - - - Updated - - -
Hello!
Distressing, I didn't observe your reply.
Ok, I'chiliad an accented beginner and I'm non sure of what I used. I just wrote some code, it works, more or less.
I don't know what is BRAM, DMEM... only to tell you how newbie I am...
Merely anyway, I'one thousand able to admission more than one element of an assortment at a time, and information technology doesn't do information technology sequencially
otherwise the frequency would drop, and information technology doesn't. The frequency is even twice what I calculated, and
I don't understand why (see full explanation above).
Thanks,
Pastel
- #6
Because you lot are incrementing the indexes every clock cycle. You want somethink like this.why I go 97 kHz instead of 48?
Lawmaking Verilog - [aggrandize] one 2 three iv 5 6 7 8 nine ten 11 e'er @ ( posedge clk) brainstorm if (max_clk == 0 ) max_clk <= 1 ; else begin sinindex <= sinindex+ 1 ; cosindex <= cosindex+ 1 ; max_clk <= 0 ; cease DA <= Sine[sinindex] ; DB <= Sine[cosindex] ; terminate
- - - Updated - - -
Many ways. E.1000. using a binary or hex file and $readmemb or $readmemh. Or calculating the initialization values at compile time using $sin() and $cos() organisation functions. Or write a function that delivers the values.Is there a way to put my sine assortment to a dedicated file and keep the top level object reasonably minor?
- #7
- Joined
- Feb 16, 2015
- Messages
- 1,089
- Helped
- 307
- Reputation
- 614
- Reaction score
- 303
- Trophy points
- 83
- Activity points
- eight,730
- #8
Thanks for your reply!
And for the solution! It was really a light-headed question. Indeed, I was incrementing at every pace.
It works now.
Past the way, I have asked a few times, but how tin can I format the code with colored syntax?
Is it something merely moderators can do?
Thanks,
Pastel
- - - Updated - - -
Hello!
Thanks for your reply!
BRAM requires 1+ cycle of read/write latency simply is the nigh dense.
As far as I can tell, there is not much latency. The clock spins at 100 MHz, and I tin can output samples at 50 Ms/s.
So yes, one cycle to put the information at the DAC input, and the side by side cycle to latch it. But I call up it'due south the least I can practise
to keep the timing prophylactic.
Your pattern looks like it should be using BRAM equally the tabular array is large enough and yous don't do anything that would prevent this.
Only to be sure (not english native, sorry). You mean that my design is currently not using BRAM and I
should change it and so that it uses BRAM?
Or you mean that looking at the lawmaking, information technology'due south likely that my blueprint really uses BRAM?
the tabular array is big enough and you don't do annihilation that would forestall this.
To forbid the table to be big, or to prevent my design to employ BRAM?
By the way, I have some other question. I'k using the MAX5875 DAC which tin work at 200 Msps.
I take noticed that any I do, it works. I mean: this works:
if(max_clk == 0) begin max_clk <= i; end else begin DA <= Sine[sinindex]; DB <= Sine[cosindex]; max_clk <= 0; terminate And this also works:
if(max_clk == 0) begin DA <= Sine[sinindex]; DB <= Sine[cosindex]; max_clk <= 1; finish else begin max_clk <= 0; end I suppose that if I fix the clock and the data at the aforementioned time, there is anyhow a
delay between the information and the clock, so it works. In one case, the information is latched
immediately, and in the other case, the information from the previous cycle is latched.
There is no departure in matters of noise at the DAC output.
Can anybody tell me why it works in both case (is my explanation right)?
Thanks,
Pastel
- #9
- #10
- Joined
- February 16, 2015
- Messages
- 1,089
- Helped
- 307
- Reputation
- 614
- Reaction score
- 303
- Bays points
- 83
- Activity points
- 8,730
Or you mean that looking at the lawmaking, it's probable that my design really uses BRAM?
I wait the tools to implement your table in BRAM. This is desirable in this case. You should confirm this in synthesis logs -- the tools sometimes do unexpected things.
- #11
Information technology's however not preferred to generate the DAC clock in logic like you lot practise. Yous'll ameliorate use a crystal or PLL generated clock through a defended FPGA clock output. If your application purpose is synthesis of clean RF signals, e.grand. for a software defined radio or exam generator, y'all'll fifty-fifty prefer a crystal oscillator straight clocking the DAC for minimal phase noise. FPGA clock jitter is relative large.
- Status
- Not open for farther replies.
Similar threads
- Xilinx System Generator Clock Signal
- Started past ing_dabrzn
- Replies: ii
- Spread spectrum clock generator using dcdl
- Started by bubu_not_taken
- Replies: 6
-
- Finite State Car for point generator
- Started by MSAKARIM
- Replies: eight
- Digital Blueprint and Embedded Programming
- PLD, SPLD, GAL, CPLD, FPGA Design
- This site uses cookies to help personalise content, tailor your feel and to go along yous logged in if you lot register.
By continuing to use this site, yous are consenting to our utilize of cookies.
Can Register Values Be Used To Access Array Values In Verilog,
Source: https://www.edaboard.com/threads/verilog-read-2-values-from-an-array-at-the-same-time.385846/
Posted by: mccullochwhatiall.blogspot.com

0 Response to "Can Register Values Be Used To Access Array Values In Verilog"
Post a Comment