Pin Change Interrupt help plaese

Hi there.

I have a project. My code is working but a has function that slowing my code. Than I decided to do this function with interrupts.

SensorDataGirisPin=6;

  for (int i=0 ; i<18; i++){
    
     duration = pulseIn(SensorDataGirisPin, HIGH);

   if(duration<1100&& duration> 190  ) {sens[i]=B1;}
   else if(duration<110 ) {sens[i]  = B0;}
  
   
   }

This “pulseIn” function very slow. There is another issue my external interrupt pins is connected.

Can I detect pin high duration with Pin Change interrupt or can use pin 6 as interrupt pin.

I am so confused about this. I cant understand interrupts.

Thank you.

The pulse in function is long because it is not detecting anything but has to wait until it times out. You can look into changing the time out time for a faster response.

I suppose your idea is to have what ever is producing your pulse also generate an interrupt that captures the current time on the mills, or micros counter.

For this you need to use the pin change interrupt function set for an edge.

Can you provide more information about what is generating these edges and if you need the full cycle time or just the duration of a pulse high or pulse low period.

Also by not posting all your code we have no idea what B0 and B1 are. That logic at the end looks a bit odd with the sens array sometimes not getting any reading. Is it initialised only once or cleared in each 18 reading measurement cycle.

This is posted in the wrong section, it has nothing to do with the section definition.

Hi thank you for your answer

There is a parking sensor brain and it sending data as 18 bit per sensor every 30ms

whether the bits will be 0 or 1 determining with

data line HIGH duration.

Start bit (or sign) duration is 1ms high

Data bits for 1 is 0.200ms High
Data bits for 0 is 0.090ms High
After every bit there is a 0.090 ms LOW

There is a one start bit and 16 data bit and 1 end bit 0.200ms as like data bit 1

I need catch this sequence with interrupts. And write a array like “sens” in above code

I connect this Data line to arduino 6. Pin and need to activate this pin as interrupt and need to detect high state duration

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.