Introduction:
In my project, I am sending the blurred image to my PC over uartlite. I had to put some delay (50 us) between sending consecutive data packets. Due to the large size of the image, it takes around 8-9 mins to transfer the image.
Maybe reducing the delay might help in reducing this time. But reducing it much will cause my python code running on the PC (to capture the data) to miss some data. So, I will keep reducing the time delay and watch till what point it is able to capture all the data.
Modifying the receiving code:
I need to modify the python code to print everytime I receive a pixel. The modified code is shown below:
uart_recv.py:
import serial #Image dimensions and total number of pixels in it WIDTH = 400 HEIGHT = 400 PIXELS = WIDTH*HEIGHT IMAGE = [] #Setting the serial port ser = serial.Serial() ser.baudrate = 9600 ser.port = 'COM7' ser.timeout = None print(ser) #Opening the serial port ser.open() print(ser.isOpen()) print("Receiving...") #Number of pixels received num_pix = 0 #Getting the pixel data one byte at a time for i in range(PIXELS): R = ser.read(1) G = ser.read(1) B = ser.read(1) IMAGE.append([R,G,B]) num_pix += 1 print(num_pix) print("Received!") #Closing the serial port ser.close() #Converting the pixel data into int for pixel in IMAGE: pixel[0] = int.from_bytes(pixel[0], 'big', signed=False) pixel[1] = int.from_bytes(pixel[1], 'big', signed=False) pixel[2] = int.from_bytes(pixel[2], 'big', signed=False) #Open the file to write to file = open("C:/Users/Chinmay/Desktop/image/blur_image.txt", "w") #Write the pixel data to the file for pixel in IMAGE: file.write("{" + str(pixel[0]) + "," + str(pixel[1]) + "," + str(pixel[2]) + "},\n") print("Written to File!") #Close the file file.close()
And below shown is the code section in the project that contains the delay for uartlite. I will be changing this delay to know till what point, it can work properly.
I will be using the following image. The blur box matrix is (5x5).
The image has (400x400) dimension, so there are a total of 160000 pixels.
Its pixel data is loaded in an array in my Vitis project.
All the other things will remain same as in this blog.
Receiving the data:
Now, run the code on the board and run "uart_recv.py" on the PC. The number of pixels received will be printed on the terminal as soon as it starts receiving data.
The delay is between sending every pixel.
delay = 50us | time take = 9:18 | pixels received = 160000
delay = 40us | time take = 7:43 | pixels received = 147843
delay = 45us | time take = 8:30 | pixels received = 160000
So, after viewing the result, I guess I was already at the minimum delay possible. For delay = 40 us, the terminal stuck at 147843 pixels. My project would work fine if my delay is 45 us or above.
Actually, I had checked the same for a delay of 20 us also earlier and I could only receive around half the pixels. I think it might require higher delay (higher than 50 us) if the image is larger. So, to confirm this, I am changing my test image and using a larger image and running the code with 45 us delay. The image is shown below:
The image's dimension is (600x600). So, there are a total of 360000 pixels. I ran my Vitis code with this image and ran the uart_recv.py on my PC after doing some changes in it for this particular image (changing the dimension variable). The result is shown below:
delay = 45 us | time take = 19:07 | pixels received = 360000
So, it can be seen that I was able to receive all the pixels for this larger image also. So, it seems that if the delay is more than 45 us, then any size image can be transferred with it. I checked the received image also. It was correct. Its shown below:
Conclusion:
So, we can conclude that to send large amount of data from the board to the PC over uartlite, we need to insert some delay between sending consecutive data packets. Now, this minimum delay can vary with the number of bytes that are sent in one go. In my case, I am sending 3 bytes at a time and I needed 45 us as the minimum delay required to capture it correctly on my PC.