element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet & Tria Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
ZedBoard Hardware Design AXI Timer creates functioning interrupts but doesn't generate outputs
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 5 replies
  • Subscribers 354 subscribers
  • Views 1786 views
  • Users 0 members are here
Related

AXI Timer creates functioning interrupts but doesn't generate outputs

Former Member
Former Member over 9 years ago

Hi,

I'm trying to generate PWM signals using AXI timers but right now I'm having some difficulty even getting just a square wave output from the timer so I'm hoping someone can help me with that first.

My hardware setup follows the instructions in Zynq Book Exercise 2D, with the timer & Zedboard buttons generating interrupts concatenated together, except that I've added three additional ports connected to the AXI timer outputs generateout0, generateout1, and pwm0.

My code also follows that example, except that I've modified the timer options setup by adding the XTC_EXT_COMPARE_OPTION into the following line:

XTmrCtr_SetOptions(&TMRInst, 0, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_EXT_COMPARE_OPTION);

My constraint file:

set_property PACKAGE_PIN W8 [get_ports pmod_jb4]
set_property PACKAGE_PIN AA9 [get_ports pmod_ja4]
set_property PACKAGE_PIN Y10 [get_ports pmod_ja3]
set_property IOSTANDARD LVCMOS33 [get_ports pmod_ja4]
set_property IOSTANDARD LVCMOS33 [get_ports pmod_jb4]
set_property IOSTANDARD LVCMOS33 [get_ports pmod_ja3]

My code:

#include "xparameters.h"
#include "xgpio.h"
#include "xtmrctr.h"
#include "xscugic.h"
#include "xil_exception.h"
#include "xil_printf.h"

// Parameter definitions
#define INTC_DEVICE_ID ttXPAR_PS7_SCUGIC_0_DEVICE_ID
#define TMR_DEVICE_IDttXPAR_TMRCTR_0_DEVICE_ID
#define BTNS_DEVICE_IDttXPAR_AXI_GPIO_0_DEVICE_ID
#define LEDS_DEVICE_IDttXPAR_AXI_GPIO_1_DEVICE_ID
#define INTC_GPIO_INTERRUPT_ID XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR
#define INTC_TMR_INTERRUPT_ID XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR

#define BTN_INT tttXGPIO_IR_CH1_MASK
#define TMR_LOADttt0xFFFE7961

XGpio LEDInst, BTNInst;
XScuGic INTCInst;
XTmrCtr TMRInst;
static int led_data;
static int btn_value;
static int tmr_count;

//----------------------------------------------------
// PROTOTYPE FUNCTIONS
//----------------------------------------------------
static void BTN_Intr_Handler(void *baseaddr_p);
static void TMR_Intr_Handler(void *baseaddr_p);
static int InterruptSystemSetup(XScuGic *XScuGicInstancePtr);
static int IntcInitFunction(u16 DeviceId, XTmrCtr *TmrInstancePtr, XGpio *GpioInstancePtr);

//----------------------------------------------------
// INTERRUPT HANDLER FUNCTIONS
// - called by the timer, button interrupt, performs
// - LED flashing
//----------------------------------------------------


void BTN_Intr_Handler(void *InstancePtr)
{
t// Disable GPIO interrupts
tXGpio_InterruptDisable(&BTNInst, BTN_INT);
t// Ignore additional button presses
tif ((XGpio_InterruptGetStatus(&BTNInst) & BTN_INT) !=
tttBTN_INT) {
tttreturn;
tt}
tbtn_value = XGpio_DiscreteRead(&BTNInst, 1);
t// Increment counter based on button value
t// Reset if centre button pressed
tif(btn_value != 1) led_data = led_data + btn_value;
telse led_data = 0;
    XGpio_DiscreteWrite(&LEDInst, 1, led_data);
    (void)XGpio_InterruptClear(&BTNInst, BTN_INT);
    // Enable GPIO interrupts
    XGpio_InterruptEnable(&BTNInst, BTN_INT);
}

void TMR_Intr_Handler(void *data)
{
tif (XTmrCtr_IsExpired(&TMRInst,0)){
ttXTmrCtr_Stop(&TMRInst,0);
tt// Once timer has expired 3 times, stop, increment counter
tt// reset timer and start running again
tt//if(tmr_count == 3){

tt//ttmr_count = 0;
tttled_data++;
tttXGpio_DiscreteWrite(&LEDInst, 1, led_data);
tt//}
tt//else tmr_count++;

tXTmrCtr_Reset(&TMRInst,0);
tXTmrCtr_Start(&TMRInst,0);
t}
}



//----------------------------------------------------
// MAIN FUNCTION
//----------------------------------------------------
int main (void)
{
  int status;
  //----------------------------------------------------
  // INITIALIZE THE PERIPHERALS & SET DIRECTIONS OF GPIO
  //----------------------------------------------------
  // Initialise LEDs
  status = XGpio_Initialize(&LEDInst, LEDS_DEVICE_ID);
  if(status != XST_SUCCESS) return XST_FAILURE;
  // Initialise Push Buttons
  status = XGpio_Initialize(&BTNInst, BTNS_DEVICE_ID);
  if(status != XST_SUCCESS) return XST_FAILURE;
  // Set LEDs direction to outputs
  XGpio_SetDataDirection(&LEDInst, 1, 0x00);
  // Set all buttons direction to inputs
  XGpio_SetDataDirection(&BTNInst, 1, 0xFF);


  //----------------------------------------------------
  // SETUP THE TIMER
  //----------------------------------------------------
  status = XTmrCtr_Initialize(&TMRInst, TMR_DEVICE_ID);
  if(status != XST_SUCCESS) return XST_FAILURE;
  XTmrCtr_SetHandler(&TMRInst, TMR_Intr_Handler, &TMRInst);
  XTmrCtr_SetResetValue(&TMRInst, 0, TMR_LOAD);
  XTmrCtr_SetOptions(&TMRInst, 0, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_EXT_COMPARE_OPTION);
//XTC_INT_MODE_OPTION

  // Initialize interrupt controller
  status = IntcInitFunction(INTC_DEVICE_ID, &TMRInst, &BTNInst);
  if(status != XST_SUCCESS) return XST_FAILURE;

  XTmrCtr_Start(&TMRInst, 0);




  while(1);

  return 0;
}

//----------------------------------------------------
// INITIAL SETUP FUNCTIONS
//----------------------------------------------------

int InterruptSystemSetup(XScuGic *XScuGicInstancePtr)
{
t// Enable interrupt
tXGpio_InterruptEnable(&BTNInst, BTN_INT);
tXGpio_InterruptGlobalEnable(&BTNInst);

tXil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
ttt t t t t t (Xil_ExceptionHandler)XScuGic_InterruptHandler,
ttt t t t t t XScuGicInstancePtr);
tXil_ExceptionEnable();


treturn XST_SUCCESS;

}

int IntcInitFunction(u16 DeviceId, XTmrCtr *TmrInstancePtr, XGpio *GpioInstancePtr)
{
tXScuGic_Config *IntcConfig;
tint status;

t// Interrupt controller initialisation
tIntcConfig = XScuGic_LookupConfig(DeviceId);
tstatus = XScuGic_CfgInitialize(&INTCInst, IntcConfig, IntcConfig->CpuBaseAddress);
tif(status != XST_SUCCESS) return XST_FAILURE;

t// Call to interrupt setup
tstatus = InterruptSystemSetup(&INTCInst);
tif(status != XST_SUCCESS) return XST_FAILURE;
t
t// Connect GPIO interrupt to handler
tstatus = XScuGic_Connect(&INTCInst,
ttttt  t  t INTC_GPIO_INTERRUPT_ID,
ttttt  t  t (Xil_ExceptionHandler)BTN_Intr_Handler,
ttttt  t  t (void *)GpioInstancePtr);
tif(status != XST_SUCCESS) return XST_FAILURE;


t// Connect timer interrupt to handler
tstatus = XScuGic_Connect(&INTCInst,
ttttttt INTC_TMR_INTERRUPT_ID,
ttttttt (Xil_ExceptionHandler)TMR_Intr_Handler,
ttttttt (void *)TmrInstancePtr);
tif(status != XST_SUCCESS) return XST_FAILURE;

t// Enable GPIO interrupts interrupt
tXGpio_InterruptEnable(GpioInstancePtr, 1);
tXGpio_InterruptGlobalEnable(GpioInstancePtr);

t// Enable GPIO and timer interrupts in the controller
tXScuGic_Enable(&INTCInst, INTC_GPIO_INTERRUPT_ID);
t
tXScuGic_Enable(&INTCInst, INTC_TMR_INTERRUPT_ID);
t

treturn XST_SUCCESS;
}

  • Sign in to reply
  • Cancel
Parents
  • bhfletcher
    0 bhfletcher over 9 years ago

    Is it a requirement to use the AXI timer? Why not use the PS TTC PWM? See the forum post below with a similar question.

    https://forums.xilinx.com/t5/Zynq-All-Programmable-SoC/AXI-Timer-PWM/m-p/555636/highlight/true#M5109

     

    Bryan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to bhfletcher

    Hi,

    Thank you for the suggestion! This is an intermediate step towards having multiple independently controlled PWM outputs simultaneously. As I understand it the TTC would limit me to just one or two outputs and I'd eventually like to have 5-10.

    I was able to get a single PWM signal working a few days ago using the TTC, based off that post.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • bhfletcher
    0 bhfletcher over 9 years ago in reply to Former Member

    The PS has two TTCs, each of which has 3 outputs, for a total of six.

    Bryan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • bhfletcher
    0 bhfletcher over 9 years ago in reply to Former Member

    The PS has two TTCs, each of which has 3 outputs, for a total of six.

    Bryan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube