Skip to content
Snippets Groups Projects
Commit b0218782 authored by James Talbert's avatar James Talbert
Browse files

Add frequency scanning to PWM loop tests

parent 7ac753e9
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "xparameters.h" #include "xparameters.h"
#include "xuartps.h" #include "xuartps.h"
#include "sleep.h" #include "sleep.h"
#include "math.h"
int main() { int main() {
init_platform(); init_platform();
...@@ -61,33 +62,43 @@ int main() { ...@@ -61,33 +62,43 @@ int main() {
(volatile uint32_t*) (XPAR_PWM_RECORDER_0_S_AXI_BASEADDR); (volatile uint32_t*) (XPAR_PWM_RECORDER_0_S_AXI_BASEADDR);
volatile uint32_t* pwmGenerate = volatile uint32_t* pwmGenerate =
(volatile uint32_t*) (XPAR_PWM_SIGNAL_OUT_0_S_AXI_BASEADDR); (volatile uint32_t*) (XPAR_PWM_SIGNAL_OUT_0_S_AXI_BASEADDR);
while (1) {
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");
print( const int min_period = 1000;
"Please connect JB0 and JB1 with an external jumper.\r\nWhen ready, press any button.\n\r"); const int max_period = 5 * 1000 * 1000;
while (buttonsGPIO[0] == 0) const float period_step_factor = 1.5;
; int period;
print("Thank You :)\r\n"); for (period = min_period; period < max_period; period *=
period_step_factor) {
pwmGenerate[0] = 50 * 1000; pwmGenerate[1] = period / 2;
pwmGenerate[1] = 25 * 1000; pwmGenerate[0] = period;
int iteration; int duty_iteration;
const int num_iterations = 100; const int num_duty_iterations = 100;
for (iteration = 0; iteration < num_iterations; iteration++) { for (duty_iteration = 0; duty_iteration < num_duty_iterations;
pwmGenerate[1] = (iteration * pwmGenerate[0]) / num_iterations; duty_iteration++) {
usleep(10000); pwmGenerate[1] = ((duty_iteration + 1) * pwmGenerate[0])
/ (num_duty_iterations + 1);
int error = pwmRecord[0] - pwmGenerate[1]; usleep(period / 25);
int abserror = error;
if (abserror < 0) { int error = pwmRecord[0] - pwmGenerate[1];
abserror = -error; int abserror = (error < 0) ? -error : error;
if (abserror > pwmGenerate[0] / 1000) {
xil_printf("%5d Hz, %3d%% Duty Cycle: %d cycle error\r\n",
(50 * 1000 * 1000 / pwmGenerate[0]),
(100 * pwmGenerate[1]) / pwmGenerate[0], error);
}
}
usleep(period / 5);
} }
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(); cleanup_platform();
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment