cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
xuantran
Participant
Participant
561 Views
Registered: ‎04-11-2019

Microbalze becomes weird

Dear all,

I have a Microblaze, which blinks a LED by using for loop delay with DELAY being 10000.

Clock of the Microblaze is 100MHz.

Optimization level of an application is -O0.

With this setup, I can see clearly the blinking LED .

However, when the Microblaze uses a Timer to measure eslapsed time of the for loop. I cannot see the blinking LED anymore. Actually, in this case the LED blinks faster than in the case without the Timer. In oder to see the blinking LED, I changed the DELAY of the for loop to 1000000.

 

I did an another experiment on the Evaluation Board VC709. The setup is the same as the one I did before. Nevertheless, I only see the blinking LED with the DELAY of the for loop being 1000000. With the DELAY being 10000, I cannot see the blinking LED.

 

Could you explain why it happens like this? What did I do wrongly?

I would be grateful for any help.

0 Kudos
Reply
4 Replies
bpatterson
Visitor
Visitor
542 Views
Registered: ‎06-27-2019

It would probably be helpful if you could post your code / block design.

0 Kudos
Reply
xuantran
Participant
Participant
522 Views
Registered: ‎04-11-2019

Thank you so much for your suggestion.

I attach the snapshop of the block desgin. The code is below.

* main.c

/****************************************************************************/
/* Includes */
#include "xparameters.h"
#include "xstatus.h"

#include "gpio.h"
#include "xtmrctr.h"

/****************************************************************************/
#define GPIO_LED_DEVICE_ID XPAR_GRNCB_UB_MAIN_GRNCB_UB_AXI_GPIO_0_BASEADDR
#define TMRCTR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID

#define TIMER_COUNTER_0 0

/* The AXI GPIO is connected to a tri color LED. This LED can light up into two
* different colors: green and red. */
static const uint32_t LED_GREEN = 0;// Bit 0 of GPIO is connected to the green LED
static const uint32_t LED_RED = 1; // Bit 1 of GPIO is connected to the red LED
static const uint32_t LED_DELAY = 10000;
/****************************************************************************/

/* Variable Definitions */
static XGpio gpioLEDInst; /* The instance of the GPIO */

static XTmrCtr TimerCounter; /* The instance of the Tmrctr Device */

/****************************************************************************/
static int32_t mainInit ();

/****************************************************************************/

int main()
{
int32_t status = XST_FAILURE;
volatile uint32_t i = 0;
uint32_t initTimerVal = 0;
uint32_t currTimerVal = 0;
uint32_t diffTimerVal = 0;

status = mainInit();
if (XST_SUCCESS != status)
return XST_FAILURE;

/* Start the timer */
XTmrCtr_Start(&TimerCounter, TIMER_COUNTER_0);

while(1)
{
gpioLEDOn (&gpioLEDInst, LED_GREEN); // Turn on LED
initTimerVal = XTmrCtr_GetValue (&TimerCounter, TIMER_COUNTER_0);
for (i = 0; i < LED_DELAY; ++i); // Delay

currTimerVal = XTmrCtr_GetValue (&TimerCounter, TIMER_COUNTER_0);

diffTimerVal = currTimerVal - initTimerVal;

gpioLEDOff (&gpioLEDInst, LED_GREEN); // Turn off LED
for (i = 0; i < LED_DELAY; ++i) {} // Delay
gpioLEDOn (&gpioLEDInst, LED_RED); // Turn on LED
for (i = 0; i < LED_DELAY; ++i) {} // Delay
gpioLEDOff (&gpioLEDInst, LED_RED); // Turn off LED
for (i = 0; i < LED_DELAY; ++i){} // Delay
}
/*
* Disable the Autoreload mode of the timer counters.
*/
XTmrCtr_SetOptions(&TimerCounter, TIMER_COUNTER_0, 0);

return 0;
}

/****************************************************************************/
static int32_t mainInit ()
{
int32_t status = XST_FAILURE;

/* Initialize GPIO (LEDs) */
status = gpioLEDInit (&gpioLEDInst, GPIO_LED_DEVICE_ID);
if (XST_SUCCESS != status)
return XST_FAILURE;

/* Initialize Timer */
status = tmrCntInit (&TimerCounter, TMRCTR_DEVICE_ID, TIMER_COUNTER_0);
if (XST_SUCCESS != status)
{
return XST_FAILURE;
}

return status;
}
/****************************************************************************/

 

Please let me know if there is anything missing or unclear.

190807_uBlaze.png
0 Kudos
Reply
peters
Xilinx Employee
Xilinx Employee
445 Views
Registered: ‎11-28-2007

Hi Xuan,

One thing I noticed is the line in your your C-code:

 

#define GPIO_LED_DEVICE_ID XPAR_GRNCB_UB_MAIN_GRNCB_UB_AXI_GPIO_0_BASEADDR

 

You assign a Baseaddress to a device ID which doesn’t look right for me.

The device ID is an assigned number to an instance of axi_gpio (can be seen in the xparameters.h), whereas the Baseaddress is actually an address in your address map.

Please check if this could be the problem.

xuantran
Participant
Participant
432 Views
Registered: ‎04-11-2019

You are right. Thank you so much for pointing out my mistake.

#define GPIO_LED_DEVICE_ID XPAR_GRNCB_UB_MAIN_GRNCB_UB_AXI_GPIO_0_BASEADDR

XPAR_GRNCB_UB_MAIN_GRNCB_UB_AXI_GPIO_0_BASEADDR = 0x40000000

Unfortunately , the software still finds the device beacause the DeviceId is uint16_t. :-(

int32_t gpioLEDInit (XGpio *InstancePtr, uint16_t DeviceId)