2009/8/20 PicDude : > > > Richard Prosser wrote: >> >> 2009/8/18 PicDude : >>> >>> Oops, this should be 400 us (*micro*seconds) long each. >>> >>> >>> >>> PicDude wrote: >>>> >>>> ... over 70 sequential data bits which are around 400ms long each... >>>> >>> >>> -- >>> View this message in context: >>> http://www.nabble.com/Better-way-to-read-a-serial-data-stream--tp250186= 55p25018667.html >>> Sent from the PIC - [PIC] mailing list archive at Nabble.com. >>> >> >> >> Picdude. >> I think you need to organise a system in which the errors don't >> accumulate. I used =A0a method (many years ago) that maintained bit >> synch =A0that may be useful. Trouble is it's a bit hard to explain. >> >> Basically you sample twice per =A0period, once at the transition and >> once at the anticipated midpoint. If the midpoint reading agrees with >> the transition reading but the bit has changed from the previous bit >> (midpoint), then you assume that you have sampled late and your clock >> is a bit slow. Similarly, if the bit has changed, and so has the >> reading since the transition, then you figure your local clock is fast >> and adjust it slightly accordingly. Providing the adjustment is small, >> you can retain lock in quite noisy environments - we were using a >> radio link. >> >> It looks a bit complicated but actually coded into quite a compact >> block of assembler. ('6805 in the case in point) >> >> Richard P >> -- >> http://www.piclist.com PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist >> >> > > > Yes I do (need to keep the errors from accumulating), hence the part about > polling in a busy loop to wait until the end-of-bit transition. =A0But I = was > wondering if there's a better way, rather than looping idly within the > interrupt service routine. > > Let me clarify a few things, which I think will make a difference -- the > bits start and end with a L-->H transition. =A0The H-->L transition point > between the start and end points of each bit varies, so the duty-cycle > determines the bit value. =A0This is not NRZ. =A0Yes, bits are the same l= ength. > > I'm using RA1 on a 16F883 currently. > > With the sheme suggested you don't have to loop idly, you just set the interrupt to go off at twice the nominal bit frequency. Then adjust the frequency slightly according to your results. Since you're only talking about a 1% error, the adjustment only needs to be minor and latency variations won't have a significant overall effect. Richard P -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist