Spartan-7 SP701 Evaluation Kit PWM Tutorial

This page gives an overview of getting started with the SP701 Evaluation Kit.

Table of Contents

Introduction

Learn how to rapidly prototype an embedded system using the Spartan-7 FPGA SP701 evaluation kit. , This video demonstrates how to put together a MicroBlaze design and run "Hello World” using the Vivado Design Suite and Vitis Unified Software Platform, as well as a simple Pulse Width Modulation (PWM) application commonly used in controlling the speed of motors, the brightness of lights, and creating efficient power supplies.

Resources

Demonstration Steps

The demonstration video will cover two quick examples of how to build a system from scratch. The first is a Hello World example using MicroBlaze and the second is the PWM application example.

Expand the following section to view the source code for the PWM demo

# Copyright (c) 2021, Xilinx, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Include Header Files and Packages */ #include <stdio.h> #include "platform.h" #include "xil_printf.h" #include "xtmrctr.h" /* Device IDs Definition */ #define GpioLed XPAR_AXI_GPIO_0_DEVICE_ID #define TMRCTR_ID XPAR_TMRCTR_0_DEVICE_ID #define UARTBaseAddress XPAR_AXI_UARTLITE_0_BASEADDR /* System clock is 100 MHz (10ns) */ u32 PwmPeriod = 1000; /* Set PwmPeriod to 1000 ns */ u32 PwmHighTime; u8 DutyCycle; XTmrCtr TimerDriver; /* Instance of the Timer driver */ int main() { u32 Status; u8 DutyCyclePercentage; init_platform(); print("PWM Test Successfully Started\n\r"); /* Initializing the Timer where TimerDriver is a pointer to the XTmrCtr instance and TMRCTR_ID is the Device ID */ Status = XTmrCtr_Initialize(&TimerDriver,TMRCTR_ID); if (Status != XST_SUCCESS) { xil_printf("Timer Initialization Failed\r\n"); return XST_FAILURE; } while (1) { xil_printf ("Enter Duty Cycle in Bytes: \n\r"); /* UART-Lite Function used to capture the user input (Enter 1 for 10% DC, 2 for 20% DC, etc.)*/ DutyCycle = XUartLite_RecvByte(UARTBaseAddress); /* Since Key strokes are represented in decimal we want to know the corresponding pressed key hence convert Duty Cycle Decimal to ASCII */ DutyCyclePercentage = (DutyCycle - '0')*10; PwmHighTime = DutyCyclePercentage * 10; xil_printf("Duty Cycle is now: %d \n\r" , DutyCyclePercentage); /* Pwm Configuration */ XTmrCtr_PwmDisable(&TimerDriver); XTmrCtr_PwmConfigure(&TimerDriver, PwmPeriod, PwmHighTime); XTmrCtr_PwmEnable(&TimerDriver); } cleanup_platform(); return 0; }

Hello World with MicroBlaze

  • Open Example Project in Vivado

  • Target SP701 Evaluation Kit

  • Select MicroBlaze Design Preset

  • Synthesize and implement

  • Export to Vitis

  • Select Hello World Template

  • Power on the board and set UART communication

  • Download application

PWM Application Example

  • Update Application Code to Support PWM IP

    • Include header files packages

    • Retrieve Device IDs

    • Capture user input to control Duty Cycle

    • Update and configure PWM

  • Power on the board and set UART communication

  • Download application

  • Use Vivado ILA to monitor PWM signal

Related Links

Collateral

Tutorials and Guides

Workshops and Training

© Copyright 2019 - 2022 Xilinx Inc. Privacy Policy