From 7ac753e94813e293bd8d47da78cc1cb5c5a0137c Mon Sep 17 00:00:00 2001
From: James Talbert <jtalbert@iastate.edu>
Date: Wed, 26 Sep 2018 17:34:54 -0500
Subject: [PATCH] Add a duty cycle sweep test The test has the user install a
 loopback jumper, then tests that the record/generate match at 1% intervals.
 The error currently holds at 18 cycles (probably a filter thing).

---
 .../Loopback_Error_Check/src/helloworld.c     | 105 ++++++++++++------
 1 file changed, 69 insertions(+), 36 deletions(-)

diff --git a/quad/vivado_workspace/PWM_Combined_Tests/PWM_Combined_Tests.sdk/Loopback_Error_Check/src/helloworld.c b/quad/vivado_workspace/PWM_Combined_Tests/PWM_Combined_Tests.sdk/Loopback_Error_Check/src/helloworld.c
index 3631c9a87..2d20f1a91 100644
--- a/quad/vivado_workspace/PWM_Combined_Tests/PWM_Combined_Tests.sdk/Loopback_Error_Check/src/helloworld.c
+++ b/quad/vivado_workspace/PWM_Combined_Tests/PWM_Combined_Tests.sdk/Loopback_Error_Check/src/helloworld.c
@@ -1,34 +1,34 @@
 /******************************************************************************
-*
-* Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy
-* of this software and associated documentation files (the "Software"), to deal
-* in the Software without restriction, including without limitation the rights
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-* copies of the Software, and to permit persons to whom the Software is
-* furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in
-* all copies or substantial portions of the Software.
-*
-* Use of the Software is limited solely to applications:
-* (a) running on a Xilinx device, or
-* (b) that interact with a Xilinx device through a bus or interconnect.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
-* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-* SOFTWARE.
-*
-* Except as contained in this notice, the name of the Xilinx shall not be used
-* in advertising or otherwise to promote the sale, use or other dealings in
-* this Software without prior written authorization from Xilinx.
-*
-******************************************************************************/
+ *
+ * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * Use of the Software is limited solely to applications:
+ * (a) running on a Xilinx device, or
+ * (b) that interact with a Xilinx device through a bus or interconnect.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the Xilinx shall not be used
+ * in advertising or otherwise to promote the sale, use or other dealings in
+ * this Software without prior written authorization from Xilinx.
+ *
+ ******************************************************************************/
 
 /*
  * helloworld.c: simple test application
@@ -48,14 +48,47 @@
 #include <stdio.h>
 #include "platform.h"
 #include "xil_printf.h"
+#include "xparameters.h"
+#include "xuartps.h"
+#include "sleep.h"
+
+int main() {
+	init_platform();
+
+	volatile uint32_t* buttonsGPIO =
+			(volatile uint32_t*) (XPAR_AXI_GPIO_2_BASEADDR);
+	volatile uint32_t* pwmRecord =
+			(volatile uint32_t*) (XPAR_PWM_RECORDER_0_S_AXI_BASEADDR);
+	volatile uint32_t* pwmGenerate =
+			(volatile uint32_t*) (XPAR_PWM_SIGNAL_OUT_0_S_AXI_BASEADDR);
 
+	print(
+			"Please connect JB0 and JB1 with an external jumper.\r\nWhen ready, press any button.\n\r");
+	while (buttonsGPIO[0] == 0)
+		;
+	print("Thank You :)\r\n");
 
-int main()
-{
-    init_platform();
+	pwmGenerate[0] = 50 * 1000;
+	pwmGenerate[1] = 25 * 1000;
 
-    print("Hello World\n\r");
+	int iteration;
+	const int num_iterations = 100;
+	for (iteration = 0; iteration < num_iterations; iteration++) {
+		pwmGenerate[1] = (iteration * pwmGenerate[0]) / num_iterations;
+		usleep(10000);
 
-    cleanup_platform();
-    return 0;
+		int error = pwmRecord[0] - pwmGenerate[1];
+		int abserror = error;
+		if (abserror < 0) {
+			abserror = -error;
+		}
+		xil_printf("%3d%% Duty Cycle: %c%3d.%08d%% error\r\n",
+				(100 * pwmGenerate[1]) / pwmGenerate[0],
+				(error < 0) ? '-' : ' ',
+				(100 * abserror) / ((int) pwmGenerate[0]),
+				((10000000000 * abserror) / ((int) pwmGenerate[0]))
+						% 100000000);
+	}
+	cleanup_platform();
+	return 0;
 }
-- 
GitLab