Manchester decoding » History » Version 5

ABDALLAH, Hussein, 03/14/2016 10:35 PM

1 1 ABDALLAH, Hussein
h1. Manchester decoding
2 1 ABDALLAH, Hussein
3 1 ABDALLAH, Hussein
This part seems to be critical for a lot of workers in the Manchester code. To decode the signal we have several approaches with different benefices for each one.
4 1 ABDALLAH, Hussein
Some common steps are needed in all approaches;
5 1 ABDALLAH, Hussein
6 1 ABDALLAH, Hussein
•	We should Know or discover the data rate clock
7 1 ABDALLAH, Hussein
•	We should synchronize to the clock to separate a bit edge from a mid-bit transition
8 1 ABDALLAH, Hussein
•	Process the incoming stream and recover the data using the previous two steps
9 1 ABDALLAH, Hussein
•	Store this data for further processing
10 1 ABDALLAH, Hussein
11 1 ABDALLAH, Hussein
All these steps should be implemented in software taking into account that we have 2 options based on timing and sampling.
12 2 ABDALLAH, Hussein
13 2 ABDALLAH, Hussein
*Timing based Manchester code*
14 2 ABDALLAH, Hussein
15 2 ABDALLAH, Hussein
In this method, we detect the time between each transition coming from the demodulator circuit. To do this, we can use a micro-controller which contains an Input capture function. This function is used to deal with input signals in embedded systems (record time-stamp and set a flag indicating that an input has been captured). Moreover, it generates an interrupt, precise the time measurement and allow decision processing. To implement this method, we need the steps below;
16 2 ABDALLAH, Hussein
17 2 ABDALLAH, Hussein
1. Set up timer to interrupt on every edge
18 2 ABDALLAH, Hussein
2. Interrupt service routine ISR should flag the edge occurred and store count value 
19 2 ABDALLAH, Hussein
3. Start timer, capture first edge and discard this. 
20 2 ABDALLAH, Hussein
4. Capture next edge and check if stored count value equal 2T (T = ½ data rate) 
21 2 ABDALLAH, Hussein
5. Repeat step 4 until count value = 2T (This is now synchronized with the data clock) 
22 2 ABDALLAH, Hussein
6. Read current logic level of the incoming pin and save as current bit value (1 or 0) 
23 2 ABDALLAH, Hussein
7. Capture next edge 
24 2 ABDALLAH, Hussein
	a. Compare stored count value with T 
25 2 ABDALLAH, Hussein
	b. If value = T 
26 2 ABDALLAH, Hussein
		● Capture next edge and make sure this value also = T (else error) 
27 2 ABDALLAH, Hussein
		● Next bit = current bit 	
28 2 ABDALLAH, Hussein
		● Return next bit
29 2 ABDALLAH, Hussein
        c. Else
30 2 ABDALLAH, Hussein
		 if value = 2T 
31 2 ABDALLAH, Hussein
		● Next bit = opposite of current bit 
32 2 ABDALLAH, Hussein
		● Return next bit
33 2 ABDALLAH, Hussein
        d. Else 
34 2 ABDALLAH, Hussein
		● Return error 
35 2 ABDALLAH, Hussein
8. Store next bit in buffer 
36 2 ABDALLAH, Hussein
9. If the desired number of bits is decoded; exit to continue further processing 
37 2 ABDALLAH, Hussein
10. Else set current bit to next bit and loop to step 7
38 2 ABDALLAH, Hussein
It should also be noted that the timer’s value will not be exactly matched to T or 2T times.
39 3 ABDALLAH, Hussein
40 3 ABDALLAH, Hussein
!Timing_Manchester.jpg!
41 4 ABDALLAH, Hussein
42 4 ABDALLAH, Hussein
*Sampling based Manchester code*
43 4 ABDALLAH, Hussein
44 4 ABDALLAH, Hussein
In this method, we will sample and buffer the state at a certain rate (A), much higher than the message data rate. This needs more memory but allows less critical time to the processor to do intensive tasks.
45 4 ABDALLAH, Hussein
Sampling is made by defining  timer to interrupt and storing the state of the pin in a long buffer.
46 4 ABDALLAH, Hussein
47 4 ABDALLAH, Hussein
The software is implemented below
48 4 ABDALLAH, Hussein
49 4 ABDALLAH, Hussein
1. Set up timer to interrupt every 2T / S
50 4 ABDALLAH, Hussein
2. SR routine should check and store the state of the microcontroller pin (1 or 0) 
51 4 ABDALLAH, Hussein
3. Repeat step 2 for desired number of bits * S occurrences 
52 4 ABDALLAH, Hussein
4. Process through the captured buffer counting the number of consecutive ones or zeros 
53 4 ABDALLAH, Hussein
5. When the next logic value changes 
54 4 ABDALLAH, Hussein
	a. Check if count >= (S/2); Then skip to step 6 
55 4 ABDALLAH, Hussein
	b.Else reset count and loop to step 4 
56 4 ABDALLAH, Hussein
6. Set current bit = logic value in buffer currently pointed too 
57 4 ABDALLAH, Hussein
7. Reset count and count to the next logic change 
58 4 ABDALLAH, Hussein
	a. Compare count with (S/2) 
59 4 ABDALLAH, Hussein
	b. If count < (S/2) 
60 4 ABDALLAH, Hussein
		● Reset and count to next logic change 
61 4 ABDALLAH, Hussein
		● Make sure count also < (S/2) 
62 4 ABDALLAH, Hussein
		● Next bit = current bit 
63 4 ABDALLAH, Hussein
		● Store next bit in data buffer
64 4 ABDALLAH, Hussein
	 a. Else if count >= (S/2) 
65 4 ABDALLAH, Hussein
		● Next bit = opposite of current bit 
66 4 ABDALLAH, Hussein
		● Store next bit in data buffer 
67 4 ABDALLAH, Hussein
	a. Else 
68 4 ABDALLAH, Hussein
		● Return error 
69 4 ABDALLAH, Hussein
8. Loop to step 7 until completely through captured data 
70 4 ABDALLAH, Hussein
9. Exit for further data processing 
71 5 ABDALLAH, Hussein
72 5 ABDALLAH, Hussein
!Sampling_Manchester.png!