A simple low speed BiPhase decoder
Untried but should get you started.
'************************************************* ***************
'* Name : BiPhase 01.BAS *
'* Author : Brian Taylor *
'* Notice : Copyright (c) 2008 Brian Taylor *
'* : All Rights Reserved *
'* Date : 29/01/2008 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
' an untried attempt at decoding the 2400 bps data stream used in the
' SMPTE LTC timecode system
'
'Defines go here
' Hardware definitions
LineIn var portB.0 'or whatever moves you
' Software definitions
A var byte
B var byte
C var byte
Msg var byte[8] ' up to 64 bits of timecode data
Valu var bit ' data bit from the biPhase data stream
Width var byte ' the number of 20 uSec chunks in the bit period
' 2400 bps is approx 416 uSecs per bit
' a ZERO should return a count of approx 20
' a ONE should yield a count of approx 10
Pattern var word ' this must match the SYNC pattern to start
'************************* Initialise block *************************
FlashLEDs: ' show em we are alive, etc
PickNose: ' etc
ScratchBum: ' etc
goto start 'jump subroutines at startup
'************************* Subroutines ****************************
FindBit:
' This extracts the 0 or 1 data bits from the incoming data stream
width = 0
FindEdge:
a = linein
pauseus 20
width = width + 1
if width > 14 then foundzero ' can't be a ONE - must be a ZERO.
' important that we exit early so we have approx 100 uSecs for
' other tasks before the next data transition. Allow for jitter
' and don't make the width comparison too tight
if linein = a then findedge
' sample a second time - repeat if no change
FoundOne:
'at this point we have a transition under 15 counts so must be a ONE.
valu = 1
goto findbitdone
FoundZero:
valu = 0
FindBitDone:
return
'***************************** MAIN ******************************
START:
FindSync:
' The values of the sync bits are fixed as 0011 1111 1111 1101
' Make a sliding window comparator by sliding the bits in the Pattern word
' up one place and adding the latest bit to the end and comparing this
' with the Sync word. NOTE the MSB/LSB might need swapping end for end.
gosub findbit
pattern = pattern << 1 + valu ' slide up one place and add latest bit
if pattern = %0011111111111101 then foundsync
goto findsync 'get one more bit & check again - keep doing it until a match
FoundSync:
GetData:
for b = 0 to 5 ' get 6 message bytes - bytes 6 & 7 are sync - so skip
for a = 0 to 7 ' get 8 bits in each message byte
gosub findbit
c.0[a] = valu ' fill the 8 bits in the byte
' MAY need a tweak to get MSB/LSB sense correct
next a
msg[b] = c
next b
' at this point you should have 6 bytes of message that needs
' to be broken down into the various data blocks per the
' SMPTE LTC specification
DoWhatever:
' unpack the nibbles you are interested in.
goto start
HTH
Brian