Tuesday, June 7, 2016

Using the Analog Discovery Box and the ADC


The picture above shows how to connect the Analog Discovery Portable Analog Circuit Design Kit to the ADC Maxim chip. The black wire is ground and the yellow wire is the wave generator.

The wave generated is just a constant signal of 3.6 V shown in the picture below.


This is the output when using the 3.6 V. This makes sense because the max voltage that the maxim chip can take is 3.6 V so this should result in the max value of the 15 bit number which is 32767. I am confused on why it wouldn't be the max value of a 16 bit number but I have to look into this some more. 


When a signal of 1.8 V was created using the wave generator, the output was 14971, which behaved almost like I expected. When I took half of the wave voltage, the output was almost halved. I will also have to look into the relationship between these values.

Petalinux commands not found, errors

After a fresh install of Petalinux v2016.1 via the installer (http://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools/2015-4.html)

Make the file executable by typing in the terminal in the directory of the installer download: 'sudo chmod +x filename.run'. Then, begin the install by typing: './filename.run' (where filename.run is the actual name of the file downloaded. For me it was petalinux-v2016.1-final-installer.run).

If the install requires additional tools and packages to properly download, download them. How to do this can be found online pretty easily.

After the install is complete, you may experience errors that may tell you certain commands are not found when you try and execute them. To avoid this inconvenience, in the terminal type:

IMPORTANT NOTE - YOU MUST RUN THE SETTINGS SCRIPT EACH TIME YOU OPEN A NEW TERMINAL OR SHELL. THE PETALINUX TOOLS WILL FAIL OTHERWISE.

'source <path to installation of petalinux>/ settings.sh'
'echo $PETALINUX'
'/opt/Xilinx/petalinux-v201X.x-final'


So for example in my circumstance I executed:

'source /opt/Xilinx/petalinux-v2016.1-final/ settings.sh'
'echo $PETALINUX'
'/opt/Xilinx/petalinux-v2016.1-final'

Now commands such as create and others should work fine.

Reference the full Petalinux Tools user guide below:

http://www.xilinx.com/support/documentation/sw_manuals/petalinux2014_2/ug977-petalinux-getting-started.pdf

Monday, June 6, 2016

Link to clone SD Cards (for copying linux images)

https://wiki.archlinux.org/index.php/disk_cloning

'Things we should all know' tutorial

Today I completed Mike's Tutorials on the blog titled, Things We should All Know (Vivado HLS) (Vivado) and (Petalinux). 

Once the tutorial is complete and you type in username root and password root, you are then able to control parts of the Zedboard using the terminal. For example, if you navigate to bin and type ls, you will see all the different commands like poke. Then, in Vivado, open the block design and observe that the LEDs are connected to axi_gpio_0. Then click on the Address Editor tab and find this cell. Notice that the offset Address is 0x4120_0000 which is the address that the LEDs are connected to within the Zedboard. 

Then you can go back to the terminal and type the following:
poke 0x4120000 0xFF 
which successfully turned on the LEDs on the Zedboard. Then if you type:
poke 0x4120000 0x0
then the LEDs turn off.







To run Pre_Filter and actually get an output at this point, follow the steps below.

Go through the usual steps of making the block design and then launch SDK. Continue as you would normally and open new application, then import src (Pre_Filter.c) and program the FPGA. Then once you run the program, open up a terminal in the virtual machine and navigate to the directory that contains the .c file. Then type:

make Pre_Filter  (which makes the file an  executable program)
./Pre_Filter     (This actually runs the code)

The output looks like this..

Inline image 1

Proximity Sensor - Maxim44000

Steps to getting the Maxim chip working:

Follow the steps given in the tutorial link below.

This starts with sdk rather than vivado because it includes a hidden block design/code for each of the maxim chips. Once you have completed the tutorial and the FPGA is programmed, then you can use gtk term to read the output of the chip. The instructions below are for installing and using gtk term.

 The following link gives a three step process on how to install gtkterm.
http://pkgs.org/centos-6/epel-i386/gtkterm-0.99.5-11.el6.i686.rpm.html

In the first step, this link is provided:
http://dl.fedoraproject.org/pub/epel/6/i386/

Open the previous link and look for:
epel-release-6-8.noarch.rpm
Click on this link and it will download. Then in the downloads folder, or at the bottom of your web browser, click the file to install it.
Then go to the terminal and type the following:
sudo yum install gtkterm
Directions to use gtkterm are in Sven's blog:
http://svenand.blogdrive.com/archive/173.html#.VWh9l9jbJ9A

At the beginning of the blog, it talks about permissions. Following these steps can help with that:
To check for the permissions, open a terminal and type:
          cd ..
          cd ..  (to move all the way out)
          cd dev (must be in this directory)
          ls -l ttyAMC0  (checks the permission)
If the permission is not crw-rw-rw, then type:
          sudo chmod 666 ttyACM0

Then we are able to follow the steps in Sven's blog.

Then once you run the program, gtk term should look something like the picture below. This picture should the fluctuations in the Proximity value as I moved my hand closer to the sensor and then farther away and repeating this motion.

Inline image 1

I am still unsure of what these values mean but the datasheet (http://datasheets.maximintegrated.com/en/ds/MAX44000.pdf) states that a photodiode array inside the IC converts light to a current which is then processed into a digital value. I think this digital value is an 8 bit number because 2^8 = 256 and the highest value that was outputted when my hand was directly on top of the sensor was 253. This is just an idea and I need to look into this more.

253  fd    11111101
208  d0    1101000
125  7d    01100001
97    61    01100001

Own LED Program

We made our own hardware and software design in order to have the LEDs light up one by one consecutively. We used the 1st Tutorial as a guide to build the hardware with the processing system and an LED GPIO, and then modified the code to change the way the LEDs lit up.


/********************************************************************************************
*This software file will demonstrate the use of a GPIO (General Purpose Input Output) and the
*connection to a Zynq Processing System in order to carry out some function.
*The relatively simple software application that we have created was designed to control the
*LEDs on the ZedBoard. When working, the LEDs will light up one by one consecutively from one
*end to the other.
*******************************************************************************************/


/* Include Files */
#include "xparameters.h"
#include "xgpio.h"
#include "xstatus.h"
#include "xil_printf.h"


/* Definitions */
#define GPIO_DEVICE_ID  XPAR_AXI_GPIO_0_DEVICE_ID    /* GPIO device that LEDs are connected to */
#define LED 0x01                                    /* Initial LED value - X0000000 */
#define LED_DELAY 10000000                            /* Software delay length */
#define LED_CHANNEL 1                                /* GPIO port for LEDs */
#define printf xil_printf                            /* smaller, optimised printf */

XGpio Gpio;                                            /* GPIO Device driver instance */

int EmilyLEDProject(void)
{

    //volatile int delay;
    int Status;
    int led = LED; /* Hold current LED value. Initialize to LED definition */

        /* GPIO driver initialization */
        Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
        if (Status != XST_SUCCESS) {
            return XST_FAILURE;
        }

        /*Set the direction for the LEDs to output. */
        XGpio_SetDataDirection(&Gpio, LED_CHANNEL, 0x00);


        led = 0x01;
        int i;
        for (i=1;i<8;i++){
            XGpio_DiscreteWrite(&Gpio,LED_CHANNEL,led);
            delay(LED_DELAY);
            led = (int)(1<<i);
            XGpio_DiscreteWrite(&Gpio,LED_CHANNEL,led);
            delay(LED_DELAY);
        }

        return XST_SUCCESS; /* Should be unreachable */
}

void delay(int nStopValue)
/**
* \brief       Loop for nStopValue iterations to provide a delay.
* \par         Details
*              It is commonly used with the constant 'ABOUT_ONE_SECOND' defined in maximPMOD.h for
*              setting approximate delays
*
* \param[in]   nStopValue    - number of iterations to loop
*
* \retval      None
*/
{
    int i=0;
    int a=0;

    for(i=0;i<nStopValue;i++)
    {
        a=i;
    }
}
/* Main function. */
int main(void){

    int Status;

    /* Execute the LED output. */
    Status = EmilyLEDProject();
    if (Status != XST_SUCCESS) {
        xil_printf("GPIO output to the LEDs failed!\r\n");
    }

    return 0;
}





/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Most of the code was the same as the 1st Tutorial, but we needed to add the delay function from a previous post in order to properly delay the time after each LED lit up. The delay code we used was taken from Mike's previous blog post, and looked like the following:

void delay(int nStopValue)
/**
* \brief       Loop for nStopValue iterations to provide a delay.
* \par         Details
*              It is commonly used with the constant 'ABOUT_ONE_SECOND' defined in maximPMOD.h for
*              setting approximate delays
*
* \param[in]   nStopValue    - number of iterations to loop
*
* \retval      None
*/
{
    int i=0;
    int a=0;

    for(i=0;i<nStopValue;i++)
    {
        a=i;
    }

This allowed for a pause of about one second after one LED lit up to the time the next one did.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

After this code was successfully working, we decided to modify it to make the LEDs light up 1-8 and then back down 8-1 continuously without stopping.
In order to do this we needed to add another 'for' loop right after the first one telling the LEDs to blink consecutively in reverse order from 8 down to 1. The 'for' loop we made looked like the following:

int j;
        for (j=8;j>-2;j--){
                    XGpio_DiscreteWrite(&Gpio,LED_CHANNEL,led);
                    delay(LED_DELAY);
                    led = (int)(1<<j);
                    //XGpio_DiscreteWrite(&Gpio,LED_CHANNEL,led);
                    delay(LED_DELAY);
                }
}

We named the variable 'j' and made it decrement by 1 starting at LED 8 and going down to -2. We had trouble getting it all the way down to the last LED and it seemed that it was reading the value for the first LED to be -2.


In order to make this non-stop we needed to put both the 2 'for' loops in a 'while' loop, which successfully made it run up the LEDs and back down without stopping.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 






Saturday, June 4, 2016

Adding Files to SD Card to boot Linaro

Now that our SD card is set with a 52 MB FAT 32 boot partition and an ext4 root file system partition, we can add the files that will boot Linaro on the Zedboard.

** What we will need **

- The Out of Box files that come on the SD card with the Zedboard. If you do not have these files, fear not, they can be downloaded from this page : https://reference.digilentinc.com/zedboard:zedboard

Download the Out-of-Box Demo .zip file and extract the files to the directory of your choice

-The Linaro file system from:
http://releases.linaro.org/archive/12.09/ubuntu/precise-images/ubuntu-desktop/linaro-precise-ubuntu-desktop-20120923-436.tar.gz

The file should look like this: linaro-precise-ubuntu-desktop-20120923-436.tar.gz

-Linaro device tree blob file (.dtb) from http://svenand.blogdrive.com/Zynq/Linaro/devicetree_linaro.dtb

The file should look like this: devicetree_linaro.dtb

Once we have all these downloaded, we are ready!

The first step is to copy the image files that come with the Zedboard SD card onto our 52 MB BOOT partition of our SD card. All of these files are located in the sd_image folder of the Zedboard Out of Box Demo download.

Our BOOT partition should look like this.





The next step is to get the Linaro file system onto our SD Card. We want to start by making a directory named 'linaro' in the tmp folder of our computer. This can be done by going to the terminal and typing the following commands.
   
     cd /tmp
     mkdir linaro

Once we have this directory, we should navigate to the folder where our Linaro file system downloaded, and run the following command in the terminal to copy the file to the /tmp/linaro directory that we just created.
     
     sudo cp linaro-precise-ubuntu-desktop-20120923-436.tar.gz /tmp/linaro/

Navigate to the linaro folder by typing cd /tmp/linaro/ in the terminal. Now we are going to unpack the file by running the following command.

     sudo tar zxf  linaro-precise-ubuntu-desktop-20120923-436.tar.gz

Your linaro folder should now look like this.

The next step is to copy the file system to the ext4 rootfs partition of our SD card. You should locate where your partitions are mounted, however they usually get mounted to the /media directory. For my machine, they are mounted at /media/zynquser/. Navigate to /tmp/linaro/binary/boot/filesystem.dir by typing 'cd /tmp/linaro/binary/boot/filesystem.dir' in terminal. Run this command to copy the file system to the rootfs partition of the SD card (This may take a few minutes).

     sudo rsync -a --progress ./ /media/zynquser/rootfs/

Once the above command is complete, unmount the partition to ensure all files have been synchronized successfully. You can unmount the partition in the terminal by typing 'sudo umount /media/zynquser/rootfs/'

We are almost done!

All that is left to do is fix the boot files to correctly boot Linaro. Open the BOOT partition on our SD card, and delete the ramdisk8M.image.gz and devicetree_ramdisk.dtb files. Then, copy the devicetree_linaro.dtb into the BOOT partition. Our BOOT partition should now look like this.





We did it! Our SD card is ready to help us boot Linaro on the Zedboard. To prepare the Zedboard for booting Linaro, please reference this earlier blog entry.

http://zedboardsiena2015.blogspot.com/2016/03/ubuntu-with-linaro-gui-working.html