Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer: Chris Seto
  5. //
  6. // Create Date:    14:14:30 01/23/2011
  7. // Design Name:
  8. // Module Name:    PPM
  9. // Project Name:   PPM Decoder
  10. // Target Devices:
  11. // Tool versions:
  12. // Description: An I2C PPM decoder
  13. //
  14. // Dependencies: I2C Slave
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21. module PPM(
  22.   Clk,
  23.   SDA,
  24.   SCL,
  25.   PPMIN
  26. );
  27.  
  28. input Clk;
  29. inout SDA;
  30. input SCL;
  31. input PPMIN;
  32.  
  33. wire [7:0] I2C_Out;
  34. wire [7:0] I2C_In;
  35. wire [7:0] I2C_Addr;
  36. wire I2C_WEn;
  37. reg UsClk;
  38. reg [4:0] MclkDiv_Count;
  39. reg [15:0] Channel[7:0];
  40. reg [2:0] ChannelSelect = 0;
  41. reg LastPosition = 0;
  42. reg [15:0] CurrentCount = 0;
  43.    
  44. i2cSlave u_i2cSlave(
  45.   .clk(Clk),
  46.   .rst(0),
  47.   .sda(SDA),
  48.   .scl(SCL),
  49.   .Out(I2C_Out),
  50.   .In(I2C_In),
  51.   .Addr(I2C_Addr),
  52.   .WEn(I2C_WEn)
  53. );
  54.  
  55. //assign I2C_In = (I2C_Addr[0]==0)?Channel[I2C_Addr[7:1]][7:0]:Channel[I2C_Addr[7:1]][15:8];
  56.  
  57. if (I2C_Addr[0]==0) begin
  58.     assign I2C_In = Channel[I2C_Addr[7:1]][7:0];
  59. end
  60. else begin
  61.     assign I2C_In = Channel[I2C_Addr[7:1]][15:8];
  62. end
  63.  
  64. // 1us counter
  65. always @(posedge Clk) begin
  66.   if (MclkDiv_Count==25) begin
  67.     MclkDiv_Count <= 5'h00;
  68.      UsClk <= !UsClk;
  69.   end
  70.   else
  71.     MclkDiv_Count <= MclkDiv_Count+1;
  72. end
  73.  
  74. // Process the PPM signal
  75. always @(posedge UsClk) begin
  76.     LastPosition <= PPMIN;
  77.    
  78.     if ((PPMIN==1) & (LastPosition==0))
  79.     begin
  80.         if (CurrentCount > 2500) begin
  81.             CurrentCount = 0;
  82.             ChannelSelect = 0;
  83.         end
  84.         else begin
  85.             Channel[ChannelSelect] = CurrentCount;
  86.             CurrentCount = 0;
  87.             ChannelSelect = ChannelSelect + 1;
  88.         end
  89.     end
  90.     else begin
  91.         CurrentCount = CurrentCount + 1;
  92.     end
  93. end
  94.  
  95. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement