Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import os
  2.  
  3. from myhdl import Cosimulation
  4. from myhdl import always_comb, toVHDL, Signal, intbv
  5.  
  6. cmd = 'vsim -c -quiet -pli myhdl_vpi.so -do cosim.do dut_bin2gray'
  7.  
  8. def bin2gray_rtl(B, G):
  9. """ Gray encoder.
  10. B -- input intbv signal, binary encoded
  11. G -- output intbv signal, gray encoded
  12. """
  13.  
  14. @always_comb
  15. def logic():
  16. ext_b = intbv(0)[len(B)+1:0]
  17. ext_b[:] = B
  18. for i in range(len(B)):
  19. G.next[i] = ext_b[i+1] ^ ext_b[i]
  20.  
  21. return logic
  22.  
  23. def bin2gray(B, G):
  24. toVHDL.name = "bin2gray"
  25. toVHDL(bin2gray_rtl, B, G)
  26.  
  27. os.system('vlib work')
  28. os.system('vcom -quiet -work work pck_myhdl_090.vhd')
  29. os.system('vcom -quiet -work work bin2gray.vhd')
  30. os.system('vlog -quiet -work work +define+width=%s dut_bin2gray.v' % (len(B)))
  31. print("All sources compiled")
  32.  
  33. return Cosimulation(cmd, B=B, G=G)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement