Parcourir la source

#263 Pi5 changes

pull/270/head
mstroh76 il y a 2 mois
Parent
révision
7e1a168e12
3 fichiers modifiés avec 70 ajouts et 50 suppressions
  1. +6
    -3
      wiringPi/test/Makefile
  2. +59
    -45
      wiringPi/test/wiringpi_test8_pwm.c
  3. +5
    -2
      wiringPi/test/wiringpi_test9_pwm.c

+ 6
- 3
wiringPi/test/Makefile Voir le fichier

@@ -3,13 +3,13 @@ CFLAGS = -Wall
LDFLAGS =

# Need BCM19 <-> BCM26, +PWM: BCM12 <-> BCM13, BCM18 <-> BCM17 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 wiringpi_test9_pwm
tests = wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test7_version wiringpi_test8_pwm wiringpi_test9_pwm

# Need XO hardware
xotests = wiringpi_xotest_test1_spi wiringpi_i2c_test1_pcf8574 wiringpi_test9_pwm
xotests = wiringpi_xotest_test1_spi wiringpi_i2c_test1_pcf8574 wiringpi_test8_pwm wiringpi_test9_pwm

# Need PiFace hardware and BCM23 <-> BCM24 , BCM18 <-> BCM17 connected (1kOhm), and PiFace Out7<->In4, Out6<->In5, R0_NO<->In6, R0_NO<->In7, R_C<-100Ohm->GND
pifacetests = wiringpi_piface_test1 wiringpi_test9_pwm
pifacetests = wiringpi_piface_test1 wiringpi_test8_pwm wiringpi_test9_pwm

all: $(tests) $(xotests) $(pifacetests)

@@ -34,6 +34,9 @@ wiringpi_test6_isr:
wiringpi_test7_version:
${CC} ${CFLAGS} wiringpi_test7_version.c -o wiringpi_test7_version -lwiringPi

wiringpi_test8_pwm:
${CC} ${CFLAGS} wiringpi_test8_pwm.c -o wiringpi_test8_pwm -lwiringPi

wiringpi_test9_pwm:
${CC} ${CFLAGS} wiringpi_test9_pwm.c -o wiringpi_test9_pwm -lwiringPi



+ 59
- 45
wiringPi/test/wiringpi_test8_pwm.c Voir le fichier

@@ -19,7 +19,7 @@ void ISR_FREQIN(void) {
gCounter++;
}

double MeasureAndCheckFreq(const char* msg, double expect_freq) {
double MeasureAndCheckFreqTolerance(const char* msg, double expect_freq, int tolerance) {
double fFrequency;
clock_t CPUClockBegin, CPUClockEnd;
int CountBegin, CountEnd;
@@ -46,15 +46,18 @@ double MeasureAndCheckFreq(const char* msg, double expect_freq) {
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(msg, fFrequency, expect_freq, (expect_freq!=0.0) ? expect_freq*2/100:0.1); //2% tolerance
CheckSameDouble(msg, fFrequency, expect_freq, (expect_freq!=0.0) ? expect_freq*tolerance/100 : 0.1); //x% tolerance
return fFrequency;
}

double MeasureAndCheckFreq(const char* msg, double expect_freq) {
return MeasureAndCheckFreqTolerance(msg, expect_freq, 2);
}


int main (void) {

int major, minor;
// char msg[255];
int PWM, FREQIN;

wiringPiVersion(&major, &minor);
@@ -67,10 +70,6 @@ int main (void) {
int rev, mem, maker, overVolted, RaspberryPiModel;
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
CheckNotSame("Model: ", RaspberryPiModel, -1);
switch(RaspberryPiModel) {
case PI_MODEL_5:
return UnitTestState(); //not supported so far
}

PWM = 18;
FREQIN = 17;
@@ -84,83 +83,98 @@ int main (void) {
return UnitTestState();
}

printf("Set pwm 0%% and enable PWM output\n");
printf("\n==> Set pwm 0%% and enable PWM output with PWM_OUTPUT (default mode)\n");
pwmWrite(PWM, 0); // <-- Allways start with 0 Hz
pinMode(PWM, PWM_OUTPUT); //Mode BAL, pwmr=1024, pwmc=32
delay(250);
double duty_fact = 0.0;
double freq = 0.0;
MeasureAndCheckFreq("PMW BAL without change", freq);
MeasureAndCheckFreq("PMW Pi0-4:BAL/Pi5:MS without change", freq);

printf("Keep pwm 0%% and set mode MS\n");
pwmSetMode(PWM_MODE_MS);
delay(250);
MeasureAndCheckFreq("PWM MS without change", freq);

// Now Change values
pwmSetMode(PWM_MODE_BAL);
int pwmc = 1000;
int pwmr = 1024;
int pwm = 512;
pwmSetClock(pwmc);
pwmSetRange(pwmr);
pwmWrite(PWM, pwm);
delay(250);
duty_fact = (double)pwm/(double)pwmr;
printf("duty factor: %g\n", duty_fact);
freq = 19200.0/pwmc*duty_fact;
MeasureAndCheckFreq("PWM BAL with settings", freq);
int pwmc;
int pwmr;
int pwm;

if (RaspberryPiModel!=PI_MODEL_5) {
pwmSetMode(PWM_MODE_BAL);
pwmc = 1000;
pwmr = 1024;
pwm = 512;
duty_fact = (double)pwm/(double)pwmr;
printf("\n==> set mode BAL, pwmc=%d, pwmr=%d, pwm=%d, duty=%g%%\n", pwmc, pwmr, pwm, duty_fact*100);
pwmSetClock(pwmc);
pwmSetRange(pwmr);
pwmWrite(PWM, pwm);
delay(250);
freq = 19200.0/pwmc*duty_fact;
MeasureAndCheckFreq("PWM BAL with settings", freq);
}

pwmSetMode(PWM_MODE_MS);
pwmc = 10;
pwmr = 256;
pwm = 171;
duty_fact = (double)pwm/(double)pwmr;
printf("\n==> set mode MS, pwmc=%d, pwmr=%d, pwm%d, duty=%g%%\n", pwmc, pwmr, pwm, duty_fact*100);
pwmSetClock(pwmc);
pwmSetRange(pwmr);
pwmWrite(PWM, pwm);
delay(250);
duty_fact = (double)pwm/(double)pwmr;
printf("duty factor: %g\n", duty_fact);
delay(250);
freq = 19200.0/(double)pwmc/(double)pwmr;
MeasureAndCheckFreq("PWM BAL with settings", freq);

printf("set PWM@GPIO%d (output) off\n", PWM);
pinMode(PWM, PM_OFF);
delay(1000);
delay(1000);
MeasureAndCheckFreq("PMW off", 0.0);

printf("Set pwm settings and enable PWM\n");
pwmc = 800;
pwmr = 2048;
pwm = 768;
pwmSetRange(pwmr);
pwmSetClock(pwmc);
pwmWrite(PWM, pwm);
pinMode(PWM, PWM_BAL_OUTPUT);
delay(250);
duty_fact = (double)pwm/(double)pwmr;
printf("duty factor: %g\n", duty_fact);
freq = 19200.0/pwmc*duty_fact;
MeasureAndCheckFreq("PMW BAL start values", freq);
if (RaspberryPiModel!=PI_MODEL_5) {
pwmc = 800;
pwmr = 2048;
pwm = 768;
duty_fact = (double)pwm/(double)pwmr;
printf("\n==> set mode PWM_BAL_OUTPUT, pwmc=%d, pwmr=%d, pwm%d, duty=%g%%\n", pwmc, pwmr, pwm, duty_fact*100);
pwmSetRange(pwmr);
pwmSetClock(pwmc);
pwmWrite(PWM, pwm);
pinMode(PWM, PWM_BAL_OUTPUT);
delay(250);
freq = 19200.0/pwmc*duty_fact;
MeasureAndCheckFreq("PMW BAL start values", freq);
}

printf("set PWM@GPIO%d (output) off\n", PWM);
pinMode(PWM, PM_OFF);
delay(1000);
delay(1000);
MeasureAndCheckFreq("PMW off", 0.0);

printf("Set pwm settings and enable PWM\n");
pwmc = 5;
pwmr = 1024;
pwm = 768;
duty_fact = (double)pwm/(double)pwmr;
printf("\n==> set mode PWM_MS_OUTPUT, pwmc=%d, pwmr=%d, pwm%d, duty=%g%%\n", pwmc, pwmr, pwm, duty_fact*100);
pwmSetRange(pwmr);
pwmSetClock(pwmc);
pwmWrite(PWM, pwm);
pwmWrite(PWM, pwm);
pinMode(PWM, PWM_MS_OUTPUT);
delay(250);
duty_fact = (double)pwm/(double)pwmr;
printf("duty factor: %g\n", duty_fact);
delay(250);
freq = 19200.0/(double)pwmc/(double)pwmr;
MeasureAndCheckFreq("PMW MS start values", freq);

printf("set PWM@GPIO%d (output) off\n", PWM);
pinMode(PWM, PM_OFF);
delay(1000);
MeasureAndCheckFreq("PMW off", 0.0);

printf("set PWM0 CLK off @ Pi5\n");
pwmSetClock(0);

result = wiringPiISRStop(FREQIN);
CheckSame("\n\nRelease ISR", result, 0);
if (result < 0) {
@@ -169,4 +183,4 @@ int main (void) {
}

return UnitTestState();
}
}

+ 5
- 2
wiringPi/test/wiringpi_test9_pwm.c Voir le fichier

@@ -74,6 +74,7 @@ int main (void) {
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
CheckNotSame("Model: ", RaspberryPiModel, -1);
int Pi4 = 0;
int Pi5 = 0;
double MaxFreq = 100.0;
switch(RaspberryPiModel) {
case PI_MODEL_A:
@@ -106,7 +107,8 @@ int main (void) {
Pi4 = 1;
break;
case PI_MODEL_5:
return UnitTestState(); //not supported so far
Pi5 = 1;
break;
}

if (!piBoard40Pin()) {
@@ -144,7 +146,7 @@ int main (void) {
delay(500);
printf("Start:\n");
//MeasureAndCheckFreq("50\% Duty (default)", 300.000); //FAIL , freq (pwmc=32) to high for irq count
if(!Pi5) {
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)) {
@@ -174,6 +176,7 @@ int main (void) {
MeasureAndCheckFreq(msg, freq);
}
}
}

delay(250);
printf("\n");


Chargement…
Annuler
Enregistrer