Like Tree2Likes
  • 1 Post By laserlight
  • 1 Post By AndiPersti

Simple Manchester decoder

This is a discussion on Simple Manchester decoder within the C Programming forums, part of the General Programming Boards category; Hi, First post so please be gentle . I am trying to write a very very simple manchester decoder type ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    5

    Simple Manchester decoder

    Hi,

    First post so please be gentle . I am trying to write a very very simple manchester decoder type thingy.

    I have a 16-bit string that i want to decode. I understand to do this properly there is the requirement for taking into account the clock etc. However, to start with all i want to do is actually decode a 16-bit sample.

    so basically i have a 16-bit binary string, and using the rule of (IEEE802.3) when encoded 1's become 10 and 0's become 01 because of the transition. so my bit string is:

    1001101001011001

    and i want the end result to be decoded from this.

    Does this make sense?

    Thanks

    Weez

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    Don't you just take pairs of digits, and look them up?
    1001101001011001
    decodes as 010
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    What you say makes sense. Just what precisely are you asking, though?

    If you're ignoring the clocking on a Manchester decoder, then you're going to totally ignore the point of Manchester decoding and make you do something that's totally unrelated to your answer. The whole point of Manchester decoding - the signal IS the clock as well, so you don't need to do anything special or limit yourself to fixed sizes, you just wait for data transitions, each one of which will give you a bit of data and a hint at how regular the clock signal is. Manchester decoding is about not having to know exactly how long something is expected to be in the 0 or 1 state for a single byte when you are polling it regularly - you watch for transitions and, no matter how irregular or fast they occur, you can receive the data they transmitted. I'd expect a program that claims to decode Manchester-encoded data will just sit and listen to the data coming in and wait for a bit-swap rather than trying to decode from static strings recorded at some point in the past and pre-sanitised.

    If you're going to decode a 16-bit string into (presumbly) an 8 bit string, then do so. But that doesn't seem related to Manchester-encoding at all, to be honest.

    I don't get what you're asking for, to be honest. Do it. And when you get stuck with the programming, ask us for help. Until then, you might as well just say "I'm going to write a program" in your post and have done with it.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  4. #4
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    I think basically you just wait for a transition up or down.
    I don't think you would normally do this in a program it would be more hardware attached to a transmission line.

    If you were in a program say maybe you just read one bit, see if it a 1 or zero, read the next bit, if it is a 1-0 transition out put a 1,
    if it is a 0-1 out put a 0. If there is no transition then out put what you previously output. If there is no transition stay as you were?

  5. #5
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Name:  CTR124-000-DIL.jpg
Views: 1597
Size:  6.1 KB

    Manchester decoding chip
    Last edited by esbo; 01-11-2013 at 10:51 PM.

  6. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    5
    Thanks for the replies. i shall look into the decoding chips when i get further along. I shall be attacking the actual recieving of data from an external source through GPIO a bit further along. for now i want to get the interpretation of the data written up, this takes place after the transmission is just a stream of 1's and 0's... I have a simple c program that ive quickly written up to hopefully demonstrate this step in my program... however i cannot get it toi work:

    Code:
    #include <stdio.h>
    
    
    
    
    
        int Data[] = {1,0,0,1};  //Data array
            
        int decode[] = {0,0};    //decoded data array
    
    
    
    
    
    
    
    
    int main()
    {
    
    
    /******************************************************************************
        Initialis/Print Data array
    ******************************************************************************/    
    
    
        int a=0;
    
    
        printf("\nBinary Sample is:\n");
    
    
        for(a=0; a<4; a++)
        {
            
            printf("%d", Data[a]);
        }    
        printf("\n");
    
    
    /*******************************************************************************
        Initialise/Print Decode array
    *******************************************************************************/
        
        int b=0;
    
    
        printf("\nDecoded data array set to 0:\n");
    
    
        for(b=0; b<2; b++)
        {
            printf("%d", decode[b]);
        }    
        printf("\n\n");
    
    
    
    
    /*******************************************************************************
        Test for bit patterns
    *******************************************************************************/
    
    
        int c;
        int d;
        a=0;    
        b=0;
    
    
        printf("Testing bit pattern.....\n");
    
    
        for(c=0;c<4;c++)
        {
            printf("\nProcessing instance bits %d & %d... \n",c++,c);        
            printf("\nData will be put into decode @ %d \n",b);
    
    
            if(Data[c] == 1 && Data[c++] == 0)
            {
            printf("\ntest 1 PASS\n");
            decode[b] = 0 ;
            printf("\nData bits %d & %d converted\n", c++,c);
            printf("\nConverted bit is %d \n",decode[b]);
            printf("\nNext TEST\n");    
            b+1;
    
    
            }
            else if(Data[c] == 0 && Data[c++] == 1)
            {
    
    
            printf("stage 2 PASS\n");
            decode[b] = 1;
            printf("\nData bits %d & %d converted\n", c,c++);
            printf("\nConverted bit is %d \n",decode[b]);
            b+1;
            printf("\nNext TEST\n");
            }
            else (printf("Error"));
            
        }
    
    
        printf("\nDecoded data is %d",decode[b]);
        
        for(b=0; b<2; b++)
        {
            
            printf("%d", decode[b]);
        }    
        printf("\n\n");
    
    
        return 0;
    }
    P.s sorry for the length of time between replies

    cheers

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2,575
    This line does nothing useful.

    Code:
    b+1;
    You likely wanted
    Code:
    b++;
    or

    Code:
    b=+1;
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by stahta01
    Code:
    b=+1;
    Heh, that is a typo, methinks. Perhaps:
    Code:
    b+=1;
    stahta01 likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by weez View Post
    however i cannot get it toi work:
    Rule #1: "It doesn't work" is not a useful problem description. Tell us what exactly went wrong (compiler errors, wrong output, ...)

    Rule #2: Always compile with warnings turned on. Then you should get something like:
    Code:
    $ make foo
    cc -Wall -Wextra -ggdb3   -c -o foo.o foo.c
    foo.c: In function ‘main’:
    foo.c:76:60: warning: operation on ‘c’ may be undefined [-Wsequence-point]
    foo.c:84:52: warning: operation on ‘c’ may be undefined [-Wsequence-point]
    foo.c:87:9: warning: statement with no effect [-Wunused-value]
    foo.c:97:54: warning: operation on ‘c’ may be undefined [-Wsequence-point]
    foo.c:99:9: warning: statement with no effect [-Wunused-value]
    foo.c:66:9: warning: unused variable ‘d’ [-Wunused-variable]
    cc   foo.o   -o foo
    Tim told you already about lines 87 and 99.

    Lines 76, 84 and 97 are about your usage of "c++".

    You can't use both "c++" and "c" as arguments in your printf()-calls because the order in which the arguments are evaluated isn't defined.
    If the compiler evaluates "c++" first, then printf() gets the values "c" and "c + 1".
    But if the compiler evaluates "c" first, then printf() gets the values "c" and "c".

    Generally, I think you have misunderstood how "c++" works and in which situations you can use it.

    Bye, Andreas
    Salem likes this.

  10. #10
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,376
    Manchester coding
    0 = Transaction from high to low in middle of interval
    1 = transaction from low to high in middle of interval

    Ok so...
    Eight bits of information translates to four bits of data
    If you see two lows in a row, the signal is changing from a 0 to 1
    If you see two highs in a row, the signal is changing from a 1 to 0

    Using strings is fine if you are trying to solve a problem in a text book, or practice drawing the signal - or even just trying to understand the protocol. However, as ledow said: The real trick with this is to detect the clock within the signal.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Decoder!
    By Balberry in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2012, 09:13 AM
  2. Help with a resistor decoder
    By usernameisvalid in forum C Programming
    Replies: 5
    Last Post: 06-25-2011, 05:21 PM
  3. decoder
    By jalenamichelle in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2010, 06:24 AM
  4. MPEG 4 decoder
    By abachler in forum Windows Programming
    Replies: 11
    Last Post: 05-10-2007, 11:32 PM
  5. MP3 Decoder
    By Pete in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 05-02-2005, 08:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21