Thursday, July 30, 2015

[VHDL] Some common mistakes I encountered while learning VHDL

Process blocks have some similarity to sequential software programmes, but they *don't* work like software programmes. Common examples:

1. Multiple assignments of same signal at different places at process block


If you have multiple assignments of a signal at different places at process block, then *only one* of them is executed. And, that one assignment would be the one which appeared last *after* all  conditional statements are checked. So, Order does matter.

For example:

FIXME: Add example probably using EDAPlayground


2. Signals read inside process block are always of *previous* cycle, i.e, before clock edge whereas signals are written at clock edge


 Inside process block, suppose if you have assigned a signal a new value, and just at next statement you are checking its value with an 'If' statement, then the value of signal read by the If statement will be of previous cycle, and not be the value you just assigned before

For example:

FIXME: Add example probably using EDAPlayground

3. For Pipelining registers, order doesn't matter


This is actually an extension of 2nd point. Suppose we want to assign value of 'a' to 'b' and of 'b' to 'c'. Then in case of software, order does matter.

// Correct
a = b;
b = c;

// Incorrect
b = c;
a = b


But, is case of VHDL inside process block:

a <= b;
b <= c;

b <= c;
a <= b;

Both are correct, since order doesn't matter. This is because of point 2. Here, in latter approach, In a single clock edge, 'b' will be assigned previous-cycle-value of 'c' and 'a' will be assigned previous-cycle-value of 'b'.

Unlike you are probably expecting that 'b' will be assigned previous-cycle-value of 'c' and then 'a' will be assigned updated 'b' (which would require 2 clock edges). Instead the case is that 'a' will also be assigned previous-cycle-value of 'b'.

Related to point 3: http://electronics.stackexchange.com/questions/108399/vhdl-question-sequential-execution-within-a-process

Wednesday, July 29, 2015

[xrandr] Setting custom resolution for VGA Monitor for Dual monitor setup

When I connected my VGA Monitor to my Laptop, in-addition to an HDMI Monitor for  Dual-Monitor setup, my system was showing only 1024x768 as maximum possible resolution, which was incorrect since I knew my monitor had 1440x900 native resolution.


I used following commands to correctly set up the resolutions:

1. First ran xrandr :
xrandr

I got this output:

Screen 0: minimum 320 x 200, current 4310 x 1080, maximum 32767 x 32767
LVDS1 connected (normal left inverted right x axis y axis)
   1366x768       60.0 +   40.0  
   1360x768       59.8     60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
VGA1 connected 1024x768+3286+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768       60.0* 
   800x600        60.3     56.2  
   848x480        60.0  
   640x480        59.9  
HDMI1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 476mm x 267mm
   1920x1080      60.0*+   50.0     59.9  
   1920x1080i     60.1     50.0     60.0  
   1280x1024      75.0     60.0  
   1152x864       75.0  
   1280x720       60.0     50.0     59.9  
   1440x576i      50.1  
   1024x768       75.1     60.0  
   1440x480i      60.1     60.1  
   800x600        75.0     60.3  
   720x576        50.0  
   720x480        60.0     59.9  
   640x480        75.0     60.0     59.9  
   720x400        70.1  
DP1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)


2. Next I used gtf to get-timing-format for 1440x900@60Hz:
gtf 1440 900 60
Output from it was :

  # 1440x900 @ 60.00 Hz (GTF) hsync: 55.92 kHz; pclk: 106.47 MHz
  Modeline "1440x900_60.00"  106.47  1440 1520 1672 1904  900 901 904 932  -HSync +Vsync



3. Then I used following commands to add this mode, bind it to VGA1, then set my VGA1 interface to this mode:
xrandr --newmode "1440x900_60.00"  106.47  1440 1520 1672 1904  900 901 904 932  -HSync +Vsync
xrandr --addmode VGA1 1440x900_60.00
xrandr --output VGA1 --mode 1440x900_60.00

And voila, my old VGA monitor is now working perfectly in Dual Monitor configuration, outputting 1440x900 @ 60Hz!


Reference:
  1. https://bbs.archlinux.org/viewtopic.php?id=73738
  2. GTF: http://linuxcommand.org/man_pages/gtf1.html
  3. XRandr: https://pkg-xorg.alioth.debian.org/howto/use-xrandr.html
  4. http://askubuntu.com/questions/377937/how-to-set-a-custom-resolution

Getting started with STM8 Development on Linux

Introduction 


A month ago, I came across a cheapest STM8 development board on eBay. They came for $0.98 (USD) and charged $0.25 for shipping and were based on STM8S103F3P6 microcontrollers. Now, I have never worked with STM8 so decided to try it out. I went ahead and ordered from eBay:

Incidentally, the good seller from China sent me 2 extra boards for free! Yay! :)  They took around a month to get reach me. So, under $9, I had a fully ready development hardware, consisting of 6 STM8 Development Boards and a very useful ST-Link v2 debugger which could be used for STM32 boards as well!! Awesome!



STM8 Development on Linux


The official STM8 toolchain from ST is windows only. I searched the net, and found that SDCC has support for STM8 and also found an awesome resource on setting it up, from here: http://www.cnx-software.com/2015/04/13/how-to-program-stm8s-1-board-in-linux/ 

Requirements:


Lets start with SDCC setup.

For Ubuntu 14.10 or higher just type
sudo apt-get install sdcc
But mine was Ubuntu 14.04, and as told by [cnxsoft] my installed version was older. So, I followed the steps mentioned in his article
sudo add-apt-repository ppa:laczik/ppa
sudo apt-get update
sudo apt-get remove sdcc sdcc-libraries
sudo apt-get install sdcc 
This installed the latest version on my system. Our next target is to compile and install stm8flash
Follow these steps:
git clone https://github.com/vdudouyt/stm8flash
cd stm8flash
make
sudo make install
Now, we need some starting template for our first code. For this, we clone the STM8 Examples for SDCC by Valentin
git clone https://github.com/vdudouyt/sdcc-examples-stm8
cd sdcc-examples-stm8

Edit the Makefile in the directory sdcc-examples-stm8 and remove the "sp_test.ihx" part from it.

Use the modified code from cnxsoft


 
include "stm8l.h"

int main() {
        int d;
        // Configure pins
        PB_DDR = 0x20;
        PB_CR1 = 0x20;
        // Loop
        do {
                PB_ODR ^= 0x20;
                for(d = 0; d < 29000; d++) { }
        } while(1);
}

and then type:
make
It would show some output similar to this:
sdcc -lstm8 -mstm8 --out-fmt-ihx   blinky.c
Now, Finally to upload the program to the board, use:
sudo stm8flash -c stlinkv2 -p stm8s103 -w blinky.ihx

It would show output similar to this:
Determine FLASH area
Writing Intel hex file 189 bytes at 0x8000... OK
Bytes written: 189

Congrats, you should now have a blinking green LED!

Blinking LED on STM8 Minimum System Development Board

 

Video:

Tuesday, July 28, 2015

Kalam Sir


Yesterday, my friend informed me that Former President, Dr. APJ Abdul Kalam had fallen ill during a lecture at IIM Shillong. I started praying for his health but also feared the worst. His advance age had started taking toll on his health. He had also been ill sometime back and was treated at Army Hospital, Delhi Cantonment.

Soon after, news appeared that Dr. Kalam was gone.

I was shocked, unable to comprehend anything. I was not ready to accept the news because this was a very personal loss for me.

My immediate reaction was to quit WhatsApp and Facebook. I needed to be alone, and not the constant meddling of social media in my life at that moment.


Dr. Kalam was not only a Former President, he was my childhood hero. An inspiration. A role model. For the last 10 years, he was my guidance, even though I've not met him once.

I first got to know about Kalam Sir from my Hindi text book of class 3rd (around 2001). Being a mediocre student those days, I had hazy ideas about him and his work. I had no idea of cryptic words like प्रक्षेपणास्त्र (prakshepanastra, meaning Missiles) or पर्माणु बम (parmanu bam, meaning Atomic Bomb). I just remembered five words: prithvi, agni, akaash, trishul and nag.

Five years later in class 8th, I got a book "Wings of Fire" from an acquaintance. This book really transformed me and opened up a new myself in me. Dr. Kalam was born in Rameshwaram and with his hard work and dedication, went on to become a Rocket Scientist and lead various projects of national importance, namely Satellite Launch Vehicle (SLV) at ISRO and Integrated Guided Missile Development Program (IGMDP) at DRDO. SLV and IGMDP programs were responsible for putting India onto world's technological map. He was also in-charge of overseeing Pokharan-II. He created the very base upon which India could stand technologically!

Wings of Fire was the book that told millions of Indian children and other people to never feel small and helpless, and to believe in themselves. He inspired me to dream big, dream high and proved that anything can be achieved by hard work and sheer determination. He gave wings to my dreams to fly high and far. His own life story of journey from being a fisherman's child to India's topmost scientist inspired a billion-people country of India. Whatever I'm today, I can trace that to his inspiration, teaching and guidance. I would not be what I'm today if it were not for him. He taught me to dream, and dream big, and shaped my overall personality.

He convinced every Indian that India can be technologically competent in every field it wants even with lowest resources and active technology-denial. He told us to not be content with "sixth-country" thing. He told that dreams of great thinkers are always transcended.

Dreams float on a impatient wind
A wind that wants to create a new order
An order of strength and thundering of fire

I'm reminded of his quote from the book Wings of Fire,
 "Let not thy winged days be spent in vain. When once gone no gold can buy them back again."

Today, I feel as if my wings got clipped today. As if a part of me is no more. :'( I had dearly wanted you to meet you atleast once.

You'll always be remembered, Kalam Sir. I'll try my best to follow your teachings, principles and guidance.

I owe you an India you always dreamt of, Kalam Sir. RIP  :'(



Dr. APJ Abdul Kalam
Do not look at Agni
as an entity directed upward
to deter the ominous
or exhibit your might.
It is fire
in the heart of an Indian.
Do not even give it
the form of a missile
as it clings to the
burning pride of this nation
and thus is bright
 - APJ Abdul Kalam

Sunday, March 1, 2015

Tiva ARM development in Linux with Eclipse and OpenOCD

I had a requirement for setting up Tiva Launchpad (TM4C124GH6PM, Cortex-M4) toolchain and development environment on Linux (Ubuntu 14.04 with Kubuntu-desktop installed). I needed OpenOCD for debugging, eclipse as IDE and open source arm-gcc toolchain. The links below proved immensely helpful. So, I thought I might as well share them.

Useful resources:
  1. http://mostlyanalog.blogspot.in/2014/09/msp430arm-development-on-linux.html
  2. http://alvarop.com/2013/02/debugging-arm-cortex-m3-devices-with-gdb-and-openocd/
  3. http://fun-tech.se/stm32/OpenOCD/gdb.php
  4. http://kernelhacks.blogspot.in/2012/11/the-complete-tutorial-for-stellaris.html
  5. http://kernelhacks.blogspot.in/2012/11/the-complete-tutorial-for-stellaris_23.html
  6. http://kernelhacks.blogspot.in/2012/11/the-complete-tutorial-for-stellaris_25.html
  7. http://chrisrm.com/howto-develop-on-the-ti-tiva-launchpad-using-linux/
  8. http://gnuarmeclipse.livius.net/blog/openocd-debugging/
  9. http://gnuarmeclipse.livius.net/blog/openocd-install/
  10. http://gnuarmeclipse.livius.net/wiki/Main_Page#OpenOCD
  11. http://www.strainu.ro/programming/embedded/programming-for-the-tiva-c-launchpad-on-linux/

Other useful links:
  • http://electronics.stackexchange.com/questions/95183/move-embedded-programming-from-keil-to-linux
  • http://www.cesareriva.com/install-segger-j-link-tools-on-gnulinux-x64-machine/
  •  http://www.timesys.com/embedded-linux/docs/Debug_Linux_kernel_with_a_JTAG_from_Segger
  • https://openwsn.atlassian.net/wiki/display/OW/GDB+and+Jlink+on+Eclipse+in+Linux

[Fix]: Code Composer Studio crash on KDE

My Code Composer Studio (CCS 6.1) used to crash every-time I open "New CCS Project" dialog. Turns out, this is a bug with 'oxygen-gtk' theme for gtk2.0 on KDE. Kubuntu linux users or Ubuntu users with KDE installed, are affected by this.

There are few workarounds to this.

Here are the links I found  useful:
  1. http://stackoverflow.com/questions/26436009/eclipse-luna-crashes-on-new-project-in-ubuntu
  2. http://askubuntu.com/questions/513471/kubuntu-14-04eclipse-adt-crashes-at-button-ok-from-project-properties
Other option might to be change the theme itself from "System Settings -> Application Appearance -> GTK". I chose to fix the oxygen theme, since I find it to be more pleasant.

Sunday, March 16, 2014

PartKeepr installation on Ubuntu (or Kubuntu)


For my personal electronics components management, I installed PartKeepr. This article details steps required to install it on Ubuntu/Kubuntu. I've the tried the steps on both Ubuntu 12.10 and Kubuntu 12.04, both desktop version.

 

What is PartKeepr?


PartKeepr (www.partkeepr.org) is an open source inventory manage system, primarily designed for electronic components. 
I generally lose track of my (however small) personal inventory of electronic components. Also, some important components may be in use in some projects. This is where PartKeepr comes in! It fulfils most of my requirements for a Small , Personal Inventory Management System for  Electronic Components.

Some of its features I like are:
  • Electronic Components Management
  • Projects and Components currently in use by them
  • Label Printing
  • Intuitive UI, although I'd like more fast and better UI 

PartKeepr Demo @  demo.partkeepr.org

 

Installation


1. Install apache, mysql, php, imagemagick
sudo apt-get install apache2 mysql-server mysql-client libapache2-mod-php5 php5-mysql php5-curl php5-cli php-pear php5-imagick php5-xsl php-apc php5-dev imagemagick git

2. Download, extract, copy to /var/www and set correct permissions
wget http://partkeepr.org/downloads/partkeepr-0.1.9.zip
unzip partkeepr-0.1.9.zip
sudo cp -r ./partkeepr-0.1.9 /var/www/
sudo chmod -R 777 /var/www/partkeepr-0.1.9/

3. Update PEAR
pear update-channels
sudo pear upgrade

4. Install phpunit, phing, doctrine components and twig. During the installation, it could happen that the ImageMagick library gets pulled in via PECL. Just hit enter on each question and ignore if it fails; as long as you've got php5-imagick installed, you're set.

pear config-set auto_discover 1
sudo pear install pear.phpunit.de/PHPUnit pear.phpunit.de/phpcpd pear.phing.info/phing pear.doctrine-project.org/DoctrineORM pear.doctrine-project.org/DoctrineSymfonyYaml pear.doctrine-project.org/DoctrineSymfonyConsole pear.twig-project.org/Twig
sudo pear install --alldeps phpmd/PHP_PMD-alpha


5. We also need jsl, the JavaScript lint

sudo apt-get install nodejs
sudo apt-get install npm

npm config set registry http://registry.npmjs.org/
sudo npm install -g jslint


6. From the browser, go to  http://localhost/partkeepr-0.1.9/setup/ and click Next



7. In the prerequisite check, I got "You are missing the GD library for PHP. Please install and activate it.".

So to install GD Library, install php5-gd
sudo apt-get install php5-gd

8. Click Re-run checks. Now, again I got "The PHP timezone () is not set or invalid. Please set the correct timezone in your php.ini file (don't forget to restart the web server afterwards)".


So, set the correct timezone in php.ini 
sudo nano /etc/php5/apache2/php.ini
Uncomment "date.timezone =" and set timezone ap per the supported timezones (here: http://in3.php.net/manual/en/timezones.php)

For example :   date.timezone = UTC

Save the file and restart the apache server:
sudo /etc/init.d/apache2 restart
Now, again Re-run Checks. This time I got all success. Click Next



9. Now, we have to create a database for PartKeepr, you can either use the form to get the desired commands for creating database or, simply enter the commands below in your shell:
mysql -uroot -p
CREATE DATABASE partkeepr CHARACTER SET utf8;
grant usage on *.* to partkeepr@localhost identified by 'partkeepr';
grant all privileges on partkeepr.* to partkeepr@localhost;
quit


10. Now, fill the form as in screenshot and click next:



11. If Database Connectivity Test is OK, then proceed.



12. Wait till the PartKeepr installation is  set-up, then click Next:






13.  Save the configuration either through browser (if it is writable) or manually. I selected 1st option and the file got saved successfully:



14. The next step is to setup Cron jobs:
crontab -e
If it asks to select your editor, select anyone of your liking.
Enter the commands as shown in screenshot of Installation and Console:
0 0,12 * * * /usr/bin/php <path-to-partkeepr>/cronjobs/CreateStatisticSnapshot.php
0 0,6,12,18 * * * /usr/bin/php <path-to-partkeepr>/cronjobs/UpdatePartCacheData.php
0 0 */2 * * /usr/bin/php <path-to-partkeepr>/cronjobs/CheckForUpdates.php
0 0 */2 * * /usr/bin/php <path-to-partkeepr>/cronjobs/UpdateTipsOfTheDay.php

 Save the file.




15. Return to Browser and click Next. It should tell that setup is complete.



16. Go to http://localhost/partkeepr-0.1.9/frontend/ and login. Default username/password is admin/admin:



17. And Voila!, you now have a working PartKeepr Installation! Congratulations!



Links I consulted for PartKeepr Installation:
1. https://github.com/partkeepr/PartKeepr/blob/master/documentation/developer/INSTALL-UBUNTU
2. http://www.cyberciti.biz/faq/ubuntu-linux-install-or-add-php-gd-support-to-apache/
3. http://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job