Using interrupts to read pulses

Discussion in 'Embedded Systems and Microcontrollers' started by Alasttt, Aug 30, 2015.

  1. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0
    Hi all,

    I am trying to use an interrupt to read a pulse. It is triggered to interrupt on change, this is fine however it will only work with 10101,if you have 11 or 00 it will skip it because there is no change. But i need this information to trigger.

    How can I implement this?

    Cheers
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,168
    It seems to me then you really don't want to trigger on pulse. (a edge translation)
    What do you really want to measure?
     
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,541
    2,369
    A little more info?
    Micro used?
    Type of input device etc?
    Some Picmicro's have an interrupt on input, you can also use dual external pin interrupt on input and chose one rising edge the other for falling edge of the same pulse.
    But to go from 11 requires a 0 inbetween??
    Max.
     
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,388
    497
    I don't think you understand a difference between square wave and pulse/pulse wave.

    Square Wave is a wave that made up of periods. Each period is divided into two segments, one segment is "high", one segment is "low".

    Pulse is only one segment, either "high" or "low".

    When you send 11, you sent two pulses, both pulses are "high", so the uC sees only one "long" pulse, not two short pulses that you, the user, are sending. Since uC sees one "long" pulse, it does not react when first pulse is replaced by second pulse.

    Same for 00. uC sees "long" "low" pulse. It does not see two "low" pulses.
     
  5. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0
    Hi,

    Well I have a sequence of 10010011 that I want to read in and then process.
    Polling didn't work so I decided to use the interrupt to detect when thers a one or zero.

    Any suggestions ? Cheers
     
  6. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0
    Hi,

    Yes that makes sense
    When I send 11 it detects one long pulse so it only registers as 1 not 11.
    How can I resolve this ?

    Many thanks
     
  7. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,541
    2,369
    Still no mention of Micro?
    You could use a stand alone Usart IC and use RS232 to input the data in an 8bit word to process it?
    Or even I2c.
    How is the sequence spaced now?
    I assume you are sending it serially of some kind?
    Max.
     
  8. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0

    I'm using atmega328, Input is coming from a pulse I'm generating by using high low commands in arduino.

    It's works on a change when you have 10 or 01, it doesn't work when u have 00 or 11 because there is no change. It is non return to zero so there is no 0 between 11

    Suggestions?.

    Thanks
     
  9. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,678
    2,732
    Assuming there is *always* a transition at the beginning of each code word, you could use the IOC to start the receiver. But then some other timing mechanism of the receiver must extract the individual bits -- entirely separate from the IOC.
     
  10. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,541
    2,369
    If you have binary serial data, which it appears you have , you have to distinguish between independent bits somehow, i.e. clocked each end.?
    Max.
     
  11. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0
    The micro is an atmega328

    I am using arduino to generate some pulses like below.

    digitalWrite(7,HIGH);
    delay(100);
    digitalwrite(7,LOW);
    delay(100);
    digitalwrite(7,HIGH);
    delay(200);
    digitalwrite(7,LOW);

    Hi what does ioc stand for
     
  12. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0
    The micro is an atmega328

    I am using arduino to generate some pulses like below for example.

    digitalWrite(7,HIGH);
    delay(100);
    digitalwrite(7,LOW);
    delay(100);
    digitalwrite(7,HIGH);
    delay(200);
    digitalwrite(7,LOW);

    This makes 10110 . I want to read this on the micro.
     
  13. Alasttt

    Thread Starter Member

    May 13, 2015
    68
    0
    The bits are distinguished between each other becuase I am taking each bit to be 50uS. So over 100uS I get two bits etc.
     
  14. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,678
    2,732
    Interrupt-on-Change
     
  15. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,168
    A simple way to build a synchronous detector using another pin/wire for the interrupt but it needs two wires instead of one. Set the data pin bit 1 or 0, wait a short time, toggle the interrupt pin bit to cause the reader/receiver interrupt routine to read the data pin state 1 or 0, repeat. You can generate self-clocking data using Manchester coding but that's maybe overkill for simple bit to bit capture if you don't need or want a constant stream of data.
     
  16. jayanthd

    Member

    Jul 4, 2015
    274
    29
    It is very easy to implement. You can use INT0 pin but the pulse width should be known. If you send 101 and 1 remains for 100ms and 0 remains for 100 ms and again 1 remains for 100 ms.

    You configure the AVR to detect say rising edge first then when rising edge is detected you start a timer of 100 ms and configure the AVR to detect falling edge. Then lets assume 0 comes then falling edge is detected and timer is stopped and the timer counter value is checked. It will have value 1 and so it means 100 ms then AVR is configured to detect rising edge and Timer is started. Lets say another 0 comes and then 1 comes. So, when rising edge is detected the timer is stopped and the counter will hold a value 2 because the timer had interrupted twice for 200 ms. so you know you had two successive 0's. Like this by toggling the edge detection an using timer you can detect the sequence of 0's and 1's. If you want I will write a code for you but I will use mikroC PRO AVR Compiler because that is the Compiler I use for programming. You can then load the .hex file from my code to Arduino using MegunoLink Pro software.

    A flag can be toggled when edge detection bit is toggled and the value of this flag and no. of 100 ms timer interrupts counter value will tell how many 1's and 0's (successive or not) you received.
     
    Last edited: Sep 8, 2015
Loading...