#263 PiFace PWM unit test
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall
|
CFLAGS = -Wall
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
# Need BCM26 <-> BCM19 connected (1kOhm)
|
# Need BCM26 <-> BCM19 connected (1kOhm)
|
||||||
tests = wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test7_version
|
tests = wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test7_version
|
||||||
@@ -9,45 +9,53 @@ tests = wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiri
|
|||||||
xotests = wiringpi_xotest_test1_spi wiringpi_i2c_test1_pcf8574
|
xotests = wiringpi_xotest_test1_spi wiringpi_i2c_test1_pcf8574
|
||||||
|
|
||||||
# Need PiFace hardware and tests condition
|
# Need PiFace hardware and tests condition
|
||||||
pifacetests = wiringpi_piface_test1
|
pifacetests = wiringpi_piface_test1 wiringpi_test9_pwm
|
||||||
|
|
||||||
all: $(tests) $(xotests) $(pifacetests)
|
all: $(tests) $(xotests) $(pifacetests)
|
||||||
|
|
||||||
wiringpi_test1_sysfs:
|
wiringpi_test1_sysfs:
|
||||||
${CC} ${CFLAGS} wiringpi_test1_sysfs.c -o wiringpi_test1_sysfs -lwiringPi
|
${CC} ${CFLAGS} wiringpi_test1_sysfs.c -o wiringpi_test1_sysfs -lwiringPi
|
||||||
|
|
||||||
wiringpi_test2_sysfs:
|
wiringpi_test2_sysfs:
|
||||||
${CC} ${CFLAGS} wiringpi_test2_sysfs.c -o wiringpi_test2_sysfs -lwiringPi
|
${CC} ${CFLAGS} wiringpi_test2_sysfs.c -o wiringpi_test2_sysfs -lwiringPi
|
||||||
|
|
||||||
wiringpi_test3_device_wpi:
|
wiringpi_test3_device_wpi:
|
||||||
${CC} ${CFLAGS} wiringpi_test3_device_wpi.c -o wiringpi_test3_device_wpi -lwiringPi
|
${CC} ${CFLAGS} wiringpi_test3_device_wpi.c -o wiringpi_test3_device_wpi -lwiringPi
|
||||||
|
|
||||||
wiringpi_test4_device_phys:
|
wiringpi_test4_device_phys:
|
||||||
${CC} ${CFLAGS} wiringpi_test4_device_phys.c -o wiringpi_test4_device_phys -lwiringPi
|
${CC} ${CFLAGS} wiringpi_test4_device_phys.c -o wiringpi_test4_device_phys -lwiringPi
|
||||||
|
|
||||||
wiringpi_test5_default:
|
wiringpi_test5_default:
|
||||||
${CC} ${CFLAGS} wiringpi_test5_default.c -o wiringpi_test5_default -lwiringPi
|
${CC} ${CFLAGS} wiringpi_test5_default.c -o wiringpi_test5_default -lwiringPi
|
||||||
|
|
||||||
wiringpi_test6_isr:
|
wiringpi_test6_isr:
|
||||||
${CC} ${CFLAGS} wiringpi_test6_isr.c -o wiringpi_test6_isr -lwiringPi
|
${CC} ${CFLAGS} wiringpi_test6_isr.c -o wiringpi_test6_isr -lwiringPi
|
||||||
|
|
||||||
wiringpi_test7_version:
|
wiringpi_test7_version:
|
||||||
${CC} ${CFLAGS} wiringpi_test7_version.c -o wiringpi_test7_version -lwiringPi
|
${CC} ${CFLAGS} wiringpi_test7_version.c -o wiringpi_test7_version -lwiringPi
|
||||||
|
|
||||||
|
wiringpi_test9_pwm:
|
||||||
|
${CC} ${CFLAGS} wiringpi_test9_pwm.c -o wiringpi_test9_pwm -lwiringPi
|
||||||
|
|
||||||
|
wiringpi_piface_test1:
|
||||||
|
${CC} ${CFLAGS} wiringpi_piface_test1.c -o wiringpi_piface_test1 -lwiringPi -lwiringPiDev
|
||||||
|
|
||||||
wiringpi_xotest_test1_spi:
|
wiringpi_xotest_test1_spi:
|
||||||
${CC} ${CFLAGS} wiringpi_xotest_test1_spi.c -o wiringpi_xotest_test1_spi -lwiringPi
|
${CC} ${CFLAGS} wiringpi_xotest_test1_spi.c -o wiringpi_xotest_test1_spi -lwiringPi
|
||||||
|
|
||||||
wiringpi_i2c_test1_pcf8574:
|
wiringpi_i2c_test1_pcf8574:
|
||||||
${CC} ${CFLAGS} wiringpi_i2c_test1_pcf8574.c -o wiringpi_i2c_test1_pcf8574 -lwiringPi
|
${CC} ${CFLAGS} wiringpi_i2c_test1_pcf8574.c -o wiringpi_i2c_test1_pcf8574 -lwiringPi
|
||||||
|
|
||||||
wiringpi_piface_test1:
|
|
||||||
${CC} ${CFLAGS} wiringpi_piface_test1.c -o wiringpi_piface_test1 -lwiringPi -lwiringPiDev
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@error_state=false ; \
|
@error_state=false ; \
|
||||||
for t in $(tests) ; do \
|
for t in $(tests) ; do \
|
||||||
echo === unit test: $${t} === ; \
|
echo === unit test: $${t} === ; \
|
||||||
time ./$${t}; \
|
if [ $${t} = *"pwm" ]; then \
|
||||||
|
time sudo ./$${t} ; \
|
||||||
|
else \
|
||||||
|
time ./$${t} ; \
|
||||||
|
fi ; \
|
||||||
if [ $$? -ne 0 ]; then \
|
if [ $$? -ne 0 ]; then \
|
||||||
error_state=true ; \
|
error_state=true ; \
|
||||||
fi ; \
|
fi ; \
|
||||||
@@ -63,7 +71,11 @@ xotest:
|
|||||||
@error_state=false ; \
|
@error_state=false ; \
|
||||||
for t in $(tests) $(xotests) ; do \
|
for t in $(tests) $(xotests) ; do \
|
||||||
echo === XO unit test: $${t} === ; \
|
echo === XO unit test: $${t} === ; \
|
||||||
time ./$${t} ; \
|
if [ $${t} = *"pwm" ]; then \
|
||||||
|
time sudo ./$${t} ; \
|
||||||
|
else \
|
||||||
|
time ./$${t} ; \
|
||||||
|
fi ; \
|
||||||
if [ $$? -ne 0 ]; then \
|
if [ $$? -ne 0 ]; then \
|
||||||
error_state=true ; \
|
error_state=true ; \
|
||||||
fi ; \
|
fi ; \
|
||||||
@@ -79,7 +91,11 @@ pifacetest:
|
|||||||
@error_state=false ; \
|
@error_state=false ; \
|
||||||
for t in $(tests) $(pifacetests) ; do \
|
for t in $(tests) $(pifacetests) ; do \
|
||||||
echo === PiFace unit test: $${t} === ; \
|
echo === PiFace unit test: $${t} === ; \
|
||||||
time ./$${t} ; \
|
if [ $${t} = *"pwm" ]; then \
|
||||||
|
time sudo ./$${t} ; \
|
||||||
|
else \
|
||||||
|
time ./$${t} ; \
|
||||||
|
fi ; \
|
||||||
if [ $$? -ne 0 ]; then \
|
if [ $$? -ne 0 ]; then \
|
||||||
error_state=true ; \
|
error_state=true ; \
|
||||||
fi ; \
|
fi ; \
|
||||||
@@ -91,7 +107,7 @@ pifacetest:
|
|||||||
echo "\n\e[5mPIFACE TEST SUCCESS\e[0m\n"; \
|
echo "\n\e[5mPIFACE TEST SUCCESS\e[0m\n"; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
for t in $(tests) $(xotests) $(pifacetests) ; do \
|
for t in $(tests) $(xotests) $(pifacetests) ; do \
|
||||||
rm -fv $${t} ; \
|
rm -fv $${t} ; \
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -9,151 +9,216 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
int PWM0[2] = {18, 12};
|
||||||
|
int PWM0_IN[2] = {17, 13};
|
||||||
|
int PWM1[2] = {13, 19};
|
||||||
|
int PWM1_IN[2] = {12, 16};
|
||||||
|
*/
|
||||||
|
|
||||||
int PWM0 = 12;
|
int PWM_OUT[4] = { 18, 12, 13, 19 };
|
||||||
int FREQIN = 6;
|
int PWM_IN[4] = { 17, 13, 12, 16 };
|
||||||
|
|
||||||
volatile int gCounter = 0;
|
volatile int gCounter = 0;
|
||||||
|
|
||||||
//Interrupt Service Routine for FREQIN
|
//Interrupt Service Routine for FREQIN
|
||||||
void ISR_FREQIN(void) {
|
void ISR_FREQIN(void) {
|
||||||
gCounter++;
|
gCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
double MeasureAndCheckFreq(const char* msg, double expect_freq) {
|
double MeasureAndCheckFreq(const char* msg, double expect_freq) {
|
||||||
double fFrequency;
|
double fFrequency;
|
||||||
clock_t CPUClockBegin, CPUClockEnd;
|
clock_t CPUClockBegin, CPUClockEnd;
|
||||||
int CountBegin, CountEnd;
|
int CountBegin, CountEnd;
|
||||||
double CPUClockInterval, CountInterval;
|
double CPUClockInterval, CountInterval;
|
||||||
double elapsed_time, CPULoad;
|
double elapsed_time, CPULoad;
|
||||||
uint64_t tbegin, tend;
|
uint64_t tbegin, tend;
|
||||||
int SleepMs = 1200;
|
int SleepMs = 1200;
|
||||||
|
|
||||||
CPUClockBegin = clock();
|
CPUClockBegin = clock();
|
||||||
tbegin = piMicros64();
|
tbegin = piMicros64();
|
||||||
CountBegin = gCounter;
|
CountBegin = gCounter;
|
||||||
delay(SleepMs);
|
delay(SleepMs);
|
||||||
CountEnd = gCounter;
|
CountEnd = gCounter;
|
||||||
CPUClockEnd = clock();
|
CPUClockEnd = clock();
|
||||||
tend = piMicros64();
|
tend = piMicros64();
|
||||||
|
|
||||||
elapsed_time = (double)(tend-tbegin)/1.0e6;
|
elapsed_time = (double)(tend-tbegin)/1.0e6;
|
||||||
CountInterval = CountEnd - CountBegin;
|
CountInterval = CountEnd - CountBegin;
|
||||||
CPUClockInterval = CPUClockEnd - CPUClockBegin;
|
CPUClockInterval = CPUClockEnd - CPUClockBegin;
|
||||||
CPULoad = CPUClockInterval*100.0 / CLOCKS_PER_SEC / elapsed_time;
|
CPULoad = CPUClockInterval*100.0 / CLOCKS_PER_SEC / elapsed_time;
|
||||||
fFrequency = CountInterval / elapsed_time / 1000;
|
fFrequency = CountInterval / elapsed_time / 1000;
|
||||||
|
|
||||||
printf("Interval: time: %.6f sec (CPU: %3.1f %%), count: %g -> frequency: %.3f kHz\n",
|
printf("\nInterval: time: %.6f sec (CPU: %3.1f %%), count: %g -> frequency: %.3f kHz\n",
|
||||||
elapsed_time, CPULoad, CountInterval, fFrequency);
|
elapsed_time, CPULoad, CountInterval, fFrequency);
|
||||||
|
|
||||||
CheckSameDouble("Wait for freq. meas.", elapsed_time, SleepMs/1000.0, 0.1); //100ms tolerance. maybe problematic on high freq/cpu load
|
CheckSameDouble("Wait for freq. meas.", elapsed_time, SleepMs/1000.0, 0.1); //100ms tolerance. maybe problematic on high freq/cpu load
|
||||||
CheckSameDouble(msg, fFrequency, expect_freq, expect_freq*2/100); //2% tolerance
|
CheckSameDouble(msg, fFrequency, expect_freq, expect_freq*2/100); //2% toleranc
|
||||||
|
|
||||||
return fFrequency;
|
return fFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int tests_pwmc[7] = {1456, 1000, 512, 100, 2000, 3000, 4000};
|
int tests_pwmc[7] = {1456, 1000, 512, 100, 2000, 3000, 4000};
|
||||||
int tests_duty[7] = { 512, 768, 682, 922, 256, 341, 102};
|
int tests_duty[7] = { 512, 768, 682, 922, 256, 341, 102};
|
||||||
int tests_pwmr[10]= { 100, 512, 1024, 1456, 2000, 3000, 5000, 10000, 15000, 20000};
|
int tests_pwmr[12]= { 50, 100, 200, 512, 1024, 1456, 2000, 3000, 5000, 10000, 15000, 20000};
|
||||||
|
int tests_pwm[3] = { 50, 25, 75};
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
|
|
||||||
int major, minor;
|
int major, minor;
|
||||||
char msg[255];
|
char msg[255];
|
||||||
|
int testruns = 4;
|
||||||
|
int PWM, FREQIN;
|
||||||
|
|
||||||
wiringPiVersion(&major, &minor);
|
wiringPiVersion(&major, &minor);
|
||||||
|
|
||||||
printf("WiringPi GPIO test program 9 (using PWM@GPIO%d (output) and GPIO%d (input))\n", PWM0, FREQIN);
|
printf("WiringPi GPIO test program 9\n");
|
||||||
printf(" pwm0 irq time\n");
|
printf("PWM/ISR test (WiringPi %d.%d)\n", major, minor);
|
||||||
|
|
||||||
printf("\nPWM/ISR test (WiringPi %d.%d)\n", major, minor);
|
wiringPiSetupGpio() ;
|
||||||
|
|
||||||
wiringPiSetupGpio() ;
|
int rev, mem, maker, overVolted, RaspberryPiModel;
|
||||||
|
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
|
||||||
int rev, mem, maker, overVolted, RaspberryPiModel;
|
CheckNotSame("Model: ", RaspberryPiModel, -1);
|
||||||
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
|
int Pi4 = 0;
|
||||||
CheckNotSame("Model: ", RaspberryPiModel, -1);
|
double MaxFreq = 100.0;
|
||||||
|
switch(RaspberryPiModel) {
|
||||||
if (!piBoard40Pin()) {
|
case PI_MODEL_A:
|
||||||
PWM0 = 18;
|
case PI_MODEL_B:
|
||||||
FREQIN = 17;
|
case PI_MODEL_BP:
|
||||||
}
|
case PI_MODEL_AP:
|
||||||
// INT_EDGE_BOTH, INT_EDGE_FALLING, INT_EDGE_RISING only one ISR per input
|
case PI_MODEL_ZERO:
|
||||||
int result = wiringPiISR(FREQIN, INT_EDGE_RISING, &ISR_FREQIN);
|
case PI_MODEL_ZERO_W:
|
||||||
CheckSame("Register ISR", result, 0);
|
case PI_MODEL_CM:
|
||||||
if (result < 0) {
|
MaxFreq = 13.0; // 12.5 kHz -> ~40% CPU@800 MHz
|
||||||
printf("Unable to setup ISR for GPIO %d (%s)\n\n",
|
printf(" - Pi1/BCM2835 detected, will skip tests with frequency above %g kHz\n", MaxFreq);
|
||||||
FREQIN, strerror(errno));
|
break;
|
||||||
return UnitTestState();
|
case PI_MODEL_2:
|
||||||
}
|
MaxFreq = 20.0;
|
||||||
|
printf(" - Pi2/BCM2836 detected, will skip tests with frequency above %g kHz\n", MaxFreq);
|
||||||
int Pi4 = 0;
|
break;
|
||||||
switch(RaspberryPiModel) {
|
case PI_MODEL_3B:
|
||||||
case PI_MODEL_4B:
|
case PI_MODEL_CM3:
|
||||||
case PI_MODEL_400:
|
case PI_MODEL_3BP:
|
||||||
case PI_MODEL_CM4:
|
case PI_MODEL_3AP:
|
||||||
case PI_MODEL_CM4S:
|
case PI_MODEL_CM3P:
|
||||||
Pi4 = 1;
|
case PI_MODEL_ZERO_2W:
|
||||||
break;
|
MaxFreq = 50.0;
|
||||||
case PI_MODEL_5:
|
printf(" - Pi3/BCM2837 detected, will skip tests with frequency above %g kHz\n", MaxFreq);
|
||||||
return UnitTestState(); //not supported so far
|
break;
|
||||||
}
|
case PI_MODEL_4B:
|
||||||
|
case PI_MODEL_400:
|
||||||
printf("\nPWM0 BAL mode:\n");
|
case PI_MODEL_CM4:
|
||||||
printf("==============\n");
|
case PI_MODEL_CM4S:
|
||||||
|
Pi4 = 1;
|
||||||
pinMode(PWM0, PWM_OUTPUT); //pwmr=1024, pwmc=32
|
break;
|
||||||
const int pmw = 512;
|
case PI_MODEL_5:
|
||||||
int pmwr = 1024;
|
return UnitTestState(); //not supported so far
|
||||||
pwmWrite(PWM0, pmw); //50% Duty
|
|
||||||
//MeasureAndCheckFreq("50\% Duty (default)", 300.000); //FAIL , freq (pwmc=32) to high for irq count
|
|
||||||
|
|
||||||
for (int c_duty=0, c_duty_end = sizeof(tests_duty)/sizeof(tests_duty[0]); c_duty<c_duty_end; c_duty++) {
|
|
||||||
|
|
||||||
double tests_duty_corr;
|
|
||||||
if (tests_duty[c_duty]>(pmwr/2)) {
|
|
||||||
tests_duty_corr = pmwr-tests_duty[c_duty];
|
|
||||||
} else {
|
|
||||||
tests_duty_corr = tests_duty[c_duty];
|
|
||||||
}
|
|
||||||
|
|
||||||
double duty_fact = tests_duty_corr/(double)pmwr;
|
|
||||||
printf("\n%d/%d set duty %d/%d\n",c_duty+1, c_duty_end, tests_duty[c_duty], pmwr);
|
|
||||||
pwmWrite(PWM0, tests_duty[c_duty]);
|
|
||||||
|
|
||||||
for (int c_pwmc=0, end = sizeof(tests_pwmc)/sizeof(tests_pwmc[0]); c_pwmc<end; c_pwmc++) {
|
|
||||||
if (Pi4 && tests_pwmc[c_pwmc]>1456) {
|
|
||||||
printf("* Set Clock (pwmc) %d not possible on BCM2711 system (OSC 54 MHz), ignore\n", tests_pwmc[c_pwmc]);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
pwmSetClock(tests_pwmc[c_pwmc]);
|
|
||||||
delay(250);
|
if (!piBoard40Pin()) {
|
||||||
double freq = 19200.0/tests_pwmc[c_pwmc]*duty_fact;
|
testruns = 1; // only fist PWM0, supported
|
||||||
sprintf(msg, "Set Clock (pwmc) %d, %d%% duty", tests_pwmc[c_pwmc], tests_duty[c_duty]*100/pmwr);
|
|
||||||
MeasureAndCheckFreq(msg, freq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
for (int testrun=0; testrun<testruns; testrun++) {
|
||||||
|
PWM = PWM_OUT[testrun];
|
||||||
|
FREQIN = PWM_IN[testrun];
|
||||||
|
|
||||||
delay(250);
|
printf("using PWM@GPIO%d (output) and GPIO%d (input))\n", PWM, FREQIN);
|
||||||
pwmSetMode(PWM_MODE_MS) ;
|
|
||||||
printf("\nPWM0 MS mode:\n");
|
|
||||||
printf("==============\n");
|
|
||||||
|
|
||||||
int pwmc = 10;
|
|
||||||
pwmSetClock(pwmc);
|
|
||||||
delay(2500);
|
|
||||||
|
|
||||||
for (int c_pmwr=0, c_pmwr_end = sizeof(tests_pwmr)/sizeof(tests_pwmr[0]); c_pmwr<c_pmwr_end; c_pmwr++) {
|
|
||||||
pwmWrite(PWM0, tests_pwmr[c_pmwr]/2);
|
|
||||||
pwmSetRange(tests_pwmr[c_pmwr]) ;
|
|
||||||
delay(250);
|
|
||||||
double freq = 19200.0/(double)pwmc/(double)tests_pwmr[c_pmwr];
|
|
||||||
sprintf(msg, "Set range (pwmr) %d", tests_pwmr[c_pmwr]);
|
|
||||||
MeasureAndCheckFreq(msg, freq);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return UnitTestState();
|
// INT_EDGE_BOTH, INT_EDGE_FALLING, INT_EDGE_RISING only one ISR per input
|
||||||
|
int result = wiringPiISR(FREQIN, INT_EDGE_RISING, &ISR_FREQIN);
|
||||||
|
CheckSame("Register ISR", result, 0);
|
||||||
|
if (result < 0) {
|
||||||
|
printf("Unable to setup ISR for GPIO %d (%s)\n\n",
|
||||||
|
FREQIN, strerror(errno));
|
||||||
|
return UnitTestState();
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
printf("*********************************\n");
|
||||||
|
printf("* PWM BAL mode *\n");
|
||||||
|
printf("*********************************\n");
|
||||||
|
pinMode(PWM, PWM_OUTPUT); //pwmr=1024, pwmc=32
|
||||||
|
const int pmw = 512;
|
||||||
|
int pmwr = 1024;
|
||||||
|
pwmWrite(PWM, pmw); //50% Duty
|
||||||
|
//MeasureAndCheckFreq("50\% Duty (default)", 300.000); //FAIL , freq (pwmc=32) to high for irq count
|
||||||
|
|
||||||
|
for (int c_duty=0, c_duty_end = sizeof(tests_duty)/sizeof(tests_duty[0]); c_duty<c_duty_end; c_duty++) {
|
||||||
|
double tests_duty_corr;
|
||||||
|
if (tests_duty[c_duty]>(pmwr/2)) {
|
||||||
|
tests_duty_corr = pmwr-tests_duty[c_duty];
|
||||||
|
} else {
|
||||||
|
tests_duty_corr = tests_duty[c_duty];
|
||||||
|
}
|
||||||
|
|
||||||
|
double duty_fact = tests_duty_corr/(double)pmwr;
|
||||||
|
printf("\n%d/%d set duty %d/%d\n",c_duty+1, c_duty_end, tests_duty[c_duty], pmwr);
|
||||||
|
pwmWrite(PWM, tests_duty[c_duty]);
|
||||||
|
|
||||||
|
for (int c_pwmc=0, end = sizeof(tests_pwmc)/sizeof(tests_pwmc[0]); c_pwmc<end; c_pwmc++) {
|
||||||
|
int pwmc = tests_pwmc[c_pwmc];
|
||||||
|
if (Pi4 && pwmc>1456) {
|
||||||
|
printf("* Set clock (pwmc) %d not possible on BCM2711 system (OSC 54 MHz), ignore\n", pwmc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
double freq = 19200.0/pwmc*duty_fact;
|
||||||
|
if (freq>MaxFreq) {
|
||||||
|
printf("* Set clock (pwmc) %d not possible on system (to slow to measure %g kHz with ISR), ignore\n", pwmc, freq);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pwmSetClock(pwmc);
|
||||||
|
delay(250);
|
||||||
|
sprintf(msg, "Set Clock (pwmc) %d, %d%% duty", pwmc, tests_duty[c_duty]*100/pmwr);
|
||||||
|
MeasureAndCheckFreq(msg, freq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(250);
|
||||||
|
printf("\n");
|
||||||
|
printf("*********************************\n");
|
||||||
|
printf("* PWM MS mode *\n");
|
||||||
|
printf("*********************************\n");
|
||||||
|
pwmSetMode(PWM_MODE_MS) ;
|
||||||
|
|
||||||
|
int pwmc = 10;
|
||||||
|
pwmSetClock(pwmc);
|
||||||
|
delay(2500);
|
||||||
|
|
||||||
|
for (int c_pmwr=0, c_pmwr_end = sizeof(tests_pwmr)/sizeof(tests_pwmr[0]); c_pmwr<c_pmwr_end; c_pmwr++) {
|
||||||
|
int pwmr = tests_pwmr[c_pmwr];
|
||||||
|
double freq = 19200.0/(double)pwmc/(double)pwmr;
|
||||||
|
if (freq>MaxFreq) {
|
||||||
|
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<c_pmw_end; c_pmw++) {
|
||||||
|
int pwm = pwmr*tests_pwm[c_pmw]/100;
|
||||||
|
sprintf(msg, "Set pwm %d/%d (%d %%)", pwm, pwmr, tests_pwm[c_pmw]);
|
||||||
|
pwmWrite(PWM, pwm);
|
||||||
|
delay(250);
|
||||||
|
MeasureAndCheckFreq(msg, freq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
result = wiringPiISRStop(FREQIN);
|
||||||
|
CheckSame("\n\nRelease ISR", result, 0);
|
||||||
|
if (result < 0) {
|
||||||
|
printf("Unable to release ISR for GPIO %d (%s)\n\n",
|
||||||
|
FREQIN, strerror(errno));
|
||||||
|
return UnitTestState();
|
||||||
|
}
|
||||||
|
pinMode(PWM, INPUT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return UnitTestState();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user