Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Identify 01 in a set of 001001001

Status
Not open for further replies.

Neyolight

Full Member level 5
Joined
Aug 29, 2011
Messages
306
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
World
Activity points
3,624
Hi All

I have a very simple question that I "kind of" know the answer to. But I would like to see what you guys think.

I have a series of digital data for example 001110001100000111100. I want to count how many 0 to 1 transitions are present in the data. For the data set in the example, I should get 3.

The simples way to do this is to store current data if its 0 and check if the next data coming in is 1. This is the theory behind it but what is the fastest and most efficient way to implement it ?

Although I havent started implementing this yet but when I do I would be using a PIC micro.


Thanks
 
Last edited:

You could also use the External Interrupt or Interrupt-on-Change features and simply have the service routine increment a counter when the appropriate transition occurs on the I/O pin.

Use of a comparator would be another option.

There are several different ways of achieving the desired count, they all have their pros and cons.


BigDog
 
Hello!

I have never encountered this problem, but here is a method that could be somewhat faster than
doing it bit by bit.
- Make a table of 256 bytes with the transition numberers:
0 -> 0
1 -> 1
2 -> 2
3 -> 1
4 -> 2
5 -> 3
Etc...
Now you can process byte by byte instead of processing bit by bit.
You have to be careful in a series of bytes about the LSB of the left part and MSB of the right one.
If they are different, then you have one extra transition to add to the new byte.

Of cours, you should try it in oder to determine what you gain (how fast) and what you loose
(256 bytes of memory), but I would bet it's faster.

Dora.
 
It is not very clear where the data is coming from but if possible the interrupt on change like bigdogguru said would give the best result.
On the other hand if the data is transfered using a protocol like I2C or UART then this wouldn't be possible and you need to check the stored data.

So where is the data coming from?
 

I believe the use of an external interrupt or interrupt-on-change would be a possible solution for both asynchronous and synchronous serial data.

For example in the the case of I2C or SPI, the clock line could be used to trigger the interrupt, the state of the data line read in the ISR, combined with a counter variable and flag to store the previous state of the data line.


BigDog
 

The data is coming from a sensor that I have no control over. My part is to identify the transition. I haven't had a chance to look at the sensor yet as its not ready. If the sensor outputs the digital data directly to a comp port on my laptop then I guess I have to read the data from a txt file and would need to use something like C# to identify pattern.

- - - Updated - - -

On the other hand, if I can somehow connect a PIC to the sensor output , I can directly output the number of transition ( 0--1) on comp port .
 

Code:
input Pin  RB0
while(1)
{
while(!RB0);
while(RB0);
count++;  //  0  to 1 transition count
}
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top