Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. `timescale 1ns / 1ps
  2.  
  3. module controller_decoder #(parameter channel = 0) (
  4. input rst, clk, sending_flag,
  5. input[7:0] in_byte,
  6. output reg [6:0] temp_out,
  7. output reg [13:0] pitch_bend);
  8.  
  9. initial pitch_bend = 0;
  10.  
  11. reg [1:0] state, next_state;
  12. reg [6:0] temp, next_pitch_bend;
  13. initial next_pitch_bend = 8192;
  14. initial temp = 7'b0111111;
  15. initial state = 0;
  16. initial next_state = 0;
  17. initial temp_out = 0;
  18. //pitch bend = next pitch bend
  19. //volume = next volume ;
  20. //reset for pitch bend is 8192
  21. //if reset = 1, assign pitch bend to 8192, if not 1, is sending flag high, is data byte? catonation of temp and in_byte
  22. //assigned to register next pitch bend
  23.  
  24. always@(posedge clk)
  25. begin
  26. state = next_state;
  27. if(sending_flag)
  28. begin
  29. pitch_bend = next_pitch_bend + temp;
  30. temp_out = temp;
  31. end
  32. end
  33.  
  34. always@(*)
  35. begin
  36. case(state)
  37. 2'b01:
  38. begin
  39. //Wait on MSB -- 7 non-zero bits from the first data byte
  40. //In each of these cases, you have to define the next pitch bend and next state based on the inputs.
  41. //condition ? value_if_true : value_if_false
  42. //push MSB to temp here
  43. //already assumes that this is a data byte
  44. //current_note <= send_to_mem || status == 8'h00 ? 8'h00 : (in_byte[7] == 1'b0 && det_data == 1'b0) ? in_byte : current_note;
  45. if(sending_flag)
  46. begin
  47. state = next_state;
  48. next_pitch_bend = temp ? in_byte[6:0] : pitch_bend;
  49. temp <= next_pitch_bend;
  50. end
  51. else state = 2'b10;
  52. end
  53. 2'b10:
  54. begin
  55. if(sending_flag)
  56. begin
  57. //Wait on LSB -- 7 non-zero bits from the second data byte
  58. //assign new pitch bend
  59. state = next_state;
  60. pitch_bend = next_pitch_bend ? in_byte[6:0] : pitch_bend;
  61. end
  62. end
  63. 2'b00:
  64. begin
  65. //Wait on status
  66. next_state <= rst ? 0 : sending_flag ? (in_byte == {4'b1110, channel[3:0]} ? 2'b01 : 0 ) : 0;
  67. next_pitch_bend <= rst ? 8192 : pitch_bend; //if rst = 1, next_pitch_bend = 8192
  68. end
  69. endcase
  70. end
  71.  
  72. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement