PaulStoffregen
Well-known member
I put in a pull request for it. Code is up on my fork and separate branch PulseIn-LC
https://github.com/PaulStoffregen/cores/pull/151
Thanks. I've merged your fix.
I put in a pull request for it. Code is up on my fork and separate branch PulseIn-LC
https://github.com/PaulStoffregen/cores/pull/151
uint8_t RC_Pins[] = {0, 1, 8, 3, 4, 5, 6, 7};
//uint8_t RC_Pins[] = {0, 1, 4, 6, 8, 3, 5, 7};
#define RC_PIN_COUNT sizeof(RC_Pins)
uint16_t pws[RC_PIN_COUNT];
uint32_t dts[RC_PIN_COUNT];
void setup() {
// put your setup code here, to run once:
for (uint8_t i = 0; i < sizeof(RC_Pins); i++)
pinMode(RC_Pins[i], INPUT);
uint32_t start_time = millis();
while (!Serial && ((millis() - start_time) < 5000)) ;
Serial.begin(115200);
}
void loop() {
// Get set of Pulse widths
uint32_t ts_loop = micros();
for (uint8_t i = 0; i < sizeof(RC_Pins); i++) {
uint32_t ts = micros();
pws[i] = pulseIn(RC_Pins[i], HIGH);
dts[i] = micros() - ts;
}
uint32_t dt_loop = micros() - ts_loop;
Serial.printf("%d : ", dt_loop);
uint32_t dt_sum = 0;
for (uint8_t i = 0; i < sizeof(RC_Pins); i++) {
Serial.printf("%d=%d(%d) ", RC_Pins[i], pws[i], dts[i]);
dt_sum += dts[i];
}
Serial.println(dt_sum);
}
58646 : 0=1477(9218) 1=1479(2774) 8=1290(18228) 3=1482(2966) 4=1292(2780) 5=1483(18415) 6=1482(2779) 7=1483(1484) 58644
58653 : 0=1476(9224) 1=1479(2775) 8=1291(18228) 3=1482(2964) 4=1292(2779) 5=1483(18416) 6=1482(2779) 7=1482(1484) 58649
58652 : 0=1476(9222) 1=1479(2774) 8=1290(18230) 3=1483(2965) 4=1292(2779) 5=1482(18416) 6=1483(2779) 7=1482(1484) 58649
58652 : 0=1476(9220) 1=1478(2773) 8=1291(18230) 3=1483(2966) 4=1293(2780) 5=1483(18414) 6=1484(2779) 7=1483(1485) 58647
38940 : 0=1477(9222) 1=1479(2774) 4=1292(4264) 6=1483(1485) 8=1290(12478) 3=1483(2966) 5=1483(1484) 7=1483(4264) 38937
38945 : 0=1477(9228) 1=1478(2773) 4=1292(4264) 6=1483(1485) 8=1290(12480) 3=1482(2965) 5=1484(1485) 7=1483(4264) 38944
38946 : 0=1477(9227) 1=1478(2773) 4=1292(4264) 6=1483(1485) 8=1290(12480) 3=1483(2967) 5=1483(1484) 7=1482(4263) 38943
38944 : 0=1476(9224) 1=1479(2774) 4=1291(4264) 6=1482(1485) 8=1291(12480) 3=1483(2965) 5=1483(1485) 7=1483(4263) 38940
38947 : 0=1476(9225) 1=1479(2774) 4=1291(4263) 6=1483(1484) 8=1290(12481) 3=1483(2966) 5=1482(1484) 7=1484(4264) 38941
38946 : 0=1476(9223) 1=1479(2774) 4=1291(4262) 6=1483(1484) 8=1291(12482) 3=1483(2966) 5=1483(1485) 7=1483(4265) 38941
I'm finding this pulseIn() to be very finicky?
I used the little sketch I had in post #22 to compare attachInterupt() with pulseIn() a while back, because on another project I had experienced a lot of jitter with pulseIn(). attachInterrupt() was better. For tiny width pulses, attachInterrupt() is limited by ISR overhead. As Paul noted, there is PPMout, and FreqCount/FreqMeasure*
digitalWriteFast(0, HIGH);
PulseIn(...)
digitalWriteFast(0, LOW);
Yes - that was what I was referring to earlier as the preferred method of timer capture input...Maybe you're thinking of PulsePosition? It's meant for reading a PPM stream, which is the encoding of many RC signals on a single pin. It's able to read several of those.
http://www.pjrc.com/teensy/td_libs_PulsePosition.html