Writing a “Resistor Code” App for Blackberry Playbook

The PlayBook, as it is known Blackberry’s tablet,  is the first device to run Blackberry Tablet OS, based on QNX Neutrino, and runs apps developed using Adobe AIR. It was later announced that the Blackberry Tablet OS would be merged with the existing Blackberry OS to produce a new operating system, Blackberry 10, that would be used universally across BlackBerry’s product line. A second major revision to the Blackberry PlayBook OS was released in February 2012.[3] The Playbook also supports Android OS applications, allowing them to be sold and installed through the Blackberry App World store (1).

Introduction

It is quite easy to design apps for Playbook, with recourse to Blackberry’s WebWorks SDK. Blackberry WebWorks for Tablet OS as the name “WebWorks” implies, is a platform for building deeply integrated web applications for the Blackberry PlayBook http://us.blackberry.com/developers/tablet/webworks.jsp. We are going to design a “Resistor Code” App with Blackberry WebWorks SDK.

What’s a Resistor?

resistor is a passive two-terminal electrical component that implements electrical resistance as a circuit element.

The current through a resistor is in direct proportion to the voltage across the resistor’s terminals. This relationship is represented by Ohm’s law:

I = {V \over R}

where I is the current through the conductor in units of amperesV is the potential difference measured across the conductor in units of volts, and Ris the resistance of the conductor in units of ohms.

The ratio of the voltage applied across a resistor’s terminals to the intensity of current in the circuit is called its resistance, and this can be assumed to be a constant (independent of the voltage) for ordinary resistors working within their ratings.

Resistors are common elements of electrical networks and electronic circuits and are ubiquitous in electronic equipment. Practical resistors can be made of various compounds and films, as well as resistance wire (wire made of a high-resistivity alloy, such as nickel-chrome). Resistors are also implemented within integrated circuits, particularly analog devices, and can also be integrated into hybrid and printed circuits.

The electrical functionality of a resistor is specified by its resistance: common commercial resistors are manufactured over a range of more than nine orders of magnitude. When specifying that resistance in an electronic design, the required precision of the resistance may require attention to the manufacturing tolerance of the chosen resistor, according to its specific application.(2)

What’s Color Code of a Resistor?

Color code is used to indicate the values or ratings of electronic components, very commonly for resistors, but also for capacitorsinductors, and others. A separate code, the 25-pair color code, is used to identify wires in some telecommunications cables. (3)

The electronic color code was developed in the early 1920s by the Radio Manufacturers Association (now part of Electronic Industries Alliance(EIA)), and was published as EIA-RS-279. The current international standard is IEC 60062.

Colorbands were commonly used (especially on resistors) because they were easily printed on tiny components, decreasing construction costs. However, there were drawbacks, especially for color blind people. Overheating of a component, or dirt accumulation, may make it impossible to distinguish brown from red from orange. Advances in printing technology have made printed numbers practical for small components, which are often found in modern electronics.

What’s a WebWorks app?

When you hear the words Blackberry WebWorks, think HTML5, JavaScript, and CSS. Essentially, a BlackBerry WebWorks application is a web application that runs on a BlackBerry smartphone or BlackBerry PlayBook tablet.

BlackBerry WebWorks is an open source project that you can find on GitHub. Be sure to check out some of the BlackBerry WebWorks Samples.

Why create a BlackBerry WebWorks app? Some reasons to consider are:

  • portability
  • integration with core BlackBerry apps
  • ease of access, even when users do not have an Internet connection available(3)

Requirements

The creating of Playbook packages is done with not many external requirements. However, you need to use external tools in order to generate signing and debugging assets required to put deployments onto device.

Setting-up a Development Machine for Playbook Deployment

Blackberry Web Works SDK must be installed in order to obtain various tools required for obtaining certificates and device provisioning.

  1. Follow the instructions at https://bdsc.webapps.blackberry.com/native/ to download the SDK and any additional tools listed on the page.
  2. Install the SDK to your development machine.

I assume that you have the Development Machine ready by now as you proceed to next steps. If not, I recommend you set up the Development Machine before proceeding.

Code-Signing Keys

We will start by requesting a code-signing keys at https://www.blackberry.com/SignedKeys/. They are absolutely free!

Enter your name, company, email, country and a 6-10 digit “PIN.” Take note of the PIN since you will need it in next steps. I suggest you write down in a file named says “keys.txt” in a folder say named “BB”.

RIM will tell you to allow up to two hours in order to receive your code-signing keys by email.

When you are registered you will receive code-signing keys.  You will receive a “PBDT” *.csj file, and an “RDT” *.csj file.

Now we can associate our own password with each of the code-signing keys.  Enter into command-line of your PC , writting in your PC’s window in Start -> Run the command cmd/k

original

A full listing of DOS commands can be found at Wikipedia.

Next, in Command-line Terminal navigate to your Program Files with following:

bcd C:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.2.0.5\bbwp\blackberry-tablet-sdk\bin

If you know how to deal with DOS (check in previous paragraph Wikipedia’s link to learn about DOS commands) you can get there step by step. I advise you at this juncture to review your knowledge of DOS commands.

blackberry-signer -csksetup -cskpass (your password)

On my PC I did the following:

command1

I have blurred my password. Take note of the password you have just made up, and keep it safe. You will require this password in next steps, and in the future.

Next run the following DOS commands using PIN and password you have just decided upon.

Registering “PBDT” *.csj file

blackberry-signer -register -csjpin (PIN) -cskpass (PBDT file)

Where the brackets are, you have to write your PIN and your PBDT csj file name, the latter is sent to you by RIM.

Registering “RDT” *.csj file.

blackberry-signer -register -csjpin (PIN) -cskpass (RDT file)

We are now ready to generate keypair which will allow us to sign our apps.

blackberry-keytool -genkeypair -keystore (output file) -storepass (another password) -dname "cn=(your company name)" -alias author

My key generating DOS command looked like the following:

command2

I have blurred author, and other relevant information. I hope it will not be too difficult for you to do it .

We will now generate a debug token for testing the App we are going to design.

The debug tokens has *.bar file extension, so our output name will be like “debugToken.bar” or any other you choose.

N. B. You can create multiple debug tokens for each of your Playbook using “-deviceId” arguments. I am not so rich, so I have only one Playbook.

Find the PIN of your Playbook, after turning on the device, and swiping from the top of the screen down, to show the system preferences. Go to About > Hardware to find the PIN number as you see in following image:

playbook-locate-pin3-975

This is not my Playbooks’ PIN! I found this image on the web, and credit is due to the author of this image!

Next you will need to generate the debug token using this PIN:

blackberry-debugtokenrequest -cskpass (your password) -keystore (your keystore file) -storepass (another password) -deviceId 0x(your device PIN) (output bar file name)

command3

First of all connect your Playbook to your PC with USB cable (recommended), but you can also do it with Wifi. You will now enable your Playbook in Development Mode in Security > Development Mode from system preferences, and you will need to have yet again a new password which I suggest to be as simple as 123.

For Development Mode on your device, go to Security > Development Mode from system preferences. And set it ON. The following image shows “No debug token” and Development Mode is OFF.

playbook_debugtoken

Take note of IP of your Playbook in Development Mode. We can certify the information on our IP in main screen of your Playbook, as show in following image of my Playbook:

ip_address

Now we will install the token:

blackberry-deploy -installDebugToken (your debug token) -device (IP address) -password (device password)

Once you have uploaded your debug token with something like the following reassuring response you have reasons to be happy:

command4

Preparing our App

We are now ready for our App. Our App will be a “Resistor Code Calculator” based on Danny Goodman’s quite old, and still popular, “Graphical Resistance Calculator”. You can view the web application and play with the Resistance Calculator visiting Danny’s site at:

http://www.dannyg.com/examples/res2/resistor.htm

I am proud owner of Javascript Bible that I bought many years ago from Amazon. Danny Goodman has authorised me to use his Javascript code to design our Blackberry Playbook App. The code we are using is quite old as old as my Javascript book. I don’t think the Javascript code has changed much, perhaps it has been fine tuned only.

In order not to reinvent the wheel, you will accept my zipped file “rescolor.zip”  which you can download from Bitbucket, an unlimited free private repositories’ site.

Unzip the contents of zipped file. You will need an unzipper program perhaps. And now view the webpage (use Google’s Chrome as you will need it from now on). We are going to use the web app in the file to make our Playbook App.

You will notice there is a config.xml file in unzipped contents you have just downloaded. This file is required to compile our App.

You can preview how our App will look like on Playbook, by installing Chrome’s “Ripple” plugin. You can read about how to install it in Blackberry’s Developper pages.

When enabled “Ripple” runs a web server on port 9910 of your computer. You will need to tweak Ripple in Chrome’s extensions (you can access “extensions” directly by pointing the Chrome browser to chrome://extensions). As shown in following image (in Portuguese, but I think it will be something similar in English) we have tweaked Ripple to view our PC’s URLs:

ripple_urlNow open index.html in Chrome. In first run-time of Ripple, after enabling, it will be asking you the platform you want to run the page. Choose WebWorks-TabletOS (2.0.0). You will be next greeted with following image:

ripple_image

The left and right popups will allow you to configure your environment. I did nothing of that sort, as I was unable to start Ripple services due to problems with portuguese language characters of my Windows. I suggest you close the popups, pressing with the mouse onto two little arrows on top, pointing to left and right. You can zoom to view, within Chrome’s personalization (surely you know to do it!), and you will see our App in a simulated Playbook:

Image1We will next create a bar extension file of our zipped file (you just downloaded). If you have made any modifications to extracted files you will need to create a zipped file, that is if you want to implement your modded webpage.

So let us compile rescolor.zip and output as rescolor.bar. Return to DOS terminal as shown previously, to bbwp directory with following DOS command:

cd C:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.2.0.5\bbwp

To make it easy, create a directory myapp, and a sub-directory inside called output.  Drop rescolor.zip file into myapp directory (or one that you modded) and run the DOS command:

bbwp c:\myapp\rescolor.zip -d -o c:\myapp\output

You will immediately get this inconvenient result shown by following image with a Warning and an Error:

error_c

This error unknown protocol: c is what we need to sort out, as the Warning on feature is not so important at this stage.

To overcome this Error, you need to first create a temp directory in your C:\ drive (if you don’t have it already) and then issue the following commands in your DOS terminal

SET TEMP =C:\TEMP
SET TMP=C:\TEMP

This solution was found at Blackberry’s Discussion Forum. I did not find any alternative solution yet.

Now if you run the command again, you will get your compiled bar file in myapps/output directory. The following image shows these commands in my PC, plus the results of compilation:

compilation

If you check your output directory, you will now find rescolor.bar.

Install and run the App

Now we will deploy this App in our Playbook. Navigate to tablet-sdk with the following DOS command:

cd blackberry-tablet-sdk\bin

Run the following command to install the App:

blackberry-deploy -installApp -password 123 -device (your Playbook IP) -package c:\myapp\output\rescolor.bar

Hopefully it will install itself correctly, and you will get the reassuring output shown in following image:

comand_install

You can now check your main screen and you will find the Resistor Color icon as shown on bottom left-side of the following image (these are actual screen shots of my Blackberry Playbook obtained by pressing simultaneously + and – buttons on top of the Playbook):

IMG_00000012

Run the App, and you can now play with color codes in your touch sensitive Playbook screen. The following image shows the App on my Playbook:

IMG_00000013

Acknowledgements

First of all thank you to Wikipedia for providing valuable information that I have used just about cut and paste at the beginning of this post. Also credits are due to Blackberry for providing so much valuable and free information on the Web. A special thank you is also due to Danny Goodman for his “Graphical Resistance Calculator” web application which has served to design our App. Also all credit is due to Joshua Granick for his easy to follow page on How to Create Keystore for Blackberry.  Once more  I thank Bitbucket for providing me a free of charge repository from where rescolor.zip can be downloaded.

Conclusions

As you have already seen, and tried (I trust) it is quite easy to write, and to deploy a webpage as an App. You can even deploy a weblink as can be seen in this App we have just designed which will open webpages within the App.  The links at the bottom open Redacacia blog (this actual blog where you are!) and Danny Goodman’s webpage. If you have a “killer” webpage that you have written in Javascript, I bet you can deploy it as an App. Of course, in order to deploy in Blackberry App World Store, and to monetize with it, you will need to sign your App to make it publicly available, and you will have to take into consideration more issues surely.

Posted in Mobile Apps, Programming, Uncategorized | Tagged , , , , , , , | 2 Comments

OpenWRT – Rootfs & Swap on USB Storage

Introduction

The chances are that you have a router with a USB port, just like I have my TP-LINK TL-MR3420 router. It is likely that with more intense usage of your router, you will need more disk space. This can be achieved by connecting any USB storage device into the USB port of the router, such as pendrive, external HDD, memory card reader, cell phone, etc.. Unlike a Linux Desktop, OpenWRT is starved of disk space in the extreme. One way to overcome limitations and gain some “Mega” space is to remove installed kernel modules. This may not be at all very convenient, In general, for router with USB port, OpenWRT includes kmod-usb2, a pre-installed  basic module support for USB, which can be expanded to allow for external storage.

Basic Equipment Requirements

– TP-LINK TL-MR3420 Router* with OpenWRT Linux distribution for embedded devices and stable release of  Attitude Adjustment.

– USB Hub* with power supply

– Hard disk drive** with USB connection

* I have a 4-port USB hub  CN-050 v.1.002 from SITECOM with external power supply (cost 16,55€)

** In my case, I have an old 2,5″ 150GB SATA HD (bought long ago, I don´t remember how much probably 75,00€) that I decided to put into an external BlueRay USB box  (cost 13,99€).

Preparing the SATA HDD

Our SATA HDD needs to be partitioned and formatted to be recognised by OpenWRT.

We use MiniTool Partition Wizard Home Edition. Besides being free it is easy to use. Hook up your SATA HDD to your PC.

We partition our SATA HDD as follows:

Partition 1 with 1GB for LinuxSwap and Partition 2 for Ext4 with remainder space of our SATA HDD.

mr3420_1

Setup USB, Swap and ExtRoot

Make sure you have Internet connection. In my case I have my router with static IP address  192.168.1.1 with main gateway pointing to address 192.168.1.254 belonging to my ADSL router THOMSON TG585i V.7, with Internet and custom DNS server pointing to Google´s Open DNS address 8.8.4.4.

STEP 1: Next start LuCI in your favorite browser by pointing the URL to your router´s static IP, in my case 192.168.1.1

Update your router´s packages in System -> Software and click Update listsmr3420_1aActions will be shown of downloading process

mr3420_1b

STEP 2: We next install kmod-ub-storage packages. In Filter field write kmod-usb-storage  and click onto Find package. The result will be shown below as shown.

mr3420_3

Install kmod-usb-storage-extras by clicking onto Install link on the left side of found package. A popup window will ask you to confirm if you want to intall

mr3420_3aClick OK. The results will be shown above as you can see next

mr3420_3b

STEP 3: We will next install filesystem packages. First we find the packages by writing in Filter field kmod-fs

mr3420_4

We will install kmod-fs-ext4 package by clicking Install link on the left of found package.

Again a popup window will ask us if we want to install kmod-fs-ext4 package and we will click OK button. Results of installations of packages will be shown as previously.

STEP 4: We will finally install block packages. First we find the packages by writing in Filter field mount-

mr3420_5

We will install block-mount package by clicking Install link on the left of found package.

Again a popup window will ask us if we want to install block-mount package and we will click OK button. Results of installations of packages will be shown as previously.

mr3420_5a

It is interesting to note that all installations have reduced the available in my case to 38%.

STEP 5: We will plugin the Hub now where we have connected the SATA HDD. The following image shows my setup

mr3420_foto

We next reboot the router in System -> Reboot tab

mr3420_6

STEP 6: After reboot launch PuTTy and perform the shown commands

mr3420_67jpg

STEP 7: After reboot, launch WinSCP (I have vi that is included in OpenWT). Go to ” /etc/config ” folder and locate and edit the file fstab

mr3420_7

Edit fstab as shown below taking note specially that /dev/sda1 is partition 1 (LinuxSwap)  and /dev/sda2 is partition 2 (Ext4 for Data) and do slight modifications as shown below

mr3420_8

Back to LuCI perform reboot again

mr3420_6

After rebooting go to System -> Software tab and Voila!

mr3420_9

A while ago we saw we had 38% of memory now we have 100% and much more memory! Note that there are no package lists. We will do something about this  later.

STEP 8: Let us now check what is going checking mount points in System -> Mount Points tab and in my case at least, swap was not enabled which we will do by ticking Enabled as shown

mr3420_10

We also note that mount point /overlay is correctly mounted in /dev/sda2.

We will now enable fstab to mount the partitions. In LuCI System -> Startup tabmr3420_fstab_enabled

Do next reboot again

mr3420_6

STEP 9: As a final act of confirmation launch PuTTy and perform the commands as shown df -k and next free

mr3420_11

STEP 10: It seems all is fine. Now we will update the package lists like in STEP 1 and do something final about spin of HDD.

Back in LuCI in System -> Software tab perform Actions of searching with keyword luci in Filter field

mr3420_12

And choose to Install luci-app-hd-idle, a utility to spin down the hard drive. A popup window will ask you if you want to install luci-app-hd-idle and you will press OK button and you will see that the package will be installed

mr3420_13

A new tab will be added called Services. Choose Services

mr3420_14

Enable hd-idle as shown and Save & Apply

We have concluded our task of USB, HDD, Rootfs and Swap. By installing hd-idle we have proved that the HDD has substituted the internal limited memory of our router.

Acknowledgements

A special thank you is due to K. L. Seet for excellent tutorial found at that website. Most of this post is based on that tutorial.

Posted in Electronic Projects, Information Technolody | Tagged , , , , , , , , | 46 Comments

This blog has now its own domain name RedAcacia.me

RedAcacia.wordpress.com is now RedAcacia.me!

This blog had 24,000 views in 2012.

In 2012, there were 11 new posts, growing the total archive of this blog to 27 posts.

The busiest day of the year was September 13th 2012 with 141 views. The most popular post that day was Fixing: Fatal Error Call To Undefined Function Json_decode.

Where did they come from?  The visits cam from 147 countries in all!
Most visitors came from The United States. India and Portugal were not far behind.

RedAcacia has not deviated from its main aim of “Just tech-oriented projects and sharing them!

RedAcacia values visitors and I have always tried to respond quickly to any queries or comments. I am also a keen learner.

RedAcacia shows now with its own domain name commitment to continue sharing knowledge in tech-matters!

A big thank you to all visitors and commentators, and a special gratitude to WordPress team in providing us all with such a wonderful facilty on the Web!

Posted in Uncategorized | Leave a comment

Debrick your TL-MR3420 router with a serial TTL cable

Introduction

When upgrading a router such as TP-Link´s  MR3420, if one does not take adequate measures, one risks to brick it. That is exactly what I did with my TL-MR3420 v1 router. The only way to debrick this router is through a serial TTL cable.  I will show here how to do it.

Requirements

You need to know a bit about soldering, and have a bit of cabling skills and adequate tools such as a crimping tool.

Preparation of the serial TTL cable

You will need a serial TTL cable. This is not the same as ordinary RS232 cable used in PCs such as USB->RS232 cable .

If you dont own a serial TTL cable, it is easy to make one. You need to buy a cheap Data cable DKU-5 or CA-42 (I bought a DKU-5 cable from a local Indian shop for 6,00€)

dku5_2

DKU-5 cable is used for data connection in old Nokia phones. Cut the cable at extreme end next to Nokia connector as shown, and expose the wires:

other_end_cable

In my case the DKU-5 cable has 3 wires. You need to know which wire corresponds to what i.e. Tx, Rx and Ground required for TTL connections on the router.

It is quite easy! You just need to use a multimeter, and check continuity on the NOKIA connector, that is which wire corresponds to what for Tx, Rx and Ground:

dku-5

In my case white wire corresponds to Tx, yellow corresponds to Rx and green corresponds to Ground. I crimped  the wires at cable end with Molex crimps as shown (we are going to use Molex connectors):

crimping1

If you want to learn to crimp, there are nice Youtube videos showing how to do it.

Before finishing touches with the serial TTL cable, we need to go forward and prepare the router for programming with this cable.

Opening and preparing the router

On the bottom side of the router, there are four round rubber pads that you will need to remove , and below these you will find four screws that you have to unscrew in order to open the router:

router_open1

Avoid static electricity as it can cause real damage to your router! The easiest way to dissipate static electricity is to use an antistatic wrist strap, which connects to your local AC ground.

Open carefully the router taking out also the front end with reflectors of the LEDs, in order to be able to remove the router´s PCB. All of following images refer to TL-MR3420 v1 router. Identify where you will connect the cable you just prepared (on the PCB from left to right: Tx, Rx, Ground, Vcc):

identify_connection

The following image shows the pinout exactly as on the router’s PCB:

pinout

Remove the solder covering the holes with desoldering pump in order to mount the male Molex connector. You will need to add a bit of extra solder and flux to remove the solder in these holes. For learning to solder, and to remove the solder with desoldering pump there are some nice Youtube videos on the Web showing how to do it.

Connect the male Molex connector (I have used a 4 pin connector to facilitate next connections, you can read about below in this tutorial). So here is an image of the connector already soldered on the router´s PCB:

molex_connector_pcb

To get the serial connection work reliably, you have to connect a 10k ohms pullup resistor between the Tx and the Vcc on the PCB. This is because the Tx pin is connected to a voltage divider (2×5.6k) and a capacitor is put between the real pin and the Tx connector. So turn over the router´s PCB, and solder a 10K ohms resistor as shown using as support the terminations of the Molex male connector we have soldered before:

solder_resistor

Now we are ready to finish up the cable we have crimped before as shown:

molex_connector_pcb1

Note: A special thank you is due to Filipe Avelar, external salesperson in ALIATRON (my company) that soldered for me the resistor, and crimped the TTL cable terminations.

We are now ready to debrick the router!

Debricking the router

Make sure the router is not powered. Connect the TTL cable to the router as shown:

connected_cable_on_router

We will now follow the procedure advised by the polish language site eko.one.pl. It is a good idea to create a folder in your PC to. where you will download some of the files you will require. My folder is called “modem”.  My PC’s OS is Windows XP.

Download:

1) firmware openwrt-ar71xx-generic-tl-mr3420-v1-squashfs-factory.bin from Openwrt site to your newly created folder where you will have the whole project.

2) tftp for Windows from http://tftpd32.jounin.net/ to your folder in a subdirectory called tftp.

Paste into tftp subdirectory the firmware you downloaded, and rename it  code.bin for sake of easy identification.

Connect the serial TTL cable to your PC (you will have already connected to your router as shown above in this tutorial). The serial TTL cable  will be recognised by your PC. If not, you will need to install adequate drivers from Web. My DKU-5 cable came with a CD containing drivers.

If the cable is recognised, check in your PCs Control Pannel -> System -> Hardware ->  Device Managemnt -> Ports (COM and LPT) .

You will see thereProlific USB-to-Serial Comm Port (COMx). x will be the port number  (in my case it is COM5).

Now start your PC´s Hyper Terminal (or use Putty). For Hyper Terminal give a name to your connection say “test”:

start_ht

Configure Properties to 115200 8N1.

In Hyper Terminal the configuration is found in File -> Properties -> Configure…-> Connect Using (my case COM5):

cable_configuration

After this selection, press Configure button and now select 115200 baud rate:

cable_configuration1

And now press the Apply button and next OK button.

And next on first screen press OK button. Leave the Hyper Terminal as it is, as it is now duly configured (do not close it!).

Change your PCs IP to 192.168.1.27. Connect the CAT5  network cable between your PC and port 1 of your router. Make sure you disable your other network connections in your PC, except for your Local Area Network that you have just connected to the router. Also remove temporarily your PC´s firewall. Your network is now shown without firewall’s lock sign:

cable_configuration2

We will now start tftp we downloaded before. Tftp will show your PC’s IP you have just configured:

tfpt1

We need to tell tftp where the code.bin firmware is. We do this by pressing Settings button and pointing the Base Directory to the folder containing code.bin:

tfpt2Press OK. Now look at your Hyper Terminal´s screen. Power your router.

Your Hyper Terminal screen will show “Autoboot in 1…“, when quickly type tpl with your keyboard. You will hopefully see the following prompt, or similar:

start

We are now ready to type:  erase 0x9f020000 +0x3c0000 

And press ENTER key. It wll result in erasing an area of the memory of the router:

programming1

We will next type the following: tftpboot 0x81000000 code.bin

And press ENTER key. The firmware will be uploaded:

programming2

tftp will show the code.bin being uploaded:

tfpt3

We will next type: cp.b 0x81000000 0x9f020000 0x3c0000

And press ENTER key. And at next prompt type: bootm 0x9f020000

The router wil now reboot and it is no more bricked!

You can now check if your router is debricked by writing in your browser the URL http://192.168.1.1.  your login screen to the router´s interface will show:

Luci_int01 (1)

Conclusions

If one has bricked his TL-MR3420 router, the solution lies in debricking with a serial TTL cable.  I have shown here that with little bit of soldering, and mechanical (crimping) skills and necessary software one can debrick TL-MR3420 router. The approach of debricking a router may be similar with other brands of routers.

Posted in Information Technolody | Tagged , , , , , , | 71 Comments

2012 in Review

The WordPress.com stats helper prepared a 2012 annual report for this blog. A big thank you to all visitors and among you that wrote comments, as well as WordPress team for running this wonderful space on the Web.

Here’s an excerpt:

4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 24,000 views in 2012. If each view were a film, this blog would power 6 Film Festivals

Click here to see the complete report.

Posted in Uncategorized | Leave a comment

Android Basic Gestures of Swipe to Control a Robot

Introduction

Basic gesture of swipe to control movements of a robot can be quite interesting, and may add intuitive interactive dimension to electronic projects.

I have published in this blog several tutorials on 8051-based robot controlled with bluetooth-enabled cell phone. Also most recently I have published a tutorial for Android phone using button images on device’s touchscreen.

Android being open-source, attracts a large following, and hence there are many different ready-made solutions. With a little bit of coding, and imagination, one can design different projects using solutions that are already available, or modifying or improvising on them.

Required equipment

A 8051 robot “Robo-51” (could be a robot with any other micrcontroller) with serial bluetooth ZX-Bluetooth module, running a firmware for bluetooth control, and an account with App Inventor.

Robo-51

Inex´s Robo-51

Inex´s bluetooth module “ZX-Bluetooth”

App Inventor Code

Our code is based on two codes BennyBlue and Swype routine both made with App Inventor .

To be able to control the robot you will need to download the source code file Bluemote2_0.zip kept at Bitbucket, an unlimited free private repositories’ site. If you already have an App Inventor folder, you can download the source code by scanning the following QR barcode:

All you need is your Android’s camera and a barcode scanning application. You may use Barcode Scanner app from ZXing Team. It’s available as a free download from the Android Market and works with all versions of Android.

If you are absolute beginner with App Inventor, the excellent resources and tutorials found at MIT’s App Inventor site are very good and easy to follow.

The control program

The Android application controls Robo-51 from Inex, with the following bluetooth send commands:

Key letter “d” results in forward movement of the robot, “a” in backward, “c” in turning leftward, “b” in turning rightward and “s” in stopping.  The following icon (inside the red circle) shows when the apk has been installed (after compiling in App Inventor, and downloading into your Android phone):

Android screen of Bluemote 2.0 app´s icon

Before running the application, you will need to pair the serial device on Robo-51 with your Android’s bluetooth. Next, when you run the app you will need to tell it which paired device will it talk to:

Select the  bluetooth device

Press the Select Device button to select the paired bluetooth device you have already paired with your Android phone:

The paired device is shown

On clicking the device our first screen will come up with MAC address of the bluetooth device:

On clicking Connect, you will hear if everything is OK “I’m robo-51… I’m at your command!”.  Connect button will change to Disconnect

You can control the robot with gestures of swipe with the finger to the left, or to the right, or forward (up finer swipe gesture) and backward (with down finger swipe gesture) , and you will hear in your Android phone voice of corresponding “forward”, “backward”, “turning left” etc. and the robot will move accordingly leftward, rightward, forward and backward. The Reset/Stop button will stop the robot.

After you have played with the control of the robot, you can disconnect by pressing Disconnect button on top right of Android screen. Clicking the menu button of your phone you can close the app.

VIDEO Demo

Conclusion

This project adds a new feature into existing Robo-51 projects. The main objective of this actual project was to achieve, with little work, similar results to those obtained with Java-based Nokia N97 and Blackberry Bold 9700. I can now tick as successful this project on basic gestures of swipe for Android.

Posted in Mobile Apps, Robotic Projects | Tagged , , , , , , , , , , | 5 Comments

Write a Drawing App “myArtwork” for Blackberry with Social Network Sharing Capability

Introduction:

With Mobile Processingg one can write J2ME apps that work in Blackberry phones. Sometime ago, I compiled a simple code that I found on the web that without any changes works perfectly in my Blackberry Bold 9900. The compiled app utilises the touchscreen on my phone as a method for drawing images. My grandchild loves to draw using this app, but his artworks were not being saved or shared until recently, when I added an app to my Blackberry that allows me to save the drawings, and to share them.

Objectives:

Write code for a drawing app named myArtwork for Blackberry smartphones with touchscreen, such as Blackberry Bold 9900, and add Social Networking sharing capability. The resulting app must have basic look and feel of a professional Blackberry app.

Requirements:

Blackberry Bold 9900, or other Blackberry smartphone with touchscreen
Mobile Processing IDE installed in PC with Java SDK and Wireless Tool Kit (WTK)
Blackberry Desktop Software

Installing Mobile Processing IDE and “Hello World” app

You need to Mobile Processing, Windows Version with Java and WTK download Mobile Processing  for building Java mobile phone applications. Note the location of the installation. In our case we unzipped into root of our C:\ drive

There is no installation just run Mobile Processing by double clicking the icon in your PCs folder:

There will be an error warning when checking for updates. The Mobile Processing project has been stale for a while, so there are no updates:

Click Ok.

Choose Preferences from the main dropdown menu:

In the Preferences dialog box, go to the Mobile tab, and enter the location of the WTK:

Choose CLDC version 1.1 and MIDP version 2.0. Click Ok.

We are now ready to write our first app “Hello World”. Cut and paste or write the following code in the sketch workspace of Mobile Processing:

PFont font;

  void setup()
  {
    font = loadFont("SansSerif.bold-24.mvlw"); 
    textFont(font);
  }

  void draw()
  {
    text("Hello World",10,25);
  }

Save the project with name Hello with dropdown main menu File -> Save as.

NOTE: All projects are saved in your PC’s My documents -> MobileProcessing.

Now, before simulating, we need to load the font into the project directory. Do Tools -> Create Font. The following configuration window will open:

We will choose SansSerif.bold-24.mvlw and include A-Z and a-z characters. If we do not do this procedure our emulator will throw Java exception error. The emulator does not how to display fonts.

We will now simulate this first application. In the dropdown main menu run the simulation with Sketch -> Build and Run. The default color emulator will open:

We will click the right button Launch in the emulator. The result will be as follows:

Check the folder in your PC in My documents -> Mobile Processing -> Hello and you will see the directories that have been created:

Open the data folder, and you will see our font file:

Now open the MIDlet folder, and you will see Hello.jad, Hello.jar and Hello.java files:

The files that Blackberry needs are Hello.jad and Hello.jar. Hello.java contains Java source code. We will not install these files in our Blackberry, and proceed with installing our drawing app “myArtwork“.

In the main dropdown menu choose File -> New and cut and paste the following code, or write it in  Mobile Processing sketch workspace:

int x;
int y;
int lastX;
int lastY;
boolean screenTouch;

void setup() {
softkey("Wipe");

x = width / 2;
y = height / 2;

framerate(15);
background(0);
stroke(255);
fill(0);
stroke(0);
strokeWeight(3);
colorMode(HSB);
}

void draw() {
if(screenTouch){

lastX = x;
lastY = y;
fill(random(0,255), 255, 255);
triangle(x + random(-20, +20), y + random(-20, +20),
x + random(-20, +20), y + random(-20, +20),
x + random(-20, +20), y + random(-20, +20));

}
}

void pointerDragged(){

x=pointerX;
y=pointerY;
redraw();
}

void pointerPressed(){
x = pointerX;
y = pointerY;
lastX = x;
lastY = y;
screenTouch = true;
}

void pointerReleased(){
screenTouch = false;
}

void softkeyPressed(String label) {
if (label.equals("Wipe")) {
background(0);
}
}

You will now save the project with the name myArtwork with  File->Save As in the main dropdown menu.

Before proceeding we will create an Icon for our App. It needs to be 62×62 pixels.  You can download here an icon we have designed, together with pde file of above code. The file is hosted by BitbucketBitbucket that offers unlimited public and private repositories and it is free for small teams. In your PC’s My Documents -> MobileProcessing ->myArtwork folder create a data folder and paste this icon image file icon.png into it.

Export as MIDlet with File-> Export MIDlet:

The MIDlet will be created and your PC´s MIDlet folder will open automatically to show myArtwork.jad, myArtwork.jar and myArtwork.java files:

Note: If you care to check myArtwork folder you will also see a new folder proguard. ProGuard is included in Mobile Processing to make the apps smaller and more efficient jar files. We will not use the jar file in this folder.

We are now ready to copy myArtwrok.jad and myArtwork.jar into the Blackberry.

After connecting your Blackberry to the PC with USB cable run Blackberry Desktop software and choose Files:

Click the Start button. You will see the next screen:

In your PCs folder MIDlet folder select myArtwork.jad and myArtwork.jar files:

And with right click of your mouse button Copy these files, and paste them into the Blackberry Desktop folder you have just opened:

Both files will be now in your Blackberry phone’s documents folder.

NOTE: If you are too lazy to write code you can  install the jad file found here into your Blackberry as shown. Note the jad and jar files are hosted at Bitbucket, a free and unlimited public and private repositories hosting site. The jad file will download from Bitbucket the required jar file (provided your Blackberry is connected to Internet) and install it following same procedures as shown below.

Now disconnect the USB cable between your Blackberry and your PC. In your Blackberry’s go to All group of folders and choose the Applications folder:

Open the folder, and select Files folder:

Open the Files folder and navigate to the documents folder. In my Blackberry I found it in File Folders -> Device -> home -> user. In documents folder within user folder, you will find myArtwork.jad and myArtwork.jar  (in case you have not downloaded the jad file as mentioned above in which case jar file will be downloaded from Web). Select myArtwork.jad:

Click myArtwork.jad and you will seee the following screen:

Click Download button and our app will start to be installed. You will get next the following warning window:

Normally you would press button No, or at least you ought to do so. We will click Yes button, and proceed with the installation. Eventually without any errors, you will get the following reassuring pop up window in your Blackberry:

You can Run immediately the app. But we will wait, and check first our All group of folders to see what appears there. You will see reassuringly see myArtwork icon:

We are now ready to test our app myArtwork for Blackberry.

Testing  our App

Click myArtwork icon and a black background empty screen will be shown in your Blackberry phone:

Touch the screen with your finger, and draw something similar to the following:

You can Wipe this drawing pressing the Menu button in your Blackberry:

You will see the option to Wipe or Exit:

If you use Wipe option the screen will be cleared. This is all that this code does. But, we will not stop here, and we will add to our app saving and sharing capabilities.

Blackberry App World offers a free software that does exactly what we want and integrates into other apps. It is called Screen Grabber. It is free, no watermark , no ads, courtesy of JaredCo.  This is a totally flexible screen capture app that lets you share your Blackberry screenshots with anyone. It is simple and useful. It has BBM, SMS, Email, Twitter and Facebook integration. It also creates in your Blackberry’s Media/Pictures folder, a new  folder called Screen_Grabs where the screenshots you have chosen  to share will be saved.

Install Jaredco‘s Screen Grabber in your Blackberry. After installing Screen Grabber and restarting your Blackberry, you will see in your Balckberry’s All group folder the Screen Grabber icon:

Now if you Run our app myArtwork, you will see the option to capture the screen if you click the Menu button in your Blackberry:

Click Screen Grabber and the following option will be opened:

For testing purpose, we will click BBM button  and the following options will be shown:

We select a contact, and the following will be shown:

You can add a comment and Send. That is it! Your first artwork has gone to your contact.The Screen Grabber app will return to the first screen. To exit, if you do not want to use other sharing features, you can press the Back menu in your Blackberry:

And you will return to the drawing you have just made. With Menu button in your Blackberry you can use Exit option to leave myArtwork app.

You can check in your BBM whether the image has been sent. It will be there for the contact you have chosen to send to.

Final words

I am a Blackberry fan. My phone is a workhorse I am using for all my business and other activities. I love the interconnection among apps, easy switching among apps, and many more features. The added most recent Social Network capabilities in apps is a plus for those that understand the value of such features. If you ask me whether I am ready to switch to iPhone or any other hype driven smartphones, I will readily answer with “no, thank you!”.

My first app for Blackberry was written to control a 8051 microcontroller-based robot (I adapted from my original Nokia N95 app). I published my work here in this blog.

I have enjoyed doing myArtwork app, and specially as it is made for my Blackberry Bold 9900. My grandchild loves myArtwork. He is an artist in making, but I am suspect!

I hope Research in Motion (RIM) will continue to exist, and come out of its actual financial woes, and more developpers will write apps for Blackberry devices.

Acknowledgments

A special thank you is due to Addy B for sharing drawing code for Motorola, written in Mobile Processing IDE.

Conclusions

We have written a drawing app for Blackberry and shown that it works as expected, and that one can easily add to it sharing for Social Network capabilities . Instead of Mobile Processing we could have written our app in Eclipse.

It is not Rocket Science to write apps for Blackberry, surely!

Posted in Mobile Apps, Programming | Tagged , , , , , , | 5 Comments

Finite-State Machine Design of a Simple Car Security Alarm on a Xilinx FPGA – Part III

Objectives

Implement  on actual hardware, a Xilinx Spartan 3 Starter kit board from Digilent, with VHDL code generated after having designed a simple car security alarm using StateCAD in part I.

Requirements

– Xilinx ISE Design Suite 14.2
– Digilent Spartan 3 Starter Kit board.

Car Security Alarm Specifications

We wil devise a simple Car Security Alarm on actual hardware, a Digilent Spartan Starter KIt board, that will sound a siren ( LD0 will switch on in our Spartan 3 board) if the car alarm system has been energized i.e. armed (A=1, that is SW7 in our Spartan 3 board ) and the door is open (B=1, that is SW1 in our Spartan 3 board) and / or an ultrasonic sensor signals movement inside the car (C=1, that is SW0 in our Spartan 3 board).

Implementation on a FPGA

Launch Xilinx ISE  Design Suite, get into the Project Navigator, and start a New Projectpressing the button for New Project. Xilinx ISE Project Navigator controls all aspects of the development flow of our FPGA. We will use it to launch all development tasks.

Give the project a name such as Car_Sec and fill all the fields appropriately, including pointing to the drive and directory in your PC where you will keep the project files:

Click on Next button and the following window will open:

Do the required changes as shown on the image and click Next button. The following window will open:

Click Finish button. The Project Navigator will show an empty view of the Hierachy window of our project:

Now we add the VHDL source we have generated in part I:

The following window will open which will hopefully do a sucessful adding of source:

Press Ok button.

The Project Navigator will show a summary of what has been done so far and the source code will show up in Hierarchy window. Highlight the Car_Sec.vhd file and double click on it:

The full VHDL code will be shown in the right window of our Project Navigator:

We are now ready to check syntax, and do further preparations for implementation.

In the Processes window we run Check Syntax

The results hopefully will be Ok as shown:

We will next see our schematic. We will first run Create Schematic Symbol in Processes window:

Now run View RTL Schematic in Processes window:

Viewer Startup Mode window will pop up, where we will choose the second choice as shown:

Click Ok. In the right window of Project Navigator we will see the main schematic:

If we click the block diagram, we will see:

By clicking LUT4 block we will see the logic circuit:

We are now ready to create contraints, i.e. configuration of inputs and outputs in our Digilent Spartan 3 Starter kit board. In Processes window run I/O Pin Planning (PlanAhead):

A window will pop up to tell us that no constraints file have been created:

We click Yes button. PlanAhead will open with Welcome to Plan Ahead window popping up:

After tcl file has run automatically, we have to close this window and concentrate on I/O Ports window of PlanAhead:

Clicking on ABC and Scalar ports we will expand these folders. And we start to introduce constraints referring to our Digilent Spartan 3 Starter kit board as shown.

We introduce the riht input and output pins. Please refer to Digilent Spartan 3 Starter kit manual.

We are now ready to save Constraints in File -> Save Constraints as shown:

Leave PlanAhead with File ->  Exit

Press OK as in following window:

We are now back to Project Navigator where we will see our constraints file we have just created:

We wii proceed to Processes window and run Synthetize-XST as shown:

Hopefully results will be of sucessful synthesis:

We next will run Implement Design:

And the results will be again hopefully of sucessful process:

Finally we are ready to generate the bit file with which we will program our Digilent Spartan 3 Starter kit board:

Programming file will be generated hopefully:

And the Console window will show the results of the process:

The right window of our Project Navigator will give us the summary of our project:

We are finally ready to implement after checking out the summary that everything is right.

We will now program in our Spartan 3 board. It is assumed that you have the Digilent board duly configured to “see” the USB Jtag programming cable, and Digilent Adept 2 chaintool is installed in your PC.

Within Processes window choose Generate Programminf file. Right click with your mouse and Run as shown

Programming file will be generated hopefully with success:

Finally we will program our Digilent Spartan 3 Starter kit board:

A pop up window will open:

Click OK. Xilinx ISE Impact will open with empty workspace:

Double click on Boundary Scan. The empty workspace will now show:

Do as it says: Right click to initialize toolchain. Choose the option as shown below:

The result will be:

A sucessful identification has occured. Press Yes button.

NOTE: We will not program the PROM. This process requires configuration in Adept 2.0 by launching Create PROM file before doing anything else in ISE Project Navigator.

A window will pop up, and we will introduce the bit file we have generated in our Car_Sec project directory.

Assign the bit file and click Open

A new pop up window will invite us to assign PROM file:

Click Bypass. A new window will pop up:

Press OK and the result will be:

We will now right click XC3S200 icon in order to program the board and choose Program:

Device will be programmed and hopefully will be hopefully successful as shown below

A succesful programming has been done.

Testing the project

The alarm security circuit will light up a LED (LD0) on Spartan 3 Starter kit board, simulating SIREN sounding, only when the conditions we have established of state machine occurs. Test the state machine as shown:

On Digilent Spartan 3 board, the leftmost switch represents ALARM armed or unarmed (upward or downward respectively) the rightmost switches are DOOR (upward door open, downward door closed) and ULTRASONIC SENSOR (upward presence detected and downward no presence).

DEMO Video:

Download

The board Constraints and bit file can be downloaded from here.

Conclusions:

A complete Workflow has been shown in this three parts tutorial of a simple Car Security Alarm using Finite-State Machine to design the logic circuit.

We first designed the State Diagram in StateCAD and generated VHDL, then we simulated our state diagram in StateCAD to verify whether it behaves as expected.

In this part of our tutorial, we imported the VHDL file of part I in Xilinx ISE Project Navigator, and we followed all the procedures to implement our VHDL in an FPGA.

We have sucessfully programmed the Digilent Spartan 3 Starter kit board, and tested our Car Security Alarm state machine we designed in part I.

Posted in Electronic Projects, Electronic Simulation | Tagged , , , , , , , , , | 10 Comments

Finite-State Machine Design of a Simple Car Security Alarm on a Xilinx FPGA – Part II

Objectives

In part I we have generated VHDL code from a State Diagram. We will now simulate the state diagram in order to debug it, and to ensure that it behaves as expected. In part III we will implement the VHDL code of part I in actual FPGA Spartan 3 Starter kit board.

Using Statebench

Before implementing our logic in our Spartan 3 Board we need to make sure that the State Diagram that we have designed will be behaving as expected by simulating it. With StateBench we can go through our design one clock cycle at a time, changing inputs and verifying outputs.

Our State Diagram of part I looks like this:

In order to be able to simulate it, we need to add a reset. In StateCAD activate Add reset:

Now add reset to the state diagram:

The following window will pop up:

Press No button to choose synchronous. We are now ready to simulate.

Click the StateBench button:

StateBench window will open:

Click the Reset button. We will now see the initial state:

We then need to add more clock cycles, clicking onto:

The result will be as shown:

We will next change input by double clicking on a time line position of input and a cursor line will appear as shown with a pop up window to assign a value:

Change the value to decimal 1 (001). The resulting window will pop up:

We will choose No to change input value to 001 henceforth. And the result will be:

NOTE: By default the rightmost edge of the clock before the point chosen will be indicating the new value (decimal 1). SIREN is still off, and we remain in STATE0.

Change values the same way to 2 (010) , 3 (011) and 4 (100). The state will continue to be STATE0 and SIREN will not sound, i.e. it will be 0 (zero).

Nowzn if we add input value 5 (101) at a different time line as shown:

The following window will pop up:

Choose again No to change values henceforth.

Around less than 10 cycles later (about 1ms later) there will a transition to STATE1 and SIREN will be sounding. i.e. it will be 1. To view better the transition, add more clock cycles by  clicking onto:

And now you can view better what is happening:

Change again by double clicking at time line edge of input to obtain the following result:

Introduce 4 (100) i.e. door is closed (B=0) and again the following window will pop up:

Choose No to maintain the input value henceforth. The result will be as shown i.e. that the state remains itself as STATE1 and SIREN is still sounding:

The graph means that if we rapidly shut the door (returning to 100 condition)  at 86ns (1300 minus 1214ns)  the SIREN will continue to sound, and the system will maintain itself at STATE1. Change the condition again to another value as shown:

Now at a different time line do the same procedure as before and change the condition of input to 1 (001)

To view bettera, add clock cycles by pressing the button:

Our better view will be something similar to shown below:

At about less than 10 cycles i.e. about 1ms, there will be transition to STATE0 and SIREN will not sound anymore. We have returned to the first state, i.e. STATE0. If we repeat the input conditions as we did before, we will prove that a transition occurs only to STATE1 when input is either 5 (101) or 6 (110)  or 7 (111).

Conclusions:

StateBench allows to simulate a state diagram by going through our design one clock cycle at a time, changing inputs and verifying output.

Our simulation has proven that the State Diagram we designed in part I is behaving as expected. We need now to implement and to test in our Digilent Spartan 3 board, the VHDL we generated in part I..

Posted in Electronic Projects, Electronic Simulation | Tagged , , , , , , , , , | 1 Comment

Finite-State Machine Design of a Simple Car Security Alarm on a Xilinx FPGA – Part I

Objectives

Finite-state machine (FSM) or finite-state automaton design of a simple car security alarm using StateCAD, and implementation  on a Digilent FPGA Spartan 3 Starter kit board..

In this part we will generate the VHDL code. In part II we will simulate and in part III we will implement the VHDL code in our Digilent Spartan 3 Starter kit board.

Requirements

– StateCAD inside Xilinx ISE Design Suite 10.1
– Digilent Spartan 3 Starter Kit board (for implmentation in part II)

Overview

StateCAD allows visual implementation of a State Diagram and translation into a Hardware Description Language (HDL) code. It is not necessary to understand the HDL code, however we have little control over how the software translates the state diagram.

We will create a state diagram for a car security alarm, and generate VHDL.  In part II we will simulate our state diagram to check whether it behaves like we expect. In part III we will create the schematic symbol and implement the VHDL code in our Diglent Spartan 3 board, and finally test the car security alarm to ensure that it works as expected.

Car Security Alarm Specifications

We wil devise a simple Car Security Alarm that will sound a siren if the car alarm system has been energized i.e. armed (A=1) and the door is open (B=1) and / or an ultrasoic sensor signals movement inside the car (C=1).

Image showing door switch , ultrasonic sensor and siren

We need to ensure that when the door has been opened in an unauthorized manner, or a presence is detected by the ultrasonic sensor within the car, the alarm siren will sound. This is achieved with a Finite-State Machine (FSM) as shown:

State transition diagram of car security alarm

1) In STATE0 the siren is off (SIREN=0) if the alarm is not energized that is armed (A=0) and the door (B) or the ultrasonic sensor (C) can be in any combination, or if alarm is armed (A=1) the siren will not sound if door is closed (B=0) or no presence is detected within the car by the utlrasonic sensor (C=0).

2) There is a transition from STATE0 to STATE1. if alarm is armed (A=1) and if either the door is open (B=1) or ultrasonic sensor detects a presence within the car (C=1) or both the door is open and ultrasonic sesnor detects (B=1 and C=1), the siren  will sound, and the system will remain in STATE1.

3) The system will remain in STATE1 that is. siren will be sounding whatever happens next to the door (either is closed or open or sensor detects or not, provided the alarm is still armed (A=1).

4) Transition from STATE1 to STATE0 occurs only if the system is desarmed (A=0). and in this circunstance for B or C, the siren will not sound anymore (SIREN=0).

Creating the Diagram in StateCAD

Our aim is to obtain a State Diagram as shown above.

Open StateCAD by navigating thorugh the Start menu:  Start -> Programs -> Xlinix ISE Design Suite 10.1 -> ISE -> Accessories -> StateCAD.

Activate the state diagram tool by clicking the Add State icon found  in the tool bar:

A state similar to the one shown below appears:

You will draw next State as shown in our proposal for the State Diagram. We will next connect up the two states with transitions by using the tool Add Transition, activating the following icon in the tool bar:

 And now draw by clicking and linking to obtain the following result:

Both states and transitions

Save the drawing with the name STATE_CAR. Now click onto the STATE0 and Edit State window will pop up:

Output condition  SIREN=”0″ added

Do as shown introducing output SIREN=”0″. After finishing click OK, and do the same with STATE1 and add output condtion as SIREN =”1″

Add variable vector to the drawing by activating Add Vector icon (looking like a yellow bus) in the tool bar:

And place variable vector:

Click onto it  and the Edit Vector window will pop up:

Change the name to ABC and the range to 2:0, as shown in the figure and click OK.

We will next change the conditions of the transitions. Click onto the loop back transition of STATE0 and Edit Condition window will pop up:

Introduce Condition: ABC = “000”) OR (ABC=”001″) OR (ABC=”010″) OR (ABC=”011″) OR (ABC=”100″) . And press OK

Edit all other transitions to obtain the following final result:

We are now ready to ckeck variables. Right click with the mouse onto an empty area of the drawing and the follwing menu will pop up where you will choose Variable… .:

Menu to check the variables

The window with Variables will pop up:

Variables window

If you have done everything right the window will show all the variables in your drawing. Click OK.

NOTE: You can make modifications here if it is required.

We are now ready to compile.  Click Generate VHDL icon on top tool bar just below top menu:

If everything is OK, following window will pop up:

NOTE: Warning windows may pop up before Results, to tell you for example that compilation has found remnants of variables you may have added and invitate you to delete them, that you must do.

A window will pop up if you Close the window, showing the VHDL code that has been generated:

Generated code window

NOTE. You can check now if the code makes sense, but can do nothing else apart going back to  the drawn project and edit it.

We are just about ready to simulate the state diagram and implement the VDL code in our Xilinx FPGA, something that we will do in parts II and III of this tutorial.

Download

The drawing and generated VHDL files can be downloaded from here.

Acknowledgements

A special credit is due to Examples from Class pdf found at University of Wrocester site, for the state diagram. This tutorial uses a  completely different approach to achieve the code generation.

Conclusions

We have designed  a State Diagram in StateCAD and compiled a VHDL file. In part II we will simulate the state diagram and in part III we will program our Digilent Spartan 3 board, and test physically the logic circuit.

Posted in Electronic Projects, Electronic Simulation | Tagged , , , , , , , , , | 2 Comments