OpenCores
URL https://opencores.org/ocsvn/sqmusic/sqmusic/trunk

Subversion Repositories sqmusic

[/] [sqmusic/] [trunk/] [sqm/] [sqm_pwm.v] - Diff between revs 4 and 6

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 6
/*
/*
        SQmusic
        SQmusic
        logarithmic PWM controller to use with SQMUSIC
        logarithmic PWM controller to use with SQMUSIC
  Version 0.1, tested on simulation only with Capcom's 1942
  Version 0.1, tested on simulation only with Capcom's 1942
 
 
  (c) Jose Tejada Gomez, 11th May 2013
  (c) Jose Tejada Gomez, 11th May 2013
  You can use this file following the GNU GENERAL PUBLIC LICENSE version 3
  You can use this file following the GNU GENERAL PUBLIC LICENSE version 3
  Read the details of the license in:
  Read the details of the license in:
  http://www.gnu.org/licenses/gpl.txt
  http://www.gnu.org/licenses/gpl.txt
 
 
  Send comments to: jose.tejada@ieee.org
  Send comments to: jose.tejada@ieee.org
 
 
*/
*/
`timescale 1ns / 1ps
`timescale 1ns / 1ps
module SQM_PWM(
module SQM_PWM(
  input clk, // VHF clock (>33 MHz)
  input clk, // VHF clock (>33 MHz)
  input reset_n,
  input reset_n,
        input [3:0]A, input [3:0]B, input [3:0]C, // input channels
        input [3:0]A, input [3:0]B, input [3:0]C, // input channels
        output Y
        output Y
);
);
 
 
 
 
SQM_PWM_1 apwm( .clk(clk), .reset_n(reset_n), .din(A), .pwm(y_a) );
SQM_PWM_1 apwm( .clk(clk), .reset_n(reset_n), .din(A), .pwm(y_a) );
SQM_PWM_1 bpwm( .clk(clk), .reset_n(reset_n), .din(B), .pwm(y_b) );
SQM_PWM_1 bpwm( .clk(clk), .reset_n(reset_n), .din(B), .pwm(y_b) );
SQM_PWM_1 cpwm( .clk(clk), .reset_n(reset_n), .din(C), .pwm(y_c) );
SQM_PWM_1 cpwm( .clk(clk), .reset_n(reset_n), .din(C), .pwm(y_c) );
 
 
assign Y=y_a | y_b | y_c;
assign Y=y_a | y_b | y_c;
endmodule
endmodule
 
 
////////////////////////////////////////////////////
////////////////////////////////////////////////////
// 1 channel only
// 1 channel only
module SQM_PWM_1(
module SQM_PWM_1(
  input clk, // VHF clock (>33 MHz)
  input clk, // VHF clock (>33 MHz)
  input reset_n,
  input reset_n,
  input [3:0]din,
  input [3:0]din,
  output reg pwm
  output reg pwm
);
);
 
 
reg [7:0] count, last0, last1;
reg [7:0] count, last0, last1;
wire [7:0]rep0, rep1;
wire [7:0]rep0, rep1;
 
 
SQM_PWM_LOG dec( .din(din), .rep0(rep0), .rep1(rep1), .zero(zero) );
SQM_PWM_LOG dec( .din(din), .rep0(rep0), .rep1(rep1), .zero(zero) );
 
 
always @(posedge clk or negedge reset_n) begin
always @(posedge clk or negedge reset_n) begin
  if( !reset_n ) begin
  if( !reset_n ) begin
    count=0;
    count<=0;
    last0=0;
    last0<=0;
    last1=1;
    last1<=1;
  end
  end
  else
  else
    if( zero ) begin
    if( zero ) begin
      pwm=0;
      pwm  <=0;
      count=0;
      count<=0;
    end
    end
    else if( last0!=rep0 || last1!=rep1 ) begin
    else if( last0!=rep0 || last1!=rep1 ) begin
      last0 <= rep0;
      last0 <= rep0;
      last1 <= rep1;
      last1 <= rep1;
      count = 0;
      count <= 0;
      pwm=0;
      pwm   <=0;
    end
    end
    else if( last0==1 && last1==1 ) begin
    else if( last0==1 && last1==1 ) begin
      pwm=clk;
      pwm  <=clk;
      count=0;
      count<=0;
    end
    end
    else begin
    else begin
      if( pwm && count==last1-1 ) begin
      if( pwm && count==last1-1 ) begin
        count=0;
        count<=0;
        pwm=0;
        pwm  <=0;
      end
      end
      else if( !pwm && count==last0-1 ) begin
      else if( !pwm && count==last0-1 ) begin
        count=0;
        count<=0;
        pwm=1;
        pwm  <=1;
      end
      end
      else begin
      else begin
        count<=count+1;
        count<=count+1;
        pwm<=pwm;
        pwm  <=pwm;
      end
      end
    end
    end
end
end
endmodule
endmodule
 
 
module SQM_PWM_LOG(
module SQM_PWM_LOG(
        input [3:0]din,
        input [3:0]din,
        output reg [7:0] rep0, // "L" repetition
        output reg [7:0] rep0, // "L" repetition
        output reg [7:0] rep1, // "H" repetition
        output reg [7:0] rep1, // "H" repetition
        output zero
        output zero
);
);
 
 
assign zero = din==0;
assign zero = din==0;
 
 
always @(din)
always @(din)
        case (din)
        case (din)
                1: begin
                1: begin
                  rep0=64;
                  rep0=64;
                  rep1=1;
                  rep1=1;
                end
                end
                2: begin
                2: begin
                  rep0=61;
                  rep0=61;
                  rep1=1;
                  rep1=1;
                end
                end
                3: begin
                3: begin
                  rep0=32;
                  rep0=32;
                  rep1=1;
                  rep1=1;
                end
                end
                4: begin
                4: begin
                  rep0=61;
                  rep0=61;
                  rep1=2;
                  rep1=2;
                end
                end
                5: begin
                5: begin
                  rep0=16;
                  rep0=16;
                  rep1=1;
                  rep1=1;
                end
                end
                6: begin
                6: begin
                  rep0=61;
                  rep0=61;
                  rep1=4;
                  rep1=4;
                end
                end
                7: begin
                7: begin
                  rep0=8;
                  rep0=8;
                  rep1=1;
                  rep1=1;
                end
                end
                8: begin
                8: begin
                  rep0=61;
                  rep0=61;
                  rep1=8;
                  rep1=8;
                end
                end
                9: begin
                9: begin
                  rep0=61;
                  rep0=61;
                  rep1=16;
                  rep1=16;
                end
                end
         10: begin
         10: begin
                  rep0=61;
                  rep0=61;
                  rep1=8;
                  rep1=8;
                end
                end
         11: begin
         11: begin
                  rep0=2;
                  rep0=2;
                  rep1=1;
                  rep1=1;
                end
                end
         12: begin
         12: begin
                  rep0=61;
                  rep0=61;
                  rep1=32;
                  rep1=32;
                end
                end
         13: begin
         13: begin
                  rep0=1;
                  rep0=1;
                  rep1=1;
                  rep1=1;
                end
                end
         14: begin
         14: begin
                  rep0=61;
                  rep0=61;
                  rep1=64;
                  rep1=64;
                end
                end
         15: begin
         15: begin
                  rep0=1;
                  rep0=1;
                  rep1=1;
                  rep1=1;
                end
                end
default: begin
default: begin
                  rep0=1;
                  rep0=1;
                  rep1=1;
                  rep1=1;
                end
                end
        endcase
        endcase
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.