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!

Introduction to the Zynq Triple Timer Counter Part Three: Adam Taylor’s MicroZed Chronicles Part 19

by Xilinx Employee ‎02-10-2014 01:16 PM - edited ‎02-10-2014 01:20 PM (44,113 Views)

In my last blog, we looked implementing the Zynq SoC’s TTC (Triple Timer Counter) by defining the hardware within Vivado. In this blog post, we’ll use the SDK to drive the TTC. Obviously the first thing we need to do is export the hardware to SDK to ensure that the software environment has the most up-to-date definition.

 

Exporting hardware to the SDK is always the first thing to do. This step pulls in the required functions and macros provided by the operating system. These can be accessed by:

 

 

#include "xttcps.h"

 

 

We also need to include Xscugic.h and Xil_exception.h so that we can use the interrupt controller.

 

The next step, as always, is is to use the xparamters.h file to obtain the TTC device ID, TTC Interrupt ID and Interrupt controller device ID.

 

Unlike our previous example using the Zynq SoC’s private timer, we need to declare a data structure to contain the output frequency, interval, pre-scaler, and TTC options.

 

 

typedef struct {

      u32 OutputHz;     /* Output frequency */

      u16 Interval;     /* Interval value */

      u8 Prescaler;     /* Prescaler value */

      u16 Options;      /* Option settings */

} TmrCntrSetup;

 

 

This data structure makes driving the TTC very easy. I’ve also used this structure to define a pre-configured settings table:

 

 

static TmrCntrSetup SettingsTable[1] = {

      {10, 0, 0, 0},    /* Ticker timer counter initial setup, only output freq */

};

 

 

This settings table initially sets the output frequency to 10Hz while initializing everything else to zero.

After initialization and device configuration, we need to define the options mode for TTC operation. Helpfully defined within xttcps.h are all of the options for the timer control register. We can therefore configure the TTC by ORing the options together. For this example I will be running the timer in interval mode with the external wave disabled.

 

 

TimerSetup->Options |= (XTTCPS_OPTION_INTERVAL_MODE |

                                          XTTCPS_OPTION_WAVE_DISABLE);

 

XTtcPs_SetOptions(&Timer, TimerSetup->Options);

 

XTtcPs_CalcIntervalFromFreq(&Timer, TimerSetup->OutputHz,&(TimerSetup->Interval), &(TimerSetup->Prescaler));

 

XTtcPs_SetInterval(&Timer, TimerSetup->Interval);

XTtcPs_SetPrescaler(&Timer, TimerSetup->Prescaler);

 

 

Having defined the TTC options and set them into the control register, we can call a function to calculate and set the interval for the desired output frequency as defined within the timer set-up structure.

 

The next step in using the TTC is to connect it to the interrupt controller and enable interrupts. There are several interrupts to choose from for each TTC. I have enabled only the interval interrupt in this instance:

 

 

XTtcPs_EnableInterrupts(TtcPsInt, XTTCPS_IXR_INTERVAL_MASK);

 

 

The file xttcps_hw.h, which is called up by xttcps.h, includes definitions for all possible TTC interrupts allowing them to be enabled as desired using the above function. Having set up the interrupt, I then start the timer and connect the MicroZed to my laptop so that I can see a message printed out each time the interrupt occurrs.

 

Within the interrupt service routine, I have simply read back the interrupt status register to determine which interrupt occurred and then cleared it. Reading of the interrupt status register within the ISR is important because there are several different interrupts possible. In a more complex use of the TTC, we would want to ensure we take the correct action depending upon the interrupt.

 

From this basic example (see attached code) you can add in the use of the match registers or more complex functions. We’ll look at that next time.

 

 

 Console output for TTC Interrupts.jpg

 

 

 

Please see the previous entries in this MicroZed series by Adam Taylor:

 

Introduction to the Zynq Triple Timer Counter Part Two: Adam Taylor’s MicroZed Chronicles Part 18

 

Introduction to the Zynq Triple Timer Counter Part One: Adam Taylor’s MicroZed Chronicles Part 17

 

The Zynq SoC’s Private Watchdog: Adam Taylor’s MicroZed Chronicles Part 16

 

Implementing the Zynq SoC’s Private Timer: Adam Taylor’s MicroZed Chronicles Part 15

 

MicroZed Timers, Clocks and Watchdogs: Adam Taylor’s MicroZed Chronicles Part 14

 

More About MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 13

 

MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 12

 

Using the MicroZed Button for Input: Adam Taylor’s MicroZed Chronicles Part 11

 

Driving the Zynq SoC's GPIO: Adam Taylor’s MicroZed Chronicles Part 10

 

Meet the Zynq MIO: Adam Taylor’s MicroZed Chronicles Part 9

 

MicroZed XADC Software: Adam Taylor’s MicroZed Chronicles Part 8

 

Getting the XADC Running on the MicroZed: Adam Taylor’s MicroZed Chronicles Part 7

 

A Boot Loader for MicroZed. Adam Taylor’s MicroZed Chronicles, Part 6 

 

Figuring out the MicroZed Boot Loader – Adam Taylor’s MicroZed Chronicles, Part 5

 

Running your programs on the MicroZed – Adam Taylor’s MicroZed Chronicles, Part 4

 

Zynq and MicroZed say “Hello World”-- Adam Taylor’s MicroZed Chronicles, Part 3

 

Adam Taylor’s MicroZed Chronicles: Setting the SW Scene

 

Bringing up the Avnet MicroZed with Vivado

 

Comments
by Visitor 473srikanth
on ‎10-17-2016 10:23 PM

Hello sir,

 

Its a great guide.

 

How can we measure PWM width using TTC timers??

 

Thanking You....

by Observer taylo_ap
on ‎10-19-2016 10:13 AM

473sirkanth 

 

Please see my reply to your earlier question at 

 

https://forums.xilinx.com/t5/Xcell-Daily-Blog/Introduction-to-the-Zynq-Triple-Timer-Counter-Part-One-Adam/ba-p/407537

 

Along with reading the TRM it is not to difficult to acheive Smiley Happy 

 

Adam 

Labels
About the Author
  • Be sure to join the Xilinx LinkedIn group to get an update for every new Xcell Daily post! ******************** Steve Leibson is the Director of Strategic Marketing and Business Planning at Xilinx. He started as a system design engineer at HP in the early days of desktop computing, then switched to EDA at Cadnetix, and subsequently became a technical editor for EDN Magazine. He's served as Editor in Chief of EDN Magazine, Embedded Developers Journal, and Microprocessor Report. He has extensive experience in computing, microprocessors, microcontrollers, embedded systems design, design IP, EDA, and programmable logic.