Friday, May 19, 2006

USB-Blaster vs Platform Cable USB


Both USB-Blaster and Platform Cable USB are the USB download cables provided by Altera and Xilinx, respectively. Most of time, the download cable is a necessity while developing and debugging your design in the FPGA. You need them to download the FPGA configuration bitstream through JTAG or Passive/Slave serial mode, to program the CPLD, to program the configuration device, to download your firmware into the soft processor and to tap the signals inside the FPGA through the FPGA embedded logic analyzer. Both of them are able to achieve all the above-mentioned purposes. But what is the main difference between them? The SELLING PRICE!!! The USB-Blaster costs USD$300 while the Platform Cable USB only costs half the price of the USB-Blaster, which is USD$149. This is really killing me because sometimes I need to use more than one download cable at the same time when dealing with multi-FPGA environment. Why can’t the Altera USB-Blaster at least cost the same like the Xilinx Platform Cable USB? In fact, Xilinx Platform Cable USB has even more features than USB-Blaster such as programming the configuration clock frequency. The USB-Blaster operates at USB full speed, which is 12Mbps, while the Platform Cable USB can operate at USB high speed!

Frankly speaking, the download cable should cost as cheap as possible by the FPGA vendors because they should be making money from selling their FPGA and CPLD devices, not from selling the download cables. Similar to the Quartus II and ISE web edition software tool, the download cable should just be a marketing tool to help promote the usage of FPGA or CPLD solutions! Imagine if I am a newbie who want to learn to use FPGA or CPLD on my own, it doesn’t make sense for me to buy a tool that is much much more expensive than a single low-cost FPGA/CPLD device.

Anyway, just for your reference, I also compare the cost of download cables that use the PC parallel port interface which are Altera ByteBlaster II, USD$150 and Xilinx Parallel Cable IV, USD$95. Once again, Xilinx is the winner when it comes to the price war. Is this the reason Xilinx being the market leader? Well, you know better.

/////////////////////////////////////////////////////////////////////////////////
// Disclaimer: All the price stated above are extracted from Altera Buy On-Line and Xilinx Online Store websites at the posting time and may change from time to time in future.

Friday, May 05, 2006

Convert Floating Point to String

A few months ago, I found out that there is no built-in function for converting a floating point data type variable to a string although there are functions that do the following:

1. Convert a string to floating point (atof)
2. Convert an integer to string (itoa)
3. Convert a string to an integer (atoi)

All the above functions come in very handy when you want to write your data to a text file. It is quite intriguing because itoa(), atoi() and atof() are provided but ftoa() are not. Unfortunately, many data are floating points in nature. Also, data that are larger than a 32-bit integer are usually represented as floating point data type. Anyway, many programming experts have already provided ftoa() solution on their websites. I believe it is not difficult to find one out there but I would like to have my very own one, too, as it is no harm trying. The C/C++ code is as shown below. I have tested it in the Microsoft Visual C++ compiler but I do not cover all the possible cases. So, use it on your own risk. It is not the best solution available for ftoa() but it certainly enough to meet my purposes. If you need one, I hope that it helps you, as well. If not, you can always write one for yourself.


////////////////////////////////////////////////////////////////
// my_ftoa.cpp
// date created: May 5, 2006
// author:
http://fpgaforum.blogspot.com/
////////////////////////////////////////////////////////////////


#include <iostream>
#include <cmath>
using namespace std;
#define PRECISION_POINT 4 //Change this to display more or less precision point

void ftoa(float f, char* a, int point); //function prototype

void main()
{
  float f = -1.23456;
  char result[32];
  ftoa(f,result, PRECISION_POINT);
  cout << result;
}

void ftoa(float f, char* a, int point)
{
  char buf_int [2]; //temporary buffer
  char buf_d [16]; //to store the integral part, e.g. "-123" for "-123.456"
  char buf_f [16]; //to store all the fraction part, e.g. "000123" for "1.000123"
  char buf_nz [16]; //to store the non-zero fraction part, e.g. "123" for "1.000123"
  int d= (int)(f); //integral part

  float fp = (f<0) ? (d-f) : (f-d); //fractional part

  int fp2int = fp*(pow(10,point));
  int fpplus1 = fp*(pow(10,point+1));

  if((fpplus1%10)>=5)
    fp2int++;

  strcpy(buf_int,"");
  strcpy(buf_d,""); //clear the buffer, just to be safe
  strcpy(buf_f,""); //clear the buffer, just to be safe
  
strcpy(buf_nz,""); //clear the buffer, just to be safe

  if((d == 0) && (f<0) && (f>-1))
  {
    strcat(buf_d,"-");
    itoa(d,buf_int,10);
    strcat(buf_d,buf_int);
  }
  else
  {
    itoa(d,buf_d,10);
  }
  strcat(buf_d,".");
  //looking for the leading zeros at the fractional part
  if(fp2int == 0)
  {
    for(int i = 0; i < point-1; i++)
      strcat(buf_f,"0");
  }
  else if(fp2int < (pow(10,point-1)))
  {
    for(int i = 0; i < point; i++)
    {
      int j = pow(10,(point-1-i));
      if(fp2int < j)
        strcat(buf_f,"0");
      else break;
    }
  }

  itoa(fp2int,buf_nz,10);
  strcat(buf_f,buf_nz);
  strcat(buf_d,buf_f);
  strcpy(a,buf_d);
}

// The end
////////////////////////////////////////////////////////////////