From 4c6ef8701b8a42a1c01d8cc67266a41f5d2449e0 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Mon, 19 Aug 2024 13:29:55 +0200 Subject: [PATCH] #263 PWM test for all supported GPIOs --- wiringPi/test/wiringpi_test9_pwm.c | 113 ++++++++++++++---------------- wiringPi/test/wiringpi_xotest_test1_spi.c | 2 +- wiringPi/test/wpi_test.h | 7 +- 3 files changed, 60 insertions(+), 62 deletions(-) diff --git a/wiringPi/test/wiringpi_test9_pwm.c b/wiringPi/test/wiringpi_test9_pwm.c index fedc2ce..21f7911 100644 --- a/wiringPi/test/wiringpi_test9_pwm.c +++ b/wiringPi/test/wiringpi_test9_pwm.c @@ -9,15 +9,8 @@ #include #include -/* -int PWM0[2] = {18, 12}; -int PWM0_IN[2] = {17, 13}; -int PWM1[2] = {13, 19}; -int PWM1_IN[2] = {12, 16}; -*/ - int PWM_OUT[4] = { 18, 12, 13, 19 }; -int PWM_IN[4] = { 17, 13, 12, 16 }; +int PWM_IN[4] = { 17, 13, 12, 26 }; volatile int gCounter = 0; @@ -27,25 +20,25 @@ void ISR_FREQIN(void) { } double MeasureAndCheckFreq(const char* msg, double expect_freq) { - double fFrequency; - clock_t CPUClockBegin, CPUClockEnd; - int CountBegin, CountEnd; - double CPUClockInterval, CountInterval; - double elapsed_time, CPULoad; + double fFrequency; + clock_t CPUClockBegin, CPUClockEnd; + int CountBegin, CountEnd; + double CPUClockInterval, CountInterval; + double elapsed_time, CPULoad; uint64_t tbegin, tend; int SleepMs = 1200; CPUClockBegin = clock(); - tbegin = piMicros64(); + tbegin = piMicros64(); CountBegin = gCounter; delay(SleepMs); CountEnd = gCounter; CPUClockEnd = clock(); - tend = piMicros64(); + tend = piMicros64(); elapsed_time = (double)(tend-tbegin)/1.0e6; CountInterval = CountEnd - CountBegin; - CPUClockInterval = CPUClockEnd - CPUClockBegin; + CPUClockInterval = CPUClockEnd - CPUClockBegin; CPULoad = CPUClockInterval*100.0 / CLOCKS_PER_SEC / elapsed_time; fFrequency = CountInterval / elapsed_time / 1000; @@ -121,29 +114,35 @@ int main (void) { } for (int testrun=0; testrunMaxFreq) { - printf("* Set Clock (pwmc, pwmr) %d, %d not possible on system (to slow to measure %g kHz with ISR), ignore\n", pwmc, pwmr, freq); - continue; + printf("* Set Clock (pwmc, pwmr) %d, %d not possible on system (to slow to measure %g kHz with ISR), ignore\n", pwmc, pwmr, freq); + continue; } sprintf(msg, "Set range (pwmr) %d", pwmr); pwmSetRange(pwmr); for (int c_pmw=0, c_pmw_end = sizeof(tests_pwm)/sizeof(tests_pwm[0]); c_pmw %spassed%s \n", msg, value, expect, COLORGRN, COLORDEF); } else { printf("%35s (%.3f<>%.3f) -> %sfailed%s \n" , msg, value, expect, COLORRED, COLORDEF); @@ -104,6 +104,9 @@ void CheckSameFloat(const char* msg, float value, float expect) { } } +void CheckSameFloatX(const char* msg, float value, float expect) { + return CheckSameFloat(msg, value, expect, 0.08f); +} void CheckSameDouble(const char* msg, double value, double expect, double epsilon) { if (fabs(value-expect)