In SX Microcontrollers, SX/B Compiler and SX-Key Tool, mrchadwickusa wrote: In sync mode the purpose of the double flip flops is to prevent an input from exhibiting 'metastable' behavior. I'll try to explain as best as I can recall how that works. Let's assume a 'D' type flip flop, which is really a simple one bit memory of sorts. Whatever is on the 'D' (data?) input when the rising edge of the clock occurs, gets stored in the flip flop and then appears at the output 'Q'. A typical flip flop chip is the 7474 or 74(LS,HC,HCT etc.)374. The issue is that when you have a clocked flip flop, there is a period of time around the clock edge that the input has to be stable. This is spec'd as the setup and hold time. If the input changes during this window of time around the clock edge, the output can become indeterminate, for some period of time. It becomes 'meta-stable'. It eventually settles down to a high or a low, but it could be either. In the SX, if you are trying to read a port and you happen to catch it during a change, the same thing can happen, but to one of the internal registers of the SX and you don't necessarily get the result you expect. Other than an incorrect input, I'm not sure if other 'bad things' can happen because of that. What the sync option does, is put two flip flops in series between the input pin and the internal bus of the SX. The input pin to the D of the first and the Q of the first to the D of the second, then the SX bus gets the Q output of the second. They are both clocked by the processor clock. What that does for you is that if the first flip flop catches the input pin during a change, and goes metastable, it has one clock time to settle until the next clock hits the second flip flop and clocks the now stable output of the first flip flop through to the SX. It ensures that the second flip flop and the internal registers of the SX have their setup and hold times met. It also means that if you try to read an input immediately after you wrote it, you have to put more than the usual one 'NOP' between the write and read instructions. This is because with SYNC enabled, those two flip flops delay any change on the input pin by two SX clock cycles. So any change caused by a write to a port, isn't seen until at least two clock cycles later. For what it's worth, I've never found it necessary to use this feature. I've never had unexplained crashes of my SX code that I could attribute to the metastability issue. Off hand, I can't think of how exactly you might develop a test program to see if it can cause an error. Left as an exercise for the reader...? MRC ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=89693#m89978 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)