Paul Bulmer wrote: > > Hi scott your the only one to reply to my plea for help so far , the code > i am trying to decode it manchester encoded and the clock and data rate are > both the same i had thought of another way of doing it but how this would work > out in code is a bit beyond me at the moment but learning fast! What i could > do is time the length of the 1 and then 0 and have a routine that would output > valid data when the timeing of the 1 and 0's match ?? Also i thought it was > worth the mention i only have a 16c54 and 16c84 programmer at the moment but > Use John Morissons PIC ICE SYSTEM anyone else use it ?? > > Does anyone have any code examples of timeing a TTL input / ouput so i could > time the length of the 1 and 0 and output a de -manchesterised signal ??? > > What i'm doing to try and learn more is use the ICE system and on the output > of the Ice i use a scope to see the difference in 1 and 0 output against the > running code .... O.K., you want to decode Manchester encoded data. For everyone else's sake, Manchester encoding combines the clock and data of (typically) synchronous data into one serial data stream. The combination is simply an exclusive - NOR: machester data = NRZ data ^ (NRZ clock)' where NRZ data == Non-Return to Zero data. A fancy way of saying there is no encoding i.e. a logic 1 is +5 volts and a logic 0 is 0 volts. NRZ clock == A clock whose rising edge occurs in the middle of each NRZ data bit ^ == exclusive or operator ( )' == The boolean complement operator Here's an example comparing NRZ to Manchester: -+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ NRZ | | | | | | | | | | | | | | | | | clock +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +-- +-----+ +-----+ +-----------------+ NRZ | | | | | | data -+ +-----+ +-----------+ +--- 1 0 1 0 0 1 1 1 Manchester +-----+ +-----+ +--+ +--+ +--+ +--+ Encoded | | | | | | | | | | | | Data ----+ +-----+ +--+ +-----+ +--+ +--+ +-- To see this and other encoding schemes, check out: http://ftp.technion.ac.il/teach/topnet/cnpp94/udin_ronenh/main.html Now, back to your problem. You wish to "bit-bang" the serial data stream and decode the Manchester data. Typically, a bit-banging algorithm goes as follows. 1) Synchronize to the input data stream by hunting for an edge. For NRZ data, you would hunt for the falling edge of the start bit. For Manchester data, you will continuously have edges. This could be either good or bad (see below). 2) Wait for one half bit time. Presumably, the data is "cleanest" in the middle of a bit. 3) Wait for one whole bit time. 4) Sample the input data. Note that this sample will occur in the middle of a bit. 5) Decode the data bit, i.e. convert from Manchester to NRZ. 6) go to step 3. The "continuous edges" of Manchester-encoded data dilemmma/panacea depends on your computing resources. If you have to use the PIC16C54 with a 32kHz crystal, your capabilities are extremely limited. Instruction cycles are around 125 usec. However, you need at least two cycles to acquire one sample. Yet a moderate data rate of 9600 baud (NRZ) has a bit time of about 100 usec. I think you see the picture. On the other hand, if you can increase the frequency, then it is possible to continuously re-synchronize to the data. This will allow you to accurately sample the middle of the data bits, and perhaps saving you the burden of having to filter the data. I'm sure (almost that is) that this message will excite someone to post their "bit-banging" code, or at least point you to a Microchip ap-note. I would post mine, but I ain't got none (for the PIC that is). Hope this helps, Scott