November 2, 2020

Playing with FPGA (simulator)

Although I've wanted to try out FPGA for a long time, but never really had the chance/time to.  This is a note on learning/playing with FPGA.

In this posting, which is just the first step -- learning about it, and use simulator first.  If/when I decide to continue with this journey, I'll then buy a small FPGA board, and continue.

I've gathered the information by talking to some experts online, googling, and read a few books.

What is FPGA (Field Programmable Gate Array)

First, what FPGA is.  Watch this short video - only 1:25 long -

Or, read Wiki,

Installing Simulator

There are several simulators, and someone suggested to use Icarus Verilog ( as it is light. 

Environment: Ubuntu 20.04

I've originally downloaded the source code and compiled, but later found Ubuntu already has apt package ready.  

Reference video, -- this is in Chinese, so no clue what the video uploader is saying, but you can just watch the video with steps.  I wrote the steps here to avoid watching the whole thing.

$ sudo apt-get install iverilog
$ sudo apt-get install gtkwave


Testing Simulator #1

1. Create project directory

$ mkdir verilog_test1

2. Using VSC, edit a file called "test1.v" in the directory created above:

module main;
$display("Hello world!");

3. compile the code

$ iverilog test1.v -o test1

4. Run it

$ vvp test1


Testing Simulator #2

This is from, and it also shows installing Icarus Verilog on Windows.

1. Create two files


// hello.v
module hello(A, B);

input A;
output B;
assign B = A;



// hello_tb.v

`timescale 1ns / 1ns
`include "hello.v"

module hello_tb;

reg A;
wire B;

hello uut(A, B);

initial begin
$dumpvars(0, hello_tb);

A = 0; // single bit
#20; // wait for 20ns, to view wave form

A = 1;

A = 0;

$display("Test complete");


2. Compile and run

$ iverilog -o hello_tb.vvp hello_tb.v
$ vvp hello_tb.vvp
VCD info: dumpfile hello_tb.vcd opened for output.
Test complete

hello_tb.vvp file is created.


3. View wave

$  gtkwave hello_tb.vcd

or, File > Open Tab > and select "hello_tb.vcd"

In left nav, lower pane, select both reg A, wire B.  Then click on "Insert" button.


Learning Resources

August 27, 2020

UPS for Ubuntu 20

Recently purchased two new UPS, one for Windows, another one for Ubuntu workstation. (UPS:

Model: APC UPS, 1500VA UPS Battery Backup & Surge Protector, BX1500M


APC UPS, 1500VA UPS Battery Backup & Surge Protector, BX1500M Backup Battery, AVR, Dataline Protection and LCD Display, Back-UPS Pro Uninterruptible Power Supply

Plugged in the workstation, mid-size LCD monitor, USB hub with external power, having several devices with it, and 8 bay USB external drive.  UPS shows it can run on battery for about 60 min with everything turned on.

With recent frequent storms, power goes out briefly occasionally and this will save me from the trouble while I'm working on my computer.

S/W on Ubuntu

  • apcupsd: daemon process communicating with APC UPS
  • apcupsd-cgi: providing Web UI for APC UPS status
  • There was an old GUI application, but it no longer runs on Ubuntu 20, and not supported.


$ sudo apt-get install apcupsd

If Web UI is desired, install apache:

$ sudo apt-get install apache2 apcupsd-cgi

$ apt list --installed | grep apcupsd

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

apcupsd-cgi/focal,now 3.14.14-3build1 amd64 [installed]
apcupsd-doc/focal,focal,now 3.14.14-3build1 all [installed,automatic]
apcupsd/focal,now 3.14.14-3build1 amd64 [installed]


I installed apcupsd-cgi although web server is not installed.  This is to analyze the CGI programs to see if I can build a front-end app without web server.  It turns out that the CGI programs are not necessary to build a GUI front-end.  I'll explain this in later section of this posting.



Configuration files:
/etc/apcupsd/apcupsd.conf   # main
/etc/apcupsd/hosts.conf     # if other computers use this UPS
/etc/apcupsd/multimon.conf  # fields to use in CGI

Executables are in this directory,


CGI Files,
If Apache is installed, the Web UI screen can be accessed with this URL:

/usr/lib/cgi-bin/apcupsd/multimon.cgi    #
/usr/lib/cgi-bin/apcupsd/upsfstats.cgi   # works as /sbin/apcaccess
/usr/lib/cgi-bin/apcupsd/upsimage.cgi    # graph generator
/usr/lib/cgi-bin/apcupsd/upsstats.cgi    #


Set up

For my environment, there is only one computer is using this UPS, attached via USB, and email is not configured.

$ sudo vi /etc/apcupsd/apcupsd.conf
BATTERYLEVEL 5  # shutdown at battery level percentage
MINUTES 5       # remaining runtime in minutes in case of power failure to shutdown
DEVICE          # blank entry for USB

$ sudo vi /etc/default/apcupsd

$ sudo cp /etc/apcupsd/apccontrol.orig /etc/apcupsd/apccontrol 

$ sudo systemctl restart apcupsd.service

CGI output analysis

All the CGIs come with the apcupsd-cgi package can run in console with proper environment variable set up.  The output is stored at:

(short URL,

Upon examining the output HTMLs from the CGIs, it's nothing but providing nice looking web interface by parsing output from running apcaccess, and the log.

By issuesing man apcaccess you will see what the apcaccess output fields mean.

To build a simple GUI app just like gapcmon (see below under Reference), parsing this output is sufficient.  To provide GUI configuration screen, then it needs to provide a form and updating the configuration file, restarting the daemon process -- this will require privileged access level.

Idea - gnome shell extension would be nice, or wxPython or Tk app is good also.


August 26, 2020

Voilà for Jupyter

"Voilà turns Jupyter notebooks into standalone web applications."

$ conda install voila -c conda-forge