Monday, June 30, 2008

Best Free Online TV Viewer

This area is still quite new. But in the last year it has exploded with content and applications. There are still very few standards, so you will end up having several viewer programs if you want to access a wide variety of shows.

What I was looking for was a replacement for cable TV. Once I started finding TVoIP programming I discovered that this just isn't cable TV like I was used to. For one, my favorite cable channels are nearly impossible to find. A&E, Showtime, PBS Kids, Spike TV, CBS, FOX, Comedy Central, C-Span, HSN, The Sci-fi channel, Nick, Movie channel can be found on one service or another. CBS, Fox and CW have made reruns of their past shows available. Not so much ABC or NBC. I also found many independent and international networks that just aren't carried by the cable companies.

When you find shows on the Internet, they will be in one of three forms:
  1. A live video stream, which is like over-the-air broadcasts. In fact many TV stations are making their over-the-air broadcasts available as Live streams. When you connect to a stream, it is like tuning into the station over the air. You join the broadcast in progress. You can't pause it or rewind it (unless you have some sort of PVR software). Many network stations consider streaming video an experiment so the quality can be variable.
  2. RSS feeds, which are better known as video Podcasts or Vcasts. You don't need an iPod to enjoy them. There is software available to receive and watch them on your computer.
  3. Video on demand, which is self-explanatory: you connect to a video server and choose the program you want to watch by using a menu or channel guide.

A quick search will turn up many free internet TV viewers but most are cut down versions of a paid software. There are a few that are not. Some of my favorites (in order) are:

JLC's internet TV viewer. Www.jlc-software.com: A simple, but effective streams viewer that doesn't have much overhead. The channel guide is maintained by the users and is very complete. But I was able to find two local streams that weren't listed (they are now). Users can submit, rate and update the channels. A favorites catagory helps you corral the streams you like. Web cams, porn and spam entries are not allowed in the guide. JLC is not responsible for the quality of the streams, and some are quite poor, or can stop working without warning. The user ratings can help you choose a good stream.

Joost Www.joost.com: A video on demand viewer. Has a very large selection of network content and full shows. One of the nicest and creative user interfaces. Lots of independent shows like Green TV, Soma girls, Indivisual, etc. Content is selected by the Joost staff and is very good. Working to add live streams. Still in beta.

TVUNetworks www.tvunetworks.com: A combination of Live streams and Video on demand. Not as many channals as the others, but you wil find Nickelodian here as well as a lot of content from China.

MIRO: (www.getmiro.com): This one will do live streams like JLC, but also does RSS. Makes heavy use of your hard drive and internet bandwidth because it wants to download everything to your hard drive, TIVO style. The program guide is proloaded, but there is very little network content. If you know where to get your video, you may like Miro.

Bablgum: (www.bablgum.com): Another RSS based viewer. ---yet to be test driven ---

VEOH (www.veoh.com): Video on demand viewer. Re-streams video from the Hulu website and CBS content (allowable) and others. Veoh will tap into the available amature video on the internet. Think of it as agragating YouTube and all it's bretheren. --yet to be test driven --

Vuze (www.vuze.com): Video on demand viewer, doesn’t offer anything that you can’t get elseware. You have to buy the premium content. ---yet to be test driven ---

Video Discovery Full episodes of a few shows from the discovery network (Discovery, History, Animal Planet). Only a few episodes of 4 shows. (blah!). I only mention it because you are likely to stumble upon it. Don't get too excited when you do.

The Amazon Unbox: (www.amazon.com/gp/video/help/faq.html): The viewer is free and there is plenty of content; for $1.99 per episode. Also movie rentals. You can buy videos on line and have them sent to your Tivo. There are better options, in my opinion.

电线插头有几种?

稍微查一下 Wikipedia 的结果大出意料之外:由 Type A 到 Type M,一共有十三种之多。

Type A、Type B

Type A 就是台湾地区的那种两只直的小棒棒的插头,而 Type B 就是多了第三只圆脚的那种。感谢 Gadget 之神,台湾地区和美国、日本用的是一样的插头,所以大部份托朋友带回来的东西都能直接插了就用。但要特别注意的是,日本的电压是 100V,所以要看清楚日本电器上有没有标示支持到 110V。没有的话要买一个 110V -> 100V 的降压器喔!不然娇嫩的日本电器被台湾 110V 的电力硬上的话...下场可是很惨的。

Type A 的一种变型是(以插座来看)左边长、右边短的版本。这种插头是为了避免插反而出现的设计,长的一端是中性线、短的一端是火线。大陆也看得到这种插座,但是和其他插座一样都是 220V 的。台湾的电器带过去前也务必要看清楚啊!

Type C、E、F、H、J、K

CEE 7/16 plug and socket 这一大堆规格都是以 Type C 为基础的,是欧陆加中东和前苏联常见的插头,我国也有在使用。它们共通的的形状是两根间隔 19mm 、直径 4mm 的圆棒子。Type C 是没有地线的基本型,Type E(法国用的)地线公的一头在插座上,插头上则是母的洞,而 Type F(德国用的)地线是接在插头的一侧。

Type H 是以色列在用的版本。以前以色列用的是一种和全世界都不一样的插头,后来改成和 Type C 相通后,插座又要保留接受以前的插头的能力,因此 Type H 的插座设计和其他人不同,地线的位置也不一样。Type J 是瑞士在用的,和其他人不同的地方在于地的位置和插头的形状 -- 瑞士的插头是六角型的。Type K 则是丹麦的规格,同样是差在地线的位置。

这六种在没有地线的时候是可以通用的,所以绝大部份时候都不用担心,但需要有接地线的时候乱插是有可能会让器材短路的。使用这种插头的地区绝大多数是 220V 的。

Type D、M

D Plug Type D 是英国以前在用的规格,形状是三根排成三角型的圆棒子。Type M 长得和 Type D 一样,只是棒子比较粗,能携带的电流也比较大。目前 D 和 M 比较见得到的地区,都是以前的英国殖民地,但除了南非和纳米比亚以此为标准之外,其他地方都在向别的规格过渡,或是兼有多种不同的规格。

Type G

BS 1363 Type G 就是英国现在在用的新规格,是三根离得很远的大方棒子,这也让 Type G 的插头特别大颗。Type G 的插头有个特色,就是依规格,里头要装一个保险丝来保护电线,另外插座上也会设有塑料滑门,防止小孩乱往插座里插东西。也因此一般认为 Type G 是特别安全的一种规格。

Type G 主要的使用地区是英国、爱尔兰和英国的一些前殖民地,也包括香港和澳门。香港现在还是在用 Type G 的插头吧?

Type I

Australian switched 3-pin dual power point (socket) 这是澳洲、纽西兰在用的规格,我国也把它订为标准之一。它的特色是两根主要的供电脚是斜的,与地面呈 30 度角,而剩下的一根地线是直的。阿根廷和乌拉圭也使用这种插头,但火线和中性线是反的。



Type L

23-16/VII with socket 意大利在欧陆国家中是个特例。虽然意大利也有使用 Type C 的插座和插头,但又自已弄出了一个直径比较小的 Type L 插头。Type L 和 Type C 的差别小到硬将 Type C 的插头插进 Type L 的插座是可行的,但要冒着撑坏插座的危险。

加上地线的 Type L 就和其他人都不兼容了。Type L 的地线在火线和中性线的正中央,因此是不分方向的。

Friday, June 27, 2008

Howto, Synopsys

1. Source the appropriate setup file:

source /usr/local/vlsi/SCRIPTS/synopsys-2004.06-setup.bash

2. Add a ".synopsys_dc.setup" file to your home directory, or assert the setup commands by hand, while running synopsys.
A sample .synopsys_dc.setup file can be found here.
The most important commands in this init file are the:
set target_library
set_link_library
set symbol_library
These variables must be set accordingly to the technology library that you are using.

3. Start synopsys:

dc_shell

4. Read the verilog files:

read -f verilog

Issue the read command for each verilog file of your design. If you have vhdl files, the the "-f" flag, which stands for "-format" should be set to
"vhdl" instead of "verilog".
If there are errors in the source files, then synopsys will report an error.

5. Set the working design

current_design

After all of the source files have been read, synopsys treats the *last* module that it read as the working design. This means, that all of the commands
issued after the source have been read, will be executed for the working design and all the modules it includes in hieararchy. If you want to change the
working design, the specify a module using the "current_design" command. Synopsys then will treat the specified module (and all of the modules it
includes in hierarchy) as the working design.

6. Issue the appropriate constraints

Some of the most useful constraint commands are the following:

set_drive
set_load

"Set_drive" sets a "drive" value to the input pins of the working design. "Value" is a value in pF and is typically the drive strength of an inverter
of fanout 4. The exact value of this capacitance can be found in the library datasheet. "Set_load" sets a "load" to the output pins of the working design.
"Value" is expressed in pFand it typically the load of an inverter with fanout 4. The exact value of this load can be found in the library datasheet.

set_false_path [-from ] [-to ]

This command specifies a path which should not be included in the timing analysis. The parameters that it accepts are a "from_list", which can be
anything like input pins, modules, cells, nets, etc. and specifies the startpoints of the false paths, and a "to_list", which specifies the endpoints of the
false paths. It is not mandatory to specify both the startpoints and the endpoints.

set_max_delay [-from ] [-to ]

This commands issues a timing constraint between the "from_list" and the"to_list". The delay between the "from_list" to the "to_list" must not exceed
the "value", which is expressed in ns.

set_fix_hold

This command instructs synopsys to fix any hold violations on "net", which must be a clock net.

set_max_area

This is an area constraint. The area of the working design must not exceed the area defined by "value". If the "value" is set to 0, the synopsys tries
to minimize the area occupied by the working design.

7. Create a clock

create_clock -name -period

This command specifies the clock and the period of the clock. "Name" can be an arbitrary name and "value" must be the period of the clock in ns.
"clock_net" must be the name of the clock as it is defined in the source files.

8. Compile

compile -map_effort

This command synthesizes and technology maps the working design. can be "low", "medium" or "high".

9. Save the results in database format

write -f db -h -o

This commad saves the design in database format. This format can be used by synopsys later in order to re-synthesize, or timing analyze, or explore
the design in any way. The "-h" flag saves the hierarchy of the design, the "-o" flag specifies the output file and "name.db" can be an arbitrary name.

10. Save the netlist

write -f verilog -hierarchy -o

This command saves the synthesized netlist in verilog format.

11. Write an SDF file

write_sdf -version 1.0

This command writes an SDF file to be used for simulation. "-version" specifies the version of the SDF file, which must be "1.0" in order to be
compatible with the available simulation tools.

12. Perform timing and area analysis

report_timing
report_area

These commands perform a timing and and an area analysis. "report_timing" calculates the delay of the most critical path and reports it's delay.
If this delay does not meet the timing constraints, the a NEGative slack is reported. "report_area" reports the area required by the working design
expressed in um^2.

13. Exit synopsys

exit

Wednesday, June 25, 2008

国家公园:黄石国家公园



   黄石国家公园(Yellowstone National Park)位于美国(The United States of America)西部北落 基山和中落基山之间的熔岩高原上,绝大部分在怀俄明州的西北部。海拔2,134-2,438米,面积8,956平方公里。
  黄石河、黄石湖纵贯其中,有峡谷、瀑布、温泉以及间歇喷泉等,景色秀丽,引人入胜。其中尤以每小时喷水一次的“老实泉”最著名。园内森林茂密,还牧养了一些残存的野生动物如美洲野牛等,供人观赏。园内设有历史古迹博物馆。
自从1872年黄石公园创办以来,已有六千多万人来此观光。游人来自五湖四海,形形色色,所获得的感受自然也就丰富多彩,各不相同:有赏心悦目的赞美,有敬畏或惊诧的感叹,有肃然起敬的沉思,有惊险恐惧的刺激,有对大自然威力和宁静的领悟,还有悲喜交加的经历……

  黄石公园是世界上最原始最古老的国家公园。根据1872年3月1日的美国国会法案,黄石公园“为了人民的利益被批准成为公众的公园及娱乐场所”,同时也是“为了使她所有的树木,矿石的沉积物,自然奇观和风景,以及其他景物都保持现有的自然状态而免于破坏”。
  
  在辽阔的怀俄明州自然森林区内,黄石国家公园占地约9,000平方公里。在那里可以看到令人印象深刻的地热现象,同时还有3,000多眼间歇泉,喷气孔和温泉。黄石国家公园还以拥有灰熊,狼,野牛和麋鹿(不是中国的那种))等野生动物而闻名于世。

  最初吸引人们的兴趣并使黄石成为国家公园的显著特征是地质方面的地热现象,这里拥有比世界上其他所有地方都多的间歇泉和温泉、彩色的黄石河大峡谷、化石森林,以及黄石湖。

   根据这里的文化遗迹可以判断黄石公园的文明史可以追溯到12000年前。更近的历史可以从这里的历史建筑,以及各个时期保存下来的公园管理人员和游人的 公用设施看出来。公园99%的面积都尚未开发,从而大量的生物种类得以繁衍,这里拥有陆地上最大数量的,种类也最多的哺乳动物。

  黄石公园是一个实实在在的荒野,是保存于美国48个州中少有的大面积自然环境之一,在这里,你可以感受自然。六、七、八月是参观的高峰时期,公园为了保护游人的安全、保护各种自然文化遗产,制定了各种规章制度。

   黄石国家公园是全世界第一个国家公园,也是1978年最早进入《世界遗产名录》的项目,公园的主体部分位于怀俄明州的西北角,部分延伸到蒙大拿州西南部 以及爱达荷州的东部。面积为7988平方千米(注:此为《国家公园探索之旅丛书—美国国家公园》一书数据;而2002/6期《人与自然》画册数据为 2219833英亩;www.whgx.library.sh.cn网的数据为3400平方英里)。

  黄石公园,这个这个冰火磨砺的 世界、犬牙交错的幻境,诞生于近两百万年前的一次火山爆发,全境99%尚未开发,这是一片广袤而洁净的原始自然区,分布在落基山脉最高峰,丰沛的雨水是这 里成为美国众多大河的发源地,在这个平均高度为8000英尺的开阔火成岩高原上,有山峦、石林、冲蚀熔岩流和黑曜岩山等地质奇观。

  黄石国家公园是美国设立最早、规模最大的国家公园。它就像中国的长城一样,是外国游客必游之处。它以保持自然环境的本色而著称于世。

   黄石国家公园内的另一景观是黄石河,它由黄石峡谷汹涌而出,贯穿整个黄石公园到达蒙大拿州境内。黄石河将山脉切穿而创造了神奇的黄石大峡谷。在阳光下, 两峡壁的颜色从橙黄过渡到橘红,仿佛是两条曲折的彩带。由于公园地势高,黄石河及其支流深深地切入峡谷,形成许多激瀑布,蔚为壮观。




Friday, June 20, 2008

Ubuntu Linux 下的经典游戏大全

你在用 Ubuntu Linux 之余,也许还要用Ubuntu Linux 来玩玩游戏吧!虽然Ubuntu Linux 用户可玩到 3D 游戏远远不如 Windows ,但 Ubuntu Linux 中的游戏也不乏精品,这里列出了几款免费的 Ubuntu Linux 中的游戏,这些 Ubuntu Linux 中的游戏,都是原生的,不需要运行 Wine 来模拟这些游戏。很多都是非常知名的 Linux 游戏,在很多地方可能都有介绍。

偶尔在网上和群里看到一些 Ubuntu Linux 小游戏,说挺不错,累了的时候不想玩什么大游戏,就收集了一些 Ubuntu Linux 小游戏并玩了一下,感觉 不错,特分享一下解解闷儿.

下面的这些 Ubuntu Linux 游戏大多数都是用通过 APT 的方式来安装的,测试环境是 Ubuntu 8.04 采用的是台湾的软件源,其它的源不能保证一定能通过 APT 的方式安装,当然你可以试试看,如果不能安装,请手动添加这些软件源。

增加以下软件源:


deb http://tw.archive.ubuntu.com/ubuntu/ hardy main restricted deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy main restricted deb http://tw.archive.ubuntu.com/ubuntu/ hardy-updates main restricted deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy-updates main restricted deb http://tw.archive.ubuntu.com/ubuntu/ hardy universe deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy universe deb http://tw.archive.ubuntu.com/ubuntu/ hardy-updates universe deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy-updates universe deb http://tw.archive.ubuntu.com/ubuntu/ hardy multiverse deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy multiverse deb http://tw.archive.ubuntu.com/ubuntu/ hardy-updates multiverse deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy-updates multiverse deb http://tw.archive.ubuntu.com/ubuntu/ hardy-security main restricted deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy-security main restricted deb http://tw.archive.ubuntu.com/ubuntu/ hardy-security universe deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy-security universe deb http://tw.archive.ubuntu.com/ubuntu/ hardy-security multiverse deb-src http://tw.archive.ubuntu.com/ubuntu/ hardy-security multiverse


如果你不会增加软件源请看这里: Ubuntu 8.04 LTS (Hardy Heron)软件源设置指南



1.supertuxkart

类似于跑跑卡丁车的游戏

右边就是我截 的图,画面质量不怎么好,

但能在LINUX下开个类似于跑跑卡丁车还是不错的,源里有下载 。




sudo apt-get install supertuxkare supertuxkare-data



2.neverputt 高尔夫球

画面看着不怎么样,但是玩的容易容易入迷,比如我,我不喜欢玩游戏,但是这个游戏玩的,怪好玩的来,赢了还想玩,输了不服气再玩。







sudo apt-get install neverputt



3。neverball 平衡球

这个 小游戏考验一个平衡,windows下也有一个平衡球的游戏,不知道大家有没有玩过,挺 耐玩的一个游戏,没想到源里也有,哇哇之下装了一个,我平衡感一般,老是东倒西歪的。









sudo apt-get install neverball neverdate



4。btanks 3D坦克

我很郁闷的是这个游戏,我搞了半天,我一点都不会玩,成心气我的,搞了半天,玩不好,有喜欢玩的可以研究吧,会玩的玩告诉我下怎么玩的,谢谢啦。









sudo apt-get install btanks-data liblua btanks

5.assaultcube

这个游戏玩法类似CS,看看右边的图就知道了,不用多说。不过操作上面的我搞了半天,仍然不知道怎么玩的,只会逛街发发子弹,有会玩的可以告诉我下,谢谢啦。












sudo apt-get install assaultcube assaultcube-data

6.nexuiz

3D第一人称枪战游戏,同上面一样,也不知道怎么玩,虽然游戏看着眼馋,也流口水,可不会玩啊,知道的也告诉我怎么玩啊,也谢谢了。











sudo apt-get install nexuiz nexuiz-data nexuiz-music



7.openarena

什么类型的游戏不清楚,哭死,又是一个不会玩的游戏,太郁闷了,连菜单在哪里找我也不知道按什么键的,如果有高手知道怎么玩,也告诉我一下哈,在此谢谢了。








sudo apt-get install openarena openarena-data

8.alien arena

看起来像是恐怖游戏的样子,没玩过,正在安装中,不知道怎么个玩法。











sudo apt-get install alien libbeecrypt6 librpm4.4 rpm alien-arena alien-arena-data



9.boswars

类型红警的游戏,这下玩红警的朋友可高兴了,至于 里面的较果如何,那就不知道了,可以玩玩体验体验吧,觉得玩的不错,在此留下你的体验,不知道怎么操作,没办法,先谢谢啦。安装是先装 上面的,然后再装下面的,网上是这么说的,不知道什么原因。










下载地址:

ftp://darkstar.ist.utl.pt/pub/getdeb/ubuntu/hardy/bo/boswars-data_2.5-1~getdeb2_all.deb

http://imhotep.unizar.es/getdeb/ubuntu/hardy/bo/boswars_2.5-1~getdeb2_i386.deb



10. ManiaDr



看上去像极品飞车,画面质量一般,里面的情况如何,还要请玩家去体验了,虽然丑点,但总比没有的强吧。源里有没有还没试,你们可以去试试源里有没有这个。安装先装第一个,然后再下一步,具体不明。现提供下载地址:





http://harrisony.com/getdeb.net/ubuntu/hardy/ma/maniadrive-data_1.2-0~getdeb3_all.deb

http://getdeb-mirror.resonar.de/archive/ubuntu/hardy/ma/maniadrive_1.2-0~getdeb3_i386.deb

Monday, June 16, 2008

CCNA First Day

From the title, it seems that today is the first that I start my study. But in fact I have had 4 weeks classes yet. But why I still call today the first day. Because it is the first day I really put my heart on it and record my everything about this learning in my blog. Hope this can help to force me to work hard on it and pass the exams.

This weekend I will have two days classes and they are the last classes for CCNA. But I still have a lot of things do not understand very well on the router protocols, such as RIP, EIGRP and OSPF. (I think those are all what I learned in CCNA.)

I transfer from Sunday class to Weekend class. That makes me miss the SPAN tree, switch configuration and VLAN sudy. I think these days I should study it by myself and catch up others.

The good news is this weekend, the teacher will teach us about the router protocol. I can try to ask some question to make me understand them better.

OK. Let me find what's in the CD about CCNA. It is also the first time I brower it (another first day).
1. The Appointment Flow for the remote access lab.
2. Link of the network topology.
...

20 余款与父亲节有关的互联网资源

【礼物】

FamilyCorner.com
FamilyFun.com
Gifts.com
Kaboose.com
MarthaStewart.com
Shopping.AOL.com

【美食】

AllRecipes.com
BetterRecipes.com
Epicurious.com
FabulousFoods.com
FoodNetwork.com
iVillage.com
KraftFoods.com
StarChefs.com 【其他】

Apples4TheTeacher.com
BHG.com
FathersDayCelebration.com
History.com
Holidays.net
TheHolidaySpot.com

Wednesday, June 11, 2008

How to generate Gray Codes for non-power-of-2 sequences

Introduction
In the not-so-distant past, I published a mini-series of four "Logic 101" articles encompassing Assertion-Level Logic, Positive-vs-Negative Logic, Reed-Muller Logic, and Gray Codes.

More recently, a reader posed an interesting question with regard to using Gray codes for FIFO counters. This question was: "Is it possible to generate a Gray code counter/sequence for any non-power-of-2 number (so long as it is an even number)? (Click Here to see the original question in more detail.)

Being up to my ears in alligators fighting fires (I never metaphor I didn't like), I posed this query to the readers of Programmable Logic DesignLine (www.pldesignline.com) and was soon deluged with responses. The thing that amazed me the most was that folks attacked this problem from so many angles and came up with so many different solutions.

What was the question again?
Just to make sure we're all tap-dancing to the same drum beat, let's quickly remind ourselves as to the original problem. Suppose we have a FIFO (First-In First-Out) memory for which we will require a read pointer and a write pointer.

As a starting point, let's assume that the size of the FIFO (the number of words it contains) is a power of 2 – let's say 2^4 = 16 words. One way to implement our read and write pointers would be as binary counters, which means they are each going to be 4 bits wide. The problem here is that multiple bits may change when transitioning from one value to another. For example, four bits change when one of the pointers transitions from 7 to 8 (0111 to 1000 in binary). As an alternative, we can use a Gray code counter, in which only one bit changes as we transition from one value to another.


1. Binary code versus 4-bit Gray code.

Observe that when we reach the final (maximum) Gray code value of 1000, the next "count" will return us to our initial value of 0000, which means that – as we expect – only a single bit changes for this transition also.

But now suppose that – instead of having 16 words, we wish our FIFO to contain only 10 words. If we use our original Gray code as shown above, the sequence will now be as follows: 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, 1101. The problem is that three bits will change value on the next transition, which will return us to our starting value of 0000 from our current value of 1101.

So, is it possible to create a Gray code sequence for any non-power-of-2 number (so long as it is an even number)? Let us see. . .

A sledgehammer approach
Actually, before we leap into the fray, I did receive one email that read as follows:

I'm sure someone will have a more formal proof, but logically you can think of the grey code counter as walking though a Karnaugh map of the counter bits. Given this, you can always extend the "walk" by two. For example, one step right becomes down, right, up. So, I'm confident you can conclude that the grey code sequence always exists.

Well, so long as we're all confident (grin). But I was hoping for a little more than this. Now, several readers took a "sledgehammer" approach whereby they hard-coded a solution without looking for an underlying structure. For example, one reader sent the following sequence with an accompanying one-line message saying: "Not an algorithm, but it appears to work."


2. A hard-coded sledgehammer approach.

As we shall see, this solution is unknowingly based on the "adjacent pairs" technique presented in the next topic. The snag here is that I simplified the problem for the purposes of my blog. In reality, the guy who posed the original question is looking to create a FIFO with a memory size of 1128, which means we really require some algorithmic way to do this rather than hammering it out by hand.

Throwing away adjacent pairs
Quite a few readers noted that – using our original gray code as the base code – wherever you have a pair of adjacent states where the least-significant bit does not change, then the states before and after such a pair always differ by exactly one bit.


3. Throwing away adjacent pairs.

For example, consider the first four codes in the left-hand table: 0000, 0001, 0011, 0010. If we remove the two shaded codes (0001 and 0011) we are left with 0000 and 0010, which differ by only one bit. So by removing one pair from the left-hand table we have a 14-count sequence, removing any two pairs gives us a 12-count sequence, and removing any three pairs gives us a 10-count sequence (it would be pointless to remove four pairs to give us an 8-count sequence, because we could achieve the same effect by dropping down to a 3-bit Gray code).

In fact, we can mix-and-match to some extent, because we could remove one pair of codes whose least-significant bit was 1 and another pair whose least-significant bit was 0 so long as these pairs are not themselves adjacent to each other.
Pruning the middle
Now, the previous solution is easy to use by hand, but it's not great as the basis for an algorithmic approach, because it would require us to keep track as to which pairs of codes we've removed.

In fact, the solution is rather simple. Remember that we generated our original 4-bit Gray code using what I call the "mirroring method" (see my Original Article for more details) – a more correct name might be to call this a "recursive reverse-and-prefix" approach.

Well, several readers noted that is possible to simply remove pairs of entries from the center of the table around the "mirror line", although everyone expressed themselves in different ways. For example, one message simply said:

It's quite easy to build gray codes which other sequences numbers then 2,4,8,16 etc. Just use the mirror technique and stop the right position.

Other folks went into a little more detail, such as the contributor who noted:

Here's a method that works for any number that can be divided by two. Let's say your even number is 58, in which case the next highest power of two is 64. So, we begin by generating a Gray code sequence for 64, BUT we stop at 29 (halfway to 58). We then forget about the rest of the "64" Gray codes, replace the MSB with a 1 (just like normal Gray codes), and mirror our original 29 codes (down to 0).

Let's look at this in a little more detail. As shown in the following figure, if we desire a 14-count sequence, we simply remove two entries from the middle – the one immediately above the "mirror" line and one immediately below. Similarly, if we are looking for a 12-count sequence, we remove two entries above the "mirror" line and two below, and so forth.


4. Pruning the middle of the sequence.

Pruning the ends
There's always another way of doing something. For example, quite a few folks came up with a logical counterpart to the previous solution. A typical suggestion was as follows:

I just read the article in which you asked how to create a non-power-of-2 modulo Gray code counter. I believe there are a lot of ways to achieve this, but I think that probably simplest one is to remove the same numbers of entries from the top and from the bottom of a traditional power-of-2 Gray code counter.

And of course, this is also perfectly correct. As shown in the following figure, if we desire a 14-count sequence, we simply remove one entry from the top of the table and one from the bottom; if we are looking for a 12-count sequence, we remove two entries from the top and two from the bottom, and so forth.


5. Pruning the ends of the sequence.

And what about ring and twisted-ring counters? As discussed in the relevant Wikipedia Entry a Ring Counter (or Overbeck Counter) is formed from a circular shift register where the output from the last register element is fed back into the input to the first (this is classified as a "counter" because it cycles through a specific sequence of states). Such a counter is used to circulate a single one (or zero) around the ring. So if we wanted a 10-state count, we would require a 10-element shift register as illustrated below:


6. A 10-bit ring counter sequence.

Of course, this does us absolutely no good at all because this isn't a Gray code sequence (two bits change for every transition). But suppose we use a Twisted Ring Counter (or Johnson Counter) in which the output from the last stage is inverted before being fed back to the input to the first stage. In this case, a 5-bit counter will provide us with the following 10-count sequence:


7. A 5-bit twisted ring counter sequence.

In conclusion
Good Grief Charlie Brown. There's a lot more to this than meets the eye. Actually, I haven't even touched on the really interesting stuff yet, because I have some cunning ideas I'm mulling over in the back of my mind (there's just too much to do and too little time to do it all in).

But before we close, there are a couple of things you might be interested in reading and/or playing with. First of all, you may wish to check the fairly wide-ranging Wikipedia Entry on Gray codes. In addition to the Gray code sequence upon which we've based our discussions, there are also Beckett"Gray codes, Snake-in-the-Box codes, Single-Track Gray codes and n-ary Gray codes (there are also known as non-Boolean Gray codes).