Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. module Sampler (
  2. output reg interrupt, // a pulse has been detected
  3. output reg [7:0] result, // output data byte
  4. input clock, // sample clock
  5. input sample // incoming signal
  6. );
  7.  
  8. reg [6:0] counter; // monotonically increasing counter
  9. reg last_sample; // for sample edge detection
  10.  
  11. always @(posedge clock)
  12. begin
  13. if (counter == 0)
  14. begin
  15. // Rollover.
  16. result = 8'h80;
  17. interrupt = 1;
  18. counter = 1;
  19. end
  20. else if (sample && !last_sample)
  21. begin
  22. // A sample happened since the last clock.
  23. result[6:0] = counter;
  24. result[7] = 0;
  25. interrupt = 1;
  26. counter = 1;
  27. end
  28. else
  29. begin
  30. counter = counter + 1;
  31. interrupt = 0;
  32. end
  33. last_sample = sample;
  34. end
  35. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement