dianjikongzhi 发表于 2010-9-21 17:21

《FPGA关于PWM输出控制原码》

本帖最后由 dianjikongzhi 于 2010-9-25 21:03 编辑

整个流行点的《FPGA关于PWM输出控制原码》,正在学的或者想学的下载

zddj 发表于 2010-9-25 10:09

下来学习了,谢谢!

lbz0123 发表于 2010-9-26 09:56

谢谢分享 下载了

fgdzypf 发表于 2010-9-29 08:19

好东西要学习一下的

liuhaosunyi 发表于 2010-10-5 21:05

先收下了再说,谢谢啦~~~{:1_432:}

ediu 发表于 2010-12-20 15:40

谢谢分享,下来看看

jackbo 发表于 2010-12-25 23:44

正需要这个东西,谢谢,学习了。

ccjj 发表于 2011-1-11 20:30

好多代码都是DSP的,难得见到用FPGA做的,下来看看,谢了!

thmoasmary 发表于 2011-1-30 10:19

不错嘛。看看先

lbz0123 发表于 2011-1-30 13:05

楼主威武
楼主上错东西了
楼主这是ALTERA的MAX2系列CPLD做的PWM生成模组
楼主重发

blackbat 发表于 2011-2-22 12:13

谢谢楼主,顶

typhoon0723 发表于 2011-5-18 11:17

这个要收下,谢谢了

sibq80 发表于 2011-5-18 21:55

好东西呀。哈哈。正需要呀!!!!!

午后薄荷 发表于 2011-6-13 14:56

正在学习中,多谢楼主的资料

fgdzypf 发表于 2011-6-14 09:20

谢谢楼主提供的资料,学习了

riscmcu 发表于 2011-6-17 17:00

非常感谢分享

xuminjun 发表于 2012-2-25 15:58

非常感谢,我正好要学习电机了

sghwjp 发表于 2012-3-4 13:59

学习下。。。。。。。。谢谢

Mdriver 发表于 2016-3-9 22:09

真的还是假的啊,怎么。。。。。。

zgq800712 发表于 2016-4-6 19:50

AN501_Pulse_Width_Modulator_Altera_MAX_II_CPLD_Design_Example




/***********************************************************************************************
Pulse Width Modulation
December 2006
*********************************************************************************/

// Top Level module
module pwm_main (up, dn, pwm, pwm_inv, pwm1, pwm2, pwm3, pwm4);

input up, dn;                        // PWM control buttons

output pwm, pwm_inv, pwm1, pwm2, pwm3, pwm4; // Five sets of PWM and one set of its compliment

wire dc_w;
wire clk_w, oscena_w, dc_clk_w, pwm_clk_w, pwm1,pwm2,pwm3,pwm4,pwm_inv;

assign pwm1 = pwm;
assign pwm2 = pwm;
assign pwm3 = pwm;
assign pwm4 = pwm;
assign pwm_inv = !pwm;

assign oscena_w = 1;               //Enabling internal UFM oscillator


      altufm_osc0_altufm_osc_1p3 u1 (.osc(clk_w), .oscena(oscena_w));
                clk_gen u2 (.osc(clk_w), .duty_cycle_clk(dc_clk_w), .pwm_clk(pwm_clk_w));
      duty_cycle u3 (.up(up), .dn(dn), .duty_cycle(dc_w), .clk(dc_clk_w));
      pwm_gen u4 (.duty_cycle(dc_w), .clk(pwm_clk_w), .pwm(pwm));

endmodule

/****************************************************************************************************/
/*Instantiation of UFM oscillator for utilizing built in clock*/

`timescale 1 ps / 1 ps
//synopsys translate_on
modulealtufm_osc0_altufm_osc_1p3
    (
    osc,
    oscena) /* synthesis synthesis_clearbox=1 */;
    output   osc;
    input   oscena;

    wirewire_maxii_ufm_block1_osc;

    maxii_ufm   maxii_ufm_block1
    (
    .arclk(1'b0),
    .ardin(1'b0),
    .arshft(1'b0),
    .bgpbusy(),
    .busy(),
    .drclk(1'b0),
    .drdout(),
    .drshft(1'b0),
    .osc(wire_maxii_ufm_block1_osc),
    .oscena(oscena)
    `ifdef FORMAL_VERIFICATION
    `else
    // synopsys translate_off
    `endif
    ,
    .drdin(1'b0),
    .erase(1'b0),
    .program(1'b0)
    `ifdef FORMAL_VERIFICATION
    `else
    // synopsys translate_on
    `endif
    // synopsys translate_off
    ,
    .ctrl_bgpbusy(),
    .devclrn(),
    .devpor(),
    .sbdin(),
    .sbdout()
    // synopsys translate_on
    );
    defparam
      maxii_ufm_block1.address_width = 9,
      maxii_ufm_block1.osc_sim_setting = 300000,
      maxii_ufm_block1.lpm_type = "maxii_ufm";
    assign
      osc = wire_maxii_ufm_block1_osc;
endmodule //altufm_osc0_altufm_osc_1p3


/*********************************************************************************************
*Clk_gen module for generating reduced frequencies from UFM Osc
   and to make suitable for generating duty cycle data clock and
   PWM generating clock
**********************************************************************************************/
module clk_gen(osc, pwm_clk, duty_cycle_clk);

input osc;

output pwm_clk, duty_cycle_clk;

reg count;
initial count=19'b0000000000000000000;

reg duty_cycle_clk;
reg pwm_clk;

always @ (posedge osc)
    begin
      count <= count + 1;
      pwm_clk <= count;
      duty_cycle_clk <= count;   
    end
endmodule

/*********************************************************************************************
* Generates 4 bit duty cycle word, each count (6.25%) corresponding to
1 of 16 duty cycle percentages
*********************************************************************************************/
module duty_cycle (up, dn, clk, duty_cycle);

input up, dn, clk;

output duty_cycle;
initial duty_cycle=4'b0000;

reg duty_cycle;

always @(posedge clk)
    begin
      if (!up)begin
            if (duty_cycle!=4'b1111)                                    // upward limit
                duty_cycle <= duty_cycle +1;
      end else begin                                                               
            if (!dn)begin
                if (duty_cycle!=4'b0000)                                        // downward limit
                  duty_cycle <= duty_cycle -1;
            end
      end
    end      
   
endmodule

/*************************************************************************************************************
* PWM generating module, uses duty cycle value from duty_cycle module
*************************************************************************************************************/
module pwm_gen (clk, duty_cycle, pwm);

input clk;
input duty_cycle;

output pwm;

reg count;
reg pwm, pwm_temp;

initial
begin
count=4'b0000;
pwm=1'b0;
end

always @ (posedge clk)
begin
        count = count+1;
                if (count == duty_cycle) pwm = pwm_temp;
                else
                        begin
                        if (count < duty_cycle)
                                begin
                                        pwm = 1'b1;
                                        pwm_temp = pwm;
                                end
                        else if (count > duty_cycle)
                                begin
                                        pwm =1'b0;
                                        pwm_temp = pwm;
                                end
                        end
end

endmodule

/****************************** End **************************************************************************/
页: [1] 2
查看完整版本: 《FPGA关于PWM输出控制原码》