pulseIn not working on ATtiny84, but digitalRead does

I created a program to read radio control car throttle and auxiliary PWM signals on an UNO, then migrated to Nano and now trying to migrate to ATtiny84. I had some confusion on the ATtiny84 CW vs CCW numbering schemes, so wrote a program to help me confirm the CW pin designations using digitalWrite.

Now I am trying to confirm that I can use the pulseIn function on pin 5. There are two blocks of code that I comment out to demonstrate that digitalRead can control the LED, but pulseIn block never turns on the LED. I tried various values for the IF condition with no success. If I comment out the pulseIn line the output state is properly determined by the val5 declaration. The input comes from a signal generating putting out 3.3V and I verified that this code works with the same signal on my UNO.

I wrote this little program assuming the digitalRead and pulseIn use the same voltage thresholds to determine logic. If so then where else should I be investigating? Thanks in advance.

// v03:  trying PulseIn for PWM inputs.
// v02:  adding some inputs to test planned mapping of backfire light app; tested DigitalRead on pins 5 & 6
// v01:  maps all available 11 DX pins as outputs and sequences through flashing pin X with X flashes.  Works 20241208

// pin assignments updated to reflect 20241207 using "new" convention of CW pin mapping
int Pin5 = 8;
int Pin8 = 5;

int val5 = 0;
int val8 = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(Pin5, INPUT);
  pinMode(Pin8, OUTPUT);
}
void loop() {

val5 = pulseIn(Pin5, HIGH);
  if (val5 > 100) {
    digitalWrite(Pin8, HIGH);
  } else {
    digitalWrite(Pin8, LOW);
  }

  // val5 = digitalRead(Pin5);
  // if (val5) {
  //   digitalWrite(Pin8, HIGH);
  //  }
  //  else {
  //   digitalWrite(Pin8, LOW);
  //  }
}

This might help your code: " The length of the pulse (in microseconds) or 0 if no pulse started before the timeout. Data type:

unsigned long

.

#warning "This is the CLOCKWISE pin mapping - make sure you're using the pinout 
diagram with the pins in clockwise order"
// ATMEL ATTINY84 / ARDUINO
//
//                           +-\/-+
//                     VCC  1|    |14  GND
//            (D  10)  PB0  2|    |13  PA0  (D  0)        AREF
//             (D  9)  PB1  3|    |12  PA1  (D  1)
//             (D 11)  PB3  4|    |11  PA2  (D  2)
//  PWM  INT0  (D  8)  PB2  5|    |10  PA3  (D  3)
//  PWM        (D  7)  PA7  6|    |9   PA4  (D  4)
//  PWM        (D  6)  PA6  7|    |8   PA5  (D  5)        PWM

NB: // PWM (D 7) PA7 6|

int Pin5 = 8;
.
.
.
val5 = pulseIn(Pin5, HIGH);
...

Your schematic shows your pulse source hooked up to PA7, which is I/O 7; your sketch is reading from I/O 8, which is a different pin.

Try using the same pins in hardware and software. And seriously consider less confusing variable names too. Pin5 = 8? Pin 8=5? Gak!

Apologies, but the error was in the schematic, not the circuit as built, so here's the updated schematic. I put the code for digitalRead in the sketch to demonstrate I had the I/O correct so I knew that was not the issue. Regarding the "Pin5 = 8" business, I agree it's confusing, but I wanted to convey the physical pin and I could not find another way to designate D8 or PB2.

I tried making val5 unsigned long, but no success.

Am I correct in assuming the threshold levels should be the same for digitalRead and pulseIn?

Did you fix the pulseln problems?

Here's a snippet of code that reads PPM input and gives you the "microseconds" value, plus there's a couple of lines to give some smoothing or average that you can leave out.
The advantage is you dont need any extra libraries.

unsigned long PPM_in, Last_PPM_in, hightime, lowtime;
const unsigned long pulsein_timeout    = 21000;    // * microseconds * pulseIn is in microseconds, a complete PPM frame plus a bit

// loop
hightime = pulseIn(PPM_input_pin, HIGH, pulsein_timeout);
lowtime  = pulseIn(PPM_input_pin, LOW, pulsein_timeout);
PPM_in   = hightime + lowtime + 10;
PPM_in = (PPM_in + Last_PPM_in) / 2;    // average using last recorded value
Last_PPM_in = PPM_in;

I changed the val5 variable from "int" to "unsigned long", with no change. Then I tried using pulseInLong and it worked! I then changed val5 back to "int" and it worked, also. I changed back to pulseIn and it did not work again, just to verify I didn't change something else inadvertently. I also demonstrated that the value returned by pulseIn is in microseconds so it looks like I am back on track.

I am curious why pulseIn worked in my Uno and Nano sketches, but I need pulseInLong for the same 1000-2000 us pulses on the ATtiny84. I need to press on with the rest of the project so do not intend to lose any sleep over it.

Thanks so much for the help!

The long is 32 bits and the int is 16. Perhaps the int only got the top half of the 32 bit return, which would be zeros. Yes, you proved the documentation is correct!