_74hc4094.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. """
  2. # TOP2049 Open Source programming suite
  3. #
  4. # 74HC4094 unit-tester
  5. #
  6. # Copyright (c) 2011 Michael Buesch <m@bues.ch>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. """
  22. from .unitest import *
  23. class Chip_74hc4094(Chip_Unitest):
  24. def __init__(self):
  25. Chip_Unitest.__init__(self, chipPackage="DIP16",
  26. chipPinVCC=16,
  27. chipPinGND=8,
  28. VCCVoltage=5)
  29. def __initChip(self):
  30. self.zifPin_STR = self.generator.getZifPinForPackagePin(1)
  31. self.zifPin_D = self.generator.getZifPinForPackagePin(2)
  32. self.zifPin_CP = self.generator.getZifPinForPackagePin(3)
  33. self.zifPin_OE = self.generator.getZifPinForPackagePin(15)
  34. self.zifPin_QS1 = self.generator.getZifPinForPackagePin(9)
  35. self.zifPin_QS2 = self.generator.getZifPinForPackagePin(10)
  36. self.zifPins_QP = []
  37. for packagePin in (4, 5, 6, 7, 14, 13, 12, 11):
  38. self.zifPins_QP.append(
  39. self.generator.getZifPinForPackagePin(packagePin))
  40. self.reset()
  41. outen = 0
  42. for zifPin in (self.zifPin_STR, self.zifPin_D,
  43. self.zifPin_CP, self.zifPin_OE):
  44. outen |= (1 << (zifPin - 1))
  45. self.setOutputEnableMask(outen)
  46. self.applyGND(True)
  47. self.applyVCC(True)
  48. def test(self):
  49. testPatterns = (0xFF, 0x00, 0xAA, 0x55, 0xF0, 0x0F,
  50. 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  51. 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00)
  52. self.progressMeterInit("Logic test", len(testPatterns))
  53. self.__initChip()
  54. # Initialize the register to all-zero
  55. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=0, OE=0))
  56. for i in range(0, 9):
  57. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=1, OE=0))
  58. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=0, OE=0))
  59. self.setOutputs(self.__makeOutMask(STR=1, D=0, CP=0, OE=0))
  60. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=0, OE=1))
  61. QP = self.__readQP()
  62. if QP != 0x00:
  63. self.throwError("Failed to clear the shiftregister. Got 0x%02X" % QP)
  64. prevContents = 0x00
  65. prev_QS1 = False
  66. count = 0
  67. for testPattern in testPatterns:
  68. self.progressMeter(count)
  69. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=0, OE=0))
  70. for bitNr in range(7, -1, -1): # MSB first
  71. self.setOutputs(self.__makeOutMask(STR=0,
  72. D=(testPattern & (1 << bitNr)),
  73. CP=0, OE=0))
  74. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=1, OE=0))
  75. (QS1, QS2) = self.__readQS()
  76. word = (prevContents << 8) | testPattern
  77. expect_QS1 = bool(word & (1 << (bitNr + 7)))
  78. expect_QS2 = prev_QS1
  79. prev_QS1 = expect_QS1
  80. if QS1 != expect_QS1 or QS2 != expect_QS2:
  81. self.throwError("Got invalid QS serial output for "
  82. "test pattern 0x%02X bit %d. Got %d/%d, but "
  83. "expected %d/%d" %\
  84. (testPattern, bitNr, QS1, QS2,
  85. expect_QS1, expect_QS2))
  86. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=0, OE=0))
  87. self.setOutputs(self.__makeOutMask(STR=1, D=0, CP=0, OE=0))
  88. self.setOutputs(self.__makeOutMask(STR=0, D=0, CP=0, OE=1))
  89. QP = self.__readQP()
  90. if QP != testPattern:
  91. self.throwError("Failed on test pattern 0x%02X. Got 0x%02X" %\
  92. (testPattern, QP))
  93. prevContents = testPattern
  94. count += 1
  95. self.progressMeterFinish()
  96. def __makeOutMask(self, STR, D, CP, OE):
  97. mask = 0
  98. if STR:
  99. mask |= (1 << (self.zifPin_STR - 1))
  100. if D:
  101. mask |= (1 << (self.zifPin_D - 1))
  102. if CP:
  103. mask |= (1 << (self.zifPin_CP - 1))
  104. if OE:
  105. mask |= (1 << (self.zifPin_OE - 1))
  106. return mask
  107. def __readQP(self):
  108. QPValue = 0
  109. count = 0
  110. inputs = self.getInputs()
  111. for zifPin in self.zifPins_QP:
  112. if inputs & (1 << (zifPin - 1)):
  113. QPValue |= (1 << count)
  114. count += 1
  115. return QPValue
  116. def __readQS(self):
  117. QS1 = False
  118. QS2 = False
  119. inputs = self.getInputs()
  120. if inputs & (1 << (self.zifPin_QS1 - 1)):
  121. QS1 = True
  122. if inputs & (1 << (self.zifPin_QS2 - 1)):
  123. QS2 = True
  124. return (QS1, QS2)
  125. ChipDescription(
  126. Chip_74hc4094,
  127. chipID = "74hc4094dip16",
  128. bitfile = "unitest",
  129. runtimeID = (0x0008, 0x01),
  130. chipType = ChipDescription.TYPE_LOGIC,
  131. description = "74HC(T)4094 shift-register",
  132. chipVendors = ("Philips", "Other"),
  133. )