First, please post your code between code tags. Second, what is your clock speed 500 kHz? I myself cannot write Verilog, only read it with effort, but it seems your basic idea is ok.
http://www.cetpainfotech.com/technology/system-verilog-training
Feb 6, 2018