home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 180 / dpcs0203b.iso / editorial / easypc / Easy-Spice / data1.cab / Examples / Manchester / manchester.spi < prev   
Encoding:
Text File  |  2002-07-08  |  1.6 KB  |  61 lines

  1. .subckt $$pseudo_random CLOCK RAND_OUT
  2. A$U2 [U1_D13 U1_D14] U2_OUT HC86D
  3. A$U3 U2_OUT RAND_OUT HC04D
  4. A$U1 [CLOCK RAND_OUT] [U1_D0 U1_D1 U1_D2 U1_D3 U1_D4 U1_D5 U1_D6 U1_D7 U1_D8 U1_D9 U1_D10 U1_D11 U1_D12 U1_D13 U1_D14] $$ShiftU1 
  5. .model $$ShiftU1 d_logic_block file=$$shiftU1 user=[10n]
  6. .file $$shiftU1 
  7. PORT (DELAY=1e-12) output out[0:31] ; 
  8. EDGE (CLOCK=in[0], DELAY=USER[0]) shift ; 
  9. shift = shift<<1 | in[1] ; 
  10. output=shift ; 
  11. .endf 
  12.  
  13. .ends
  14.  
  15. .keep /subs
  16.  
  17. .model Manch_enc d_logic_block file = manchenc
  18. .file manchenc
  19. EDGE (clock=in[1], WIDTH=1) bit1 ;
  20. EDGE (clock=in[1], WIDTH=1) bit2 ;
  21. bit1 = !bit1 & !bit2  | bit1 & !bit2 & in[0] |  !bit1 & bit2 & in[0] ; 
  22. bit2 = in[0] ;
  23. out[0] = bit1 ;
  24. .endf
  25.  
  26. .model manchester_decoder d_logic_block file = manch_dec
  27.  
  28. .file manch_dec
  29. * Manchester decoder
  30.  
  31. PORT count_d     out[0:5];
  32. PORT st_d        out[6:9]; // state machine
  33.  
  34. PORT data        in[0];
  35.  
  36. EDGE (CLOCK=in[1], WIDTH=6) count;
  37. EDGE (CLOCK=in[1], WIDTH=1) shift0;
  38. EDGE (CLOCK=in[1], WIDTH=1) shift1;
  39. EDGE (CLOCK=in[2], WIDTH=4) state;
  40.  
  41. * state machine
  42. READONLY state_0[16] =  6  0  0  2 10  4 10  6 14  8  4 10  0 12  8 14;
  43. READONLY state_1[16] =  1  3  3  5  5  3  7  9  9  7 11 13 13 11 15  3;
  44.  
  45. shift0 = data;
  46. shift1 = shift0;
  47.  
  48. trig = shift0 ^ shift1;
  49.  
  50. hold = (count>=0 && count<=15 || count>=32 && count<=47) && trig;
  51. skip = (count>=16 && count<=31 || count>=48 && count<=63) && trig;
  52.  
  53. count = (hold ? count : skip ? count+2 : count+1);
  54. state = data ? state_1[state] : state_0[state];
  55.  
  56.  
  57. count_d = count;
  58. st_d = state ;
  59. .endf
  60.  
  61.