home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p078 / 7.img / TUTOR.PLB / CAPFIT.PLD < prev    next >
Encoding:
Text File  |  1991-02-18  |  6.5 KB  |  130 lines

  1.  
  2.                             CAPACITOR FITTING
  3.  
  4.     Here is an interesting example of an advanced application of the PLD
  5. hardware language.
  6.  
  7.     Consider a bank of six capacitors, each with its own capacitance
  8. rating, each of which can be enabled or disabled by an individual line of
  9. a six-bit signal.  If all six lines are inactive, none of the capacitors
  10. are enabled and the capacitance of the bank is zero.  On the other hand,
  11. if all six lines are active, all capacitors are enabled and the
  12. capacitance of the bank is maximal, equal to the sum of the capacitances
  13. of the individual parts.  If some lines are active and others are
  14. inactive, the capacitance of the bank is intermediate, equal to the sum of
  15. the capacitances of just the parts that are enabled.
  16.  
  17.     We want to enable the bank of capacitors in such a way that the total
  18. capacitance starts at an initial value and changes approximately
  19. quadratically with time.  A synchronous binary counter that steps through
  20. the values 0, 1, 2, ..., 15 in either direction is available externally.
  21. Such a configuration of capacitors is useful for linearity corrections in
  22. the sweep circuits of multi-synchronous monitors.
  23.  
  24.     The basic problem is to find the combinations of capacitors that most
  25. closely fit a specified quadratic capacitance curve at each point along
  26. the curve, then to create logic to enable that combination at the right
  27. step of the counter.  The values of the individual capacitors in the bank
  28. are chosen to be approximately proportional to the binary values of 1, 2,
  29. 4, 8, and so forth.  Unfortunately, capacitors are not available (readily)
  30. in precisely the desired values, so it is not a simple matter of feeding a
  31. binary number to the bank of capacitors and having it replicate the binary
  32. value represented.  Instead, for each point, it is necessary to choose
  33. from among all possible combinations of capacitors the one that best fits
  34. the desired value.
  35.  
  36.     Implementation is as follows:  The source code works like a computer
  37. program.  In an outer loop, variable k is set to each desired capacitance
  38. in nanofarads.  The sixteen values for k represent sixteen points along
  39. the quadratic curve.  These points could have been computed from quadratic
  40. coefficients in the source code, but the example is a little clearer and
  41. more versatile with the values given explicitly.  In an inner loop,
  42. variable i is set to each possible combination of bits from 000000 to
  43. 111111 binary (0 to 63 decimal).  The individual capacitance values appear
  44. in the equation for variable j, represented here in nanofarads so they
  45. will be integers.  For each combination i, the resulting capacitance of
  46. the entire bank is computed by multiplying the value of each capacitor by
  47. the value of the corresponding bit of i, then by summing up the results
  48. (i[5] represents the high order bit, i[0] represents the low).  If a bit
  49. in i is zero, then the product will be zero and the capacitor will not
  50. contribute to the sum.  If the difference between the total capacitance
  51. and the desired capacitance is less than the best thus far, the newly
  52. computed value is remembered for later use.  Finally, when all
  53. combinations have been examined, the combination that yields the best
  54. total capacitance is used to generate a product term for that step.
  55. Function "line" merely displays the step number, the total capacitance,
  56. and the deviation from the ideal value.  After that the next capacitance
  57. value for the next point on the curve is processed in the same way.
  58.  
  59.     When studying the source code, please refer to the following
  60. definitions for the variables used.  The first two are actual signal sets,
  61. the remainder are variables used only in computations.
  62.  
  63.     IN   Counter signals (input)
  64.     CAP  Capacitor control signals (output)
  65.     n    Step number (0, 1, 2, ..., 15)
  66.     k    Value desired for the bank of capacitors at step n
  67.     m    Value resulting in the best fit thus far
  68.     l    Output combination corresponding to m
  69.     j    Value of output combination being tested
  70.     i    Output combination corresponding to j
  71.  
  72.     This technique changes what would be a very laborious process into a
  73. simple joy.  Thanks to Fred Lehman for the idea underlying this
  74. application and for permission to use it as an example.
  75.  
  76.  
  77. |PAL16L8 in:IN[3..0], io:CAP[5..0]
  78. |
  79. | Active-low:  CAP[5..0]
  80. |
  81. | n = 0                                 |Clear the input step number.
  82. |
  83. | k = 19,                               |For the next input step, select
  84. |     38,                               |the capacitance value that is
  85. |     59,                               |desired from the bank of
  86. |     83,                               |capacitors.
  87. |    110,                               |
  88. |    141,                               | [Step 5]
  89. |    176,                               | [Step 6]
  90. |    216,                               | [Step 7]
  91. |    263,                               | [Step 8]
  92. |    319,                               | [Step 9]
  93. |    384,                               | [Step 10]
  94. |    462,                               | [Step 11]
  95. |    556,                               | [Step 12]
  96. |    670,                               | [Step 13]
  97. |    813,                               | [Step 14]
  98. |    992:                               | [Step 15]
  99. |
  100. | { m = 99999                           |Initialize the minimum deviation.
  101. |
  102. |   i = 000000b..111111b:               |For the next possible output
  103. |   { j = 680 * i[5]                    |value, compute the capacitance
  104. |       + 330 * i[4]                    |that would result by adding the
  105. |       + 150 * i[3]                    |value of each capacitor enabled.
  106. |       +  68 * i[2]
  107. |       +  47 * i[1]
  108. |       +  33 * i[0]
  109. |
  110. |     abs(j-k) < abs(m-k):              |If the newly computed capacitance
  111. |     { m = j                           |is closer to the desired value
  112. |       l = i                           |than the best thus far, switch
  113. |       }                               |attention to the new value.
  114. |     }
  115. |
  116. |   i=5..0:                             |Attach the product term for the
  117. |     CAP[i] = IN[3..0]==n & l[i]       |value that fits best.
  118. |
  119. |   i = line(n, m, m-k)                 |Display the results.
  120. |
  121. |   n = n+1                             |Advance to the next step and
  122. |   }                                   |repeat.
  123.  
  124.  
  125. | Vectors:
  126. | { Display (IN[3..0])d, CAP[5..0]
  127. |   Test     IN[3..0]
  128. |   End }
  129.  
  130.