Using interrupts to read pulses

Thread Starter

Alasttt

Joined May 13, 2015
68
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
 

nsaspook

Joined Aug 27, 2009
16,322
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
It seems to me then you really don't want to trigger on pulse. (a edge translation)
What do you really want to measure?
 

MaxHeadRoom

Joined Jul 18, 2013
30,658
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.
 

shteii01

Joined Feb 19, 2010
4,644
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
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.
 

Thread Starter

Alasttt

Joined May 13, 2015
68
It seems to me then you really don't want to trigger on pulse. (a edge translation)
What do you really want to measure?
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
 

Thread Starter

Alasttt

Joined May 13, 2015
68
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.
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
 

MaxHeadRoom

Joined Jul 18, 2013
30,658
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.
 

Thread Starter

Alasttt

Joined May 13, 2015
68
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.

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
 

joeyd999

Joined Jun 6, 2011
6,279
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.
 

MaxHeadRoom

Joined Jul 18, 2013
30,658
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.
 

Thread Starter

Alasttt

Joined May 13, 2015
68
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.
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);

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.
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.
Hi what does ioc stand for
 

Thread Starter

Alasttt

Joined May 13, 2015
68
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.
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.
 

Thread Starter

Alasttt

Joined May 13, 2015
68
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.
The bits are distinguished between each other becuase I am taking each bit to be 50uS. So over 100uS I get two bits etc.
 

nsaspook

Joined Aug 27, 2009
16,322
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
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.
 

jayanthd

Joined Jul 4, 2015
945
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:
Top