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

Resource

Link

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 # 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