Thursday, March 14, 2013

Spartan-6 Clock Multiplier / Divider using PLL DCM

I started using Spartan-6 FPGA couple of weeks ago.  Going back to my old VHDL coding to be able to work on a custom application.
I needed to divide my input 100MHz CLK to run a task at 33MHz.  I know I should be able to do that with the PLL/DCM built in the Spartan-6.  But, I can not find any reference code to show what/how is this done in code.  How can I configure the PLL registers to divide/multiply and what is the labels I will be using to trigger to my task.

If someone out there able to explain that, I really would appreciate a lot.

Saturday, March 9, 2013

FPGA SPARTAN-2 XC2S200 Tools

I am going back to my Digilab 2 FPGA Board that has Spartan-2 FPGA from Xilinx for a small project and proof of concept, but for my surprise, the new ISE Webpack from Xilinx does not support this chip anymore.  And, of-course, Digilent does not support it either,   is it discontinued board.  So, now what should I do?

I know this board is more than enough for what I am working on.  I got another board Nexys-3 that has Spartan-6 and it works so far great, but, is the Spartan-2 really un-usable now?  or, is someone out there can guide to and point me to a tool that I can use to program it with?

I am going to work on this task and try to see what I can do and find...

Friday, January 18, 2013

Android Development How to Set Focus

You ever need to set focus for a control on your GUI.
You could design a GUI interface for your Android application but, you need to set the focus to one specific control on start-up.  In this example I am using a Button control for that.  You have two options, option one: add the focus option in the xml file that describes your GUI, or option two: add the code that does the same thing in option one but can be used in run time instead of only once on start-up.

Option One:
Add this part to your xml GUI file



<Button
android:id="@+id/open_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open_comm"
android:onClick="onClick"
android:focusableInTouchMode="true"
>
<requestFocus/>
</Button>



Option Two:
Add this to the Activity module:

static Button Open_Button;

Open_Button = (Button) findViewById(R.id.open_bt);

Open_Button.setFocusableInTouchMode(true);
Open_Button.requestFocus();


More information will be added, and screen shots...

Wednesday, December 12, 2012

MPLAB X IDE So Slow and takes for EVER

Anyone can help with this would be great.  It was working fine for ever, then suddenly it started to take forever when I connect to the board to download FW or edit project settings.

I now I installed some Java for Android development recently and this is about the time it started to do this...
What part is causing this I am not sure yet...


Some of the things I did so far and did not work:

  1. I changed the path to  jdkhome=""  in the following file  "C:\Program Files (x86)\Microchip\MPLABX\mplab_ide\etc\mplab_ide.conf"
  2. I also, added the switch to the start-up icon "C:\Program Files (x86)\Microchip\MPLABX\mplab_ide\bin\mplab_ide.exe" --jdkhome "C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.6.0_32-windows-x64\java-windows"




This is not good, it is killing me, I can not do any development like this...

Updates: 12/13/2012:
It was something with my Bluetooth.  I started working on Bluetooth around the same time when MPLAB started acting this way.  So, I thought to disconnect my BT dongle, and walla, MPLAB working just fine!!  Something was going on between BT dongle and MPLAB.  I will have to find out!

Monday, December 10, 2012

Configure Eclipse to Auto-Save before Executing App

So, if you develop using  Eclipse, you must know how you have to save your modules every time you click on run.  So, it is an extra click every time.  Usually in most other IDEs you would not have to do this, because they have an option to auto-save your modified documents.

I know there was an option in Eclipse too, and I used it before but, I forgot how to do that and it took me a while to find it again.
so, here it is, a note to my self and to others who need to know how...

Click on Window -> Preferences
Select General from the list on the left
Expand it and click on Workspace
In the right side make sure the "Save automatically before build" is checked



Now Select Run/Debug from the list on the left
and Expand it to Select Launching
In the right side find and make sure "Save required dirty editors before launching" is Always



Click OK and you are set to go.



Tuesday, December 4, 2012

Do you get this message: "javadoc java platform manager"

If you are using NetBeans and writing Java applications, you try to get some information on functions or properties details and you get this message, "javadoc java platform manager". Then you most likely missing some Documentation from Java JDK.




Try and delete this folder first after backing it up some where:
/home/elsaghir/.netbeans/7.0/var/cache

Here is what you need to add:
sudo aptitude install openjdk-6-jdk
sudo aptitude install openjdk-6-doc

replace the number 6 with the latest revision of java at this time...
you should see new data and folders in this folder 
/usr/lib/jvm/default-java/docs

How to: Retrieve Time in C++ OR Calculate Elapsed Time


Here are few different methods to retrieve time in C++ depends on your requirements

I always need to retrieve time information one way or anther to use in my code. so I decided to create this Knol to keep/list all methods and related information for everyone so we can retrieve this easier in the future!




/*
The Goal of this project is to be a reference to all Date and time stuff
Author: Hesham Elsaghir
Date: 10/13/2010
*/
#include"stdafx.h"#include "iostream"#include "time.h"#include "atltime.h"
using namespace std;

int  _tmain(int argc, _TCHAR* argv[])
{
SYSTEMTIME st;
FILETIME ft;

unsigned short File_Time_Date;
unsigned short File_Time_Time; // time and date in numbers format...

GetLocalTime(&st);

SystemTimeToFileTime(&st, &ft);
cout << "Today's Day # is: " << st.wDay << endl;
cout << "Today's Month # is: " << st.wMonth << endl;
cout << "Today's Year is: " << st.wYear << endl;
// This function will convert the time and date to Dos Date and Time format
FileTimeToDosDateTime(&ft, &(File_Time_Date), &(File_Time_Time));
cout << "Time now in File time is: " << File_Time_Time << endl;
cout << "Time now in File Date is: " << File_Time_Date << endl;
// This is a different method to obtain Date and Time
struct tm now;
time_t time_now;
time(&time_now);
now = *localtime(&time_now); 
/* Get time and date structure */mktime(&now);
cout << "Time now is: " << now.tm_mon << now.tm_mday << now.tm_year << endl;cout << "Ctime format to time: " << ctime(&time_now) << endl;

long time_taken = clock();
printf(
"%ld\n", time_taken);
printf("%d\n", CLOCKS_PER_SEC);
// How to use sscanf() to int day, month, year;
char test[] = "10/3/2010";
sscanf(test, "%d/%d/%d", &day, &month, &year);
printf(
"day: %02d\n",day);
printf(
"moth: %02d\n",month);
printf(
"year: %04d\n",year);
// Here is a way to print local and Gtime "UTC"struct tm *local;
time_t t;
t = time(NULL);
local = localtime(&t);
printf(
"Local time and date: %s\n", asctime(local));
local = gmtime(&t);
printf(
"UTC time and date: %s\n", asctime(local));

// Using sprintf to write a formated string into an array
GetLocalTime(&st);
char temp_mdy[50];
sprintf(temp_mdy, "    @date       %02d/%02d/%04d\n",st.wMonth,st.wDay, st.wYear);

cout << temp_mdy << endl;


// Different methods to capture time elapsed
long st_time = clock();
// do some work here
Sleep(500);             // sleep 500 milliseconds
long sp_time = clock();
printf("Time Elapsed is: %ld Millisecond\n", sp_time - st_time);
// Or you can use this
time_t time_1, time_2;
time(&time_1);
Sleep(10000);                 // sleep 10 seconds
time(&time_2);
printf("Time Elapsed is: %.2lf seconds\n", difftime(time_2,time_1));


return
 0;
}

Here is the output of the program:
 



I will be adding more futures to cover C# later.

References:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/