UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Participant bgw_bogdan
Participant
658 Views
Registered: ‎07-26-2013

read time of GPIO pin too long

Jump to solution

In my design I have MicroBlaze instance which runs at 100MHz.

I want to measure how much time I need to get a new value of a GPIO pin. This is my pseudo code:

 

enable timer;

t1= get timer value;

pin_value = XGpio_DiscreteRead(gpio pin);

t2 = get timer value;

 

print(t2-t1);

 

And this give me something like 3000 clks which means around 30us?

I have tried to use optimization, to enable/disable interrupts, but I can't see any significant reduce of time I need to read this value..Where to look? Do I have something in my hw design wrong? Or is it bad code? 

Thanks! 

0 Kudos
1 Solution

Accepted Solutions
Participant bgw_bogdan
Participant
634 Views
Registered: ‎07-26-2013

Re: read time of GPIO pin too long

Jump to solution

At the end solution for this was very simple. Instruction and data cache were not enabled and because of that performances of MB were really poor. I have to enable instruction and data cache by Xil_ICacheEnable() and Xil_DCacheEnable(). 

Thanks for the help! 

0 Kudos
3 Replies
Voyager
Voyager
601 Views
Registered: ‎03-28-2016

Re: read time of GPIO pin too long

Jump to solution

Check out the implementation of the XGpio_DiscreteRead() function.  Look in the gpio library source directory (...bsp.../microblaze_0/libsrc/gpio_...).  Maybe there are safety checks in there you don't absolutely require.  If so, you could make your own copy of the function and trim it down to run faster.

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com
0 Kudos
Adventurer
Adventurer
594 Views
Registered: ‎04-19-2018

Re: read time of GPIO pin too long

Jump to solution
first, compilers may translate apparently simple lines into many assembler instructions. I bet that is a simple register read and should take much much less than a microsecond.
If assembler is over the top for you, I'd suggest an empirical approach: replace the single read by a for loop reading 10, 100, 1000, even more if you can (be aware of counter roll over). Run the series again with no read (empty loop - you might need to disable optimizations, sometimes compilers are too smart).
Now, for each series, subtract the empty loop time from the reading one. Plot these values against the number of reads (10, 100, etc). I would expect them to fall in a straight line. The slope should be the time it takes for a single reading.
Good luck!
0 Kudos
Participant bgw_bogdan
Participant
635 Views
Registered: ‎07-26-2013

Re: read time of GPIO pin too long

Jump to solution

At the end solution for this was very simple. Instruction and data cache were not enabled and because of that performances of MB were really poor. I have to enable instruction and data cache by Xil_ICacheEnable() and Xil_DCacheEnable(). 

Thanks for the help! 

0 Kudos