EmbDev.net

Forum: FPGA, VHDL & Verilog Ring oscillator timing simulation


von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
Hi, I am trying to simulate a ring oscillator in Modelsim using the 
delay (.sdo) file generated by Quartus to get the relationship between 
frequency and # of gates. For some reason whenever I simulate this I get 
the exact same frequency, 1.6 GHz, regardless if my oscillator has 1 
gate or 1000. My simulation is basically just:

assign B = ~A;
assign C = ~B;
assign A = ~C;

and then expanded in a generate loop for more gates.

An I doing something wrong with the sdo file? I first compile in 
Modelsim, then select Simulate, add the sdo file, then start.

Thanks

:
von gerhard (Guest)


Rate this post
useful
not useful
Are you sure that you don't generate 1000
3-Inverter Loops that just sit next to each
other?

Gerhard

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
I don't know exactly what happens at the other end of the compiler, but 
I assumed that since every intermediate signal depends on the initial 
one that it wouldn't separate the inverters.

von Markus (Guest)


Rate this post
useful
not useful
You cannot simulate analog behavior this way. You only can simulate 
something similar.

von user (Guest)


Rate this post
useful
not useful
you can simulate this by adding an delay assignment.

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
I thought that the delay the simulator used (generated by Quartus) would 
be the same as if I manually added a delay assignment, only I don't know 
what delay to use in real time. So nothing should be analog in the 
simulation. All I really want to know is the delay across a single gate, 
which should accumulate for larger loops, but I'm not confident in my 
simulation due to the weird results.

von Markus (Guest)


Rate this post
useful
not useful
Again, you cannot (in no case) simulate the behavior of a ring 
oscillator, because this function uses analog behavior. The Simulator 
can only simulate digital behavior.

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
Of course all circuit behavior is analog behavior, calling it digital is 
an approximation. Given enough gates the output of the oscillator should 
be approximately digital. If I just attach a constant delay to each 
assignment then the oscillator works perfectly in simulation, only I 
have to guess what the gate delay is. I was hoping the synthesized delay 
file would have a more accurate delay.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Chris C1111 wrote:
> Hi, I am trying to simulate a ring oscillator in Modelsim using the
> delay (.sdo) file generated by Quartus to get the relationship between
> frequency and # of gates. For some reason whenever I simulate this I get
> the exact same frequency, 1.6 GHz, regardless if my oscillator has 1
> gate or 1000.
Beside the fact that the frequency will be much differtent in real life:
whats the initial value for all the gates? How do you assign it?

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
I use an external clock and a counter with an initialization signal.

assign A = (INIT) ? 1'b1 : ~C;

This should initialize all signals.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Chris C1111 wrote:
> assign A = (INIT) ? 1'b1 : ~C;
And the other ones?

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
If I set one signal, all the others should be initialized automatically. 
For the example in my first post if I set A = 1, then B and C are 
automatically initialized to 0 and 1 since during initialization there 
is no combinational loop.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Chris C1111 wrote:
> For the example in my first post if I set A = 1, then B and C are
> automatically initialized to 0 and 1 since during initialization there
> is no combinational loop.
And after that all "even" signals will be 1 and all "odd" signals will 
be 0. And thenn, what will happen if they circle araound? Will there 
(for any single signal) be a difference between the short "10101" 
sequence and the long "10101010101010101010101010101010101010101" 
cycling around? No, in both cases each single signal will toggle at 
maximum speed...

So try it with passing through the signal and only toggle its polarity 
on one bit:
assign B = ~A;
assign C = B;
assign A = C;
But then you will have to tell the synthesizer that it has to "keep" all 
of the signals. In VHDL for Xilinx you could do it this way:
http://www.lothar-miller.de/s9y/categories/29-Ringoszillator
(try the google translator, its German)

: Edited by Moderator
von Messknecht (Guest)


Rate this post
useful
not useful
assign B = #delay ~A;

where is the delay per inverter  in your model?

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
When I synthesize it in Quartus it generates a delay file (.sdo) which I 
use while I run my simulation.

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
I think I have it figured out. In order to keep the compiler from over 
simplifying the intermediate gates into a single LUT I need to set all 
the intermediate signals as outputs. Thanks for the replies!

von dasdgw (Guest)


Rate this post
useful
not useful
You don't need to specify the intermediate signals as output.
As Lothar told you already, you have to tell Quartus to don't optimize 
these signals.

Take a look at the attributes keep, noprune and preserve.

Can't remember right now which one did the trick.

I adopted Lothars code to run on a de0nano using Quartus II 12.0.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
dasdgw wrote:
> I adopted Lothars code to run on a de0nano using Quartus II 12.0.
In VHDL? What are the results? Can you show the code? I find it very 
interesting to compare different architectures...   ;-)

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
Thanks for pointing that out! Somehow I completely missed Lothar's last 
post. What you said makes perfect sense, I can't believe I missed that. 
Why does wikipedia state the output frequency is 1/(2*N×inverter delay)?

http://en.wikipedia.org/wiki/Ring_oscillator
(the figure caption)

Edit: I don't think what you said is correct. Immediately after 
initialization, everything is stable except for the first inverter, so 
the last inverter won't toggle until every inverter before it has. At 
that point every inverter is stable again except for the first one.

: Edited by User
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Attached files:

Rate this post
useful
not useful
Chris C1111 wrote:
> Edit: I don't think what you said is correct.
Hmmm...

You and wikipedia are right. I did a short test with symbolic delay:
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
4
entity RingO is
5
    Port ( reset : in  STD_LOGIC; 
6
           fout  : out STD_LOGIC);
7
end RingO;
8
9
architecture Behavioral of RingO is
10
  signal ring    : std_logic_vector(2 downto 0); -- ungerade Bitanzahl
11
--  signal ring    : std_logic_vector(20 downto 0); -- ungerade Bitanzahl
12
  attribute KEEP : string; 
13
  attribute KEEP of ring : signal is "true"; 
14
begin
15
  assert ring'length mod 2 = 1 report "Length of ring must be an odd number!" severity failure;
16
17
  process (ring,reset) begin
18
     for i in ring'range loop
19
       if i = ring'left then
20
         if reset='1' then
21
           ring(i) <= '1';
22
         else
23
           ring(i) <= not ring(0) after 1ns;
24
         end if;
25
       else
26
         ring(i)   <= not ring(i+1) after 1ns;
27
       end if;
28
     end loop;
29
  end process;
30
31
  fout <= ring(0);
32
33
end Behavioral;
I will check this on hardware later...  ;-)

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Attached files:

Rate this post
useful
not useful
Without the attribute "keep" all of the stages are optimized down to 1 
single mux-stage (see screenshots). Of course you could invent an output 
pin for each bit (as you did), but FPGA IO pins in real life are to 
expensive for such a simple task...

von Chris C. (Company: U1) (cc1717)


Rate this post
useful
not useful
Yes I didn't know about the keep attribute. Using this my oscillator 
works well in simulation and on my de0 (although as you predicted the 
frequency differs greatly). I get about 250MHz with 21 gates on 
hardware, I'm too scared to go much faster than that.

von J. S. (engineer)


Rate this post
useful
not useful
Chris C. wrote:
> I get about 250MHz with 21 gates on
> hardware, I'm too scared to go much faster than that.

I used ring oscillators with up to 1.2GHz with a chain length which 
makes sure, that all inverters fully saturate before the signal is 
looped back to them. According to the switching time and routing, it is 
possible to tune the model's delays appropriately.

http://www.96khz.org/htm/noisegenerator2.htm

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.