Verilog: [7] Ultra-detailed WaveDrom tutorial, a powerful tool for drawing timing diagrams, this article is enough.

Broken thoughts:

Unexpectedly, when the last article was sent out, almost no one read it in the first few hours. Is it because I wrote it too obscurely? This article introduces a simple but quite easy-to-use software WaveDrom, which can draw timing diagrams very conveniently. Good news for digital people!

This article will start from the installation and introduce the grammar involved in detail. Readers can bookmark it and refer to it at any time.

PS At this speed, I don't know how long it will take to finish learning the modules in the Basic Verilog library. Wow_(:з)∠)_ (I have forgotten which day it is this week).

Table of contents

1 Software installation

2 Drawing Tutorials

2.1 Create a signal (Signal)

2.2 Adding Clock

2.3 Combining clocks and signals (Putting all together)

2.4 Adding gaps (Spacers and Gaps)

2.5 Grouping signals (The groups)

2.6 Period and Phase (Period and Phase)

2.7 Other property configuration (The config{} property)

2.7.1 Horizontal scale (hscale)

2.7.2 Theme style (skin)

2.7.3 Head and tail labels (head/foot)

2.8 Labeling Arrows and Lines (Arrows)

2.8.1 Curve (Splines)

2.8.2 Sharp lines

2.9 Drawing with code (Some code)

3 Image saving and exporting


1 Software installation

Official website address: WaveDrom - Digital timing diagram everywhere

The software itself is divided into an offline version and an online version . Since the online version does not need to be installed, the installation process of the offline version is mainly introduced here. Unlike ordinary software that requires an installation package, the downloaded software is the entire program, and the corresponding executable can be opened directly. The file can be run directly.

Click "Download editor" in the lower left corner of the official website to open the download interface:

Just choose the version corresponding to your own system. Here I choose the Windows 64-bit version. Click the button on the right to download the software. (I used the edge plugin here, so it looks different from the original Github button, you can ignore it)

Open the compressed package and click wavedrom-editor.exe to run the program directly.

You can decompress the file to your usual installation directory, and then send the wavedrom-editor.exe shortcut to the desktop for easy opening.

When such an interface appears, it means that it can run successfully. Let's start the tutorial on the drawing function.

2 Drawing Tutorials

WaveDrom provides an official tutorial , and this drawing tutorial is based on the official tutorial ( more detailed than the official tutorial ).

If you want to check it directly, you can refer to this form (Can I ask for a little attention? _(:з)∠)_)

2.1 Create a signal (Signal)

The following code creates a signal named "Alfa", the " signal " keyword creates a series of signals, " name " defines the signal name, and " wave " defines the signal waveform, where each character represents a The signal type for the time period.

{ signal: [{ name: "Alfa", wave: "01.zx=ud.23.456789" }] }

The specific signal types are shown in the table below:

2.2 Adding Clock

The clock signal is a relatively special signal, which only has two states of high and low levels. Optional flags are provided to control whether rising/falling edges are shown. At the same time, it can be used simultaneously with other signals to achieve drawing similar to a gated clock.

Note that h and l of the clock are different from 1 and 0 of the signal (different edge angles).

The following code implements the clock style for reference.

{ signal: [
  { name: "pclk", wave: 'p.......' },
  { name: "Pclk", wave: 'P.......' },
  { name: "nclk", wave: 'n.......' },
  { name: "Nclk", wave: 'N.......' },
  {},
  { name: 'clk0', wave: 'phnlPHNL' },
  { name: 'clk1', wave: 'xhlhLHl.' },
  { name: 'clk2', wave: 'hpHplnLn' },
  { name: 'clk3', wave: 'nhNhplPl' },
  { name: 'clk4', wave: 'xlh.L.Hx' },
]}

The specific clock type is shown in the table below:

2.3 Combining clocks and signals (Putting all together)

When we draw a timing diagram, we usually need to put the clock and the signal together, in order to facilitate the viewing of the relationship between the two. Not only can you directly combine the clock with the signal, but you can also put the text or data name you want to add into some symbols in the form of labels using the keyword " data " to represent the value of the bus. Values ​​are added sequentially to the symbols "23456789=".

The code below gives an example of usage.

{ signal: [
  { name: "clk",  wave: "P......" },
  { name: "bus",  wave: "x.==.=x", data: ["head", "body", "tail", "data"] },
  { name: "wire", wave: "0.1..0." }
]}

2.4 Adding gaps (Spacers and Gaps)

In the timing diagram, it is sometimes necessary to omit clocks and signals, which requires adding gaps to omit unnecessary parts.

{ signal: [
  { name: "clk",         wave: "p.....|..." },
  { name: "Data",        wave: "x.345x|=.x", data: ["head", "body", "tail", "data"] },
  { name: "Request",     wave: "0.1..0|1.0" },
  {},
  { name: "Acknowledge", wave: "1.....|01." }
]}

2.5 Grouping signals (The groups)

By grouping, the hierarchical relationship between signals can be better displayed for easy reference and comparison. Use "[ ]" to realize the grouping of signals, and the name of the group can be added selectively.

{ signal: [
  {    name: 'clk',   wave: 'p..Pp..P'},
  ['Master',
    ['ctrl',
      {name: 'write', wave: '01.0....'},
      {name: 'read',  wave: '0...1..0'}
    ],
    {  name: 'addr',  wave: 'x3.x4..x', data: 'A1 A2'},
    {  name: 'wdata', wave: 'x3.x....', data: 'D1'   },
  ],
  {},
  ['Slave',
    ['ctrl',
      {name: 'ack',   wave: 'x01x0.1x'},
    ],
    [ 
    {  name: 'rdata', wave: 'x.....4x', data: 'Q2'},
    ],  
  ]
]}

2.6 Period and Phase (Period and Phase)

Period and phase are important attributes in the timing diagram, which can be edited and modified through the keywords " period " and " phase ".

Note that period only supports integers; phase supports integers and decimals, and the unit 1 of the phase refers to a period.

{ signal: [
  { name: "CK",   wave: "P.......",                                              period: 2  },
  { name: "CMD",  wave: "x.3x=x4x=x=x=x=x", data: "RAS NOP CAS NOP NOP NOP NOP", phase: 0.5 },
  { name: "ADDR", wave: "x.=x..=x........", data: "ROW COL",                     phase: 0.5 },
  { name: "DQS",  wave: "z.......0.1010z." },
  { name: "DQ",   wave: "z.........5555z.", data: "D0 D1 D2 D3" }
]}

2.7 Other property configuration (The config{} property)

Attribute configuration can modify many places of the image, increase the flexibility of drawing, use the keyword " config " to control the attribute.

2.7.1 Horizontal scale (hscale)

The horizontal scale modifies the horizontal width of the entire picture, which is intuitively understood as the drawing length per unit period.

{ signal: [
  { name: "clk",     wave: "p...." },
  { name: "Data",    wave: "x345x",  data: ["head", "body", "tail"] },
  { name: "Request", wave: "01..0" }
  ],
  config: { hscale: 1 }
}

 When modifying config: { hscale: 2 }:

2.7.2 Theme style (skin)

Through the " skin " keyword, the overall theme style of the plot can be modified. The offline version v2.9.1 provides four optional parameters "default", "dark", "lowkey" and "narrow"; the online version currently provides two optional parameters "default" and "narrow".

{ signal: [
  { name: "clk",     wave: "p...." },
  { name: "Data",    wave: "x345x",  data: ["head", "body", "tail"] },
  { name: "Request", wave: "01..0" }
  ],
  config: { hscale: 2 ,
            skin: "lowkey"
          }
}

2.7.3 Head and tail labels (head/foot)

The keywords " head " and " foot " can be used to label the whole picture through head and tail labels, including text (title text), tick (label with vertical mark), tock (label between vertical marks) , every (display a label every N cycles).

{signal: [
  {name:'clk',         wave: 'p....' },
  {name:'Data',        wave: 'x345x', data: 'a b c' },
  {name:'Request',     wave: '01..0' }
],
 head:{
   text:'WaveDrom example',
   tick:0,
   every:2
 },
 foot:{
   text:'Figure 100',
   tock:9
 },
}

  • text

text has all the attributes of SVG text, and its attributes can be modified through the " tspan " keyword, and predefined font styles can be used (including the types in the table below, and the required font and color can be combined), and SVG can also be used Other properties of tspan constitute freestyle.

SVG tspan other attribute configuration can refer to: tspan - SVG | MDN (mozilla.org)

{signal: [
  {name:'clk', wave: 'p.....PPPPp....' },
  {name:'dat', wave: 'x....2345x.....', data: 'a b c d' },
  {name:'req', wave: '0....1...0.....' }
],
head: {text:
  ['tspan',
    ['tspan', {class:'error h1'}, 'error '],
    ['tspan', {class:'warning h2'}, 'warning '],
    ['tspan', {class:'info h3'}, 'info '],
    ['tspan', {class:'success h4'}, 'success '],
    ['tspan', {class:'muted h5'}, 'muted '],
    ['tspan', {class:'h6'}, 'h6 '],
    'default ',
    ['tspan', {fill:'pink', 'font-weight':'bold', 'font-style':'italic'}, 'pink-bold-italic']
  ]
},
foot: {text:
  ['tspan', 'E=mc',
    ['tspan', {dy:'-5'}, '2'],
    ['tspan', {dy: '5'}, '. '],
    ['tspan', {'font-size':'25'}, 'B '],
    ['tspan', {'text-decoration':'overline'},'over '],
    ['tspan', {'text-decoration':'underline'},'under '],
    ['tspan', {'baseline-shift':'sub'}, 'sub '],
    ['tspan', {'baseline-shift':'super'}, 'super ']
  ],tock:-5
}
}

See the table below for the predefined styles:

2.8 Labeling Arrows and Lines (Arrows)

Sometimes it is necessary to connect and label the timing diagram, and WaveDrom provides the corresponding implementation. Using the " edge " keyword, you can include "curve" and "polyline", and both provide directed and undirected configuration methods; "polyline" provides a flat-angled arrow style, which is convenient for adjusting the length of the time period label.

There are three types of wires, which can be experienced in use:

symbol Curve Type
~ S-curve
- is combined with ~ arc
- or | straight line

Provide a small tip: You may think that the connection line can only be blue, but in fact, you can draw the red connection line (but they are all undirected) through wrong syntax.

2.8.1 Curve (Splines)

The following code shows a case of curve connection. It can be seen that the points to be connected are first defined using the " node " keyword, and then these points are connected using the " edge " keyword. By using different connection symbols, it can be realized Different connection effects.

The code below gives a simple use case.

{ signal: [
  { name: 'A', wave: '01........0....',  node: '.a........j' },
  { name: 'B', wave: '0.1.......0.1..',  node: '..b.......i' },
  { name: 'C', wave: '0..1....0...1..',  node: '...c....h..' },
  { name: 'D', wave: '0...1..0.....1.',  node: '....d..g...' },
  { name: 'E', wave: '0....10.......1',  node: '.....ef....' }
  ],
  edge: [
    'a~b t1', 'c-~a t2', 'c-~>d time 3', 'd~-e',
    'e~>f', 'f->g', 'g-~>h', 'h~>i some text', 'h~->j'
  ]
}

The specific curve definition is shown in the table below:

2.8.2 Sharp lines

The following code shows a case of polyline connection. You can see that the points to be connected are first defined using the " node " keyword, and then they are connected using the " edge " keyword. By using different connection symbols, different connection effect.

The code below gives a simple use case.

{ signal: [
  { name: 'A', wave: '01..0..',  node: '.a..e..' },
  { name: 'B', wave: '0.1..0.',  node: '..b..d.', phase:0.5 },
  { name: 'C', wave: '0..1..0',  node: '...c..f' },
  {                              node: '...g..h' },
  {                              node: '...I..J',  phase:0.5 },
  { name: 'D', wave: '0..1..0',  phase:0.5 }
  ],
  edge: [
    'b-|a t1', 'a-|c t2', 'b-|-c t3', 'c-|->e t4', 'e-|>f more text',
    'e|->d t6', 'c-g', 'f-h', 'g<->h 3 ms', 'I+J 5 ms'
  ]
}

See the following table for specific polyline definitions:

2.9 Drawing with code (Some code)

WaveDrom provides a way to use code for drawing. For example, you can generate sequentially increasing bus signals (such as the following code) through loop iterations, freeing you from repetitive labor.

Simply analyze the code here. By using the keyword " function ", the function is constructed and called at the end to draw the following diagram.

But I guess that for most people, this function may not be used, including myself, I still prefer the WYSIWYG method, so it is not the focus of this article (I don’t understand it too much_(:з) ∠)_).

(function (bits, ticks) {
  var i, t, gray, state, data = [], arr = [];
  for (i = 0; i < bits; i++) {
    arr.push({name: i + '', wave: ''});
    state = 1;
    for (t = 0; t < ticks; t++) {
      data.push(t + '');
      gray = (((t >> 1) ^ t) >> i) & 1;
      arr[i].wave += (gray === state) ? '.' : gray + '';
      state = gray;
    }
  }
  arr.unshift('gray');
  return {signal: [
    {name: 'bin', wave: '='.repeat(ticks), data: data}, arr
  ]};
})(5, 16)

So far is the drawing tutorial of WaveDrom, the next step is to export the generated picture (does anyone still use screenshots?)

3 Image saving and exporting

WaveDrom provides ways to save and export image data, whether it is an offline version or an online version, just click the "≡" button in the lower right corner to find it.

Here are the functions of these buttons:

button

Function
Load... Read stored graphics data files
Save As... Store the current graph data file as json
Export SVG... Export vector graphics
Export PNG... Export PNG image
Rotate Layout... Rotate code area and drawing area
Proportions Modify the ratio of the code area to the drawing area
Expand URL Expand the URL (not quite understand)
WaveDrom Guide Open the official user guide (reading this blog is enough)
on GitHub Open the GitHub project official website

So far, have you learned WaveDrom? I didn't learn to read it again (manual ditch head). 


This is the whole content of this issue. If you like my article, don't forget to like + bookmark + follow, and share it with your friends~

Guess you like

Origin blog.csdn.net/Alex497259/article/details/126307849