在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1205|回复: 0

[讨论] Veriloga 的功率计Power_meter,如何读输出功率是多少?

[复制链接]
发表于 2023-7-14 11:22:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 TOPEEP108 于 2023-7-14 11:23 编辑

如图,想知道输出的三个端口分别怎么读出数据?


                               
登录/注册后可看大图



附上Veriloga 代码





  1. `include "discipline.h"
  2. `include"constants.h"


  3. // $Date: 1997/08/28 05:53:32 $
  4. // $Revision: 1.1 $
  5. //
  6. //
  7. // Based on the OVI Verilog-A Language Reference Manual, version 1.0 1996
  8. //
  9. //

  10. `define PI          3.14159265358979323846264338327950288419716939937511
  11. `define ABSTOL_TIME 1e-12



  12. //--------------------
  13. // power_meter
  14. //
  15. // -  Power meter
  16. //
  17. // iin:                input for current passing through the meter [V,A]
  18. // vp_iout:        positive voltage sending terminal and output for current
  19. //              passing through the meter [V,A]
  20. // vn:                negative voltage sensing terminal [V,A]
  21. // pout:        measured impedance converted to a voltage [V]
  22. // va_out:        measured apparent power [W]
  23. // pf_out:        measured power factor []
  24. //
  25. // INSTANCE parameters
  26. //    tstart      = time to wait before starting measurement [s]
  27. //    bw          = bw of rms filters (a first order filter) [Hz]
  28. //    log_to_file = whether to log the results to a file; yes or no []
  29. //    filename    = The name of the file in which the results are logged []
  30. //
  31. // MODEL parameters
  32. //    {none}
  33. //
  34. // In order to measure the power being dissipated in a 2 port device,
  35. // this meter should be placed in the netlist so that the current flowing
  36. // into the device passes between 'iin' and 'vp_iout' first,
  37. // that 'vp_iout' is connected to the positive terminal of the device and
  38. // that 'vn' is connected to the negative terminal of the device.
  39. //
  40. // The measured power is the average over time of the product of the voltage
  41. // across and the current through the device. This average is calculated by
  42. // integrating the VI product and dividing by time and passing the result
  43. // through a first order filter with bandwidth 'bw'.
  44. //
  45. // The apparent power is calculated by finding the rms values of the current
  46. // and voltage first and filtering them with a first order filter of
  47. // bandwidth, 'bw'. The apparent power is the product of the voltage and
  48. // current rms values.
  49. //
  50. // The purpose of the filtering is to remove ripple.
  51. // It is recommended that the 'bw' be set to a low value in order to
  52. // produce accurate measurements and that at least 10 input ac cycles be
  53. // allowed before the power_meter is considered settled. Also allow time
  54. // for the filters to settle.
  55. //
  56. // This meter requires accurate integration so it is desirable that the
  57. // integration method is set to 'gear2only' in the netlist
  58. //

  59. nature P_Power
  60.         abstol = 1n;
  61.         huge = 100M;
  62.         units = "Watts";
  63.         access = Pow;
  64. endnature

  65. nature PowerFactor
  66.         abstol = 1m;
  67.         units = "{none}";
  68.         huge = 100M;
  69.         access = PF;
  70. endnature

  71. discipline power_current
  72.         potential P_Power;
  73.         flow Current;
  74. enddiscipline

  75. discipline power_factor_current
  76.         potential PowerFactor;
  77.         flow Current;
  78. enddiscipline
  79.        
  80. (* instrument_module *)
  81. module power_meter(iin,vp_iout,vn,pout, va_out, pf_out);
  82. electrical iin, vp_iout, vn;
  83. power_current pout;
  84. power_current va_out;
  85. power_factor_current pf_out;
  86. parameter real tstart = 0 from [0:inf);
  87. parameter real bw = 10 from (0:inf);
  88. parameter integer log_to_file = 0;

  89.    electrical v_ifilt1, v_ifilt2;
  90.    electrical v_vfilt1, v_vfilt2;
  91.    electrical v_pfilt1, v_pfilt2;
  92.    electrical vgnd;

  93.    svcvs  #(.poles({-2*`PI*bw,0}) ) irms_filter (v_ifilt2,vgnd,v_ifilt1,vgnd);
  94.    svcvs  #(.poles({-2*`PI*bw,0}) ) vrms_filter (v_vfilt2,vgnd,v_vfilt1,vgnd);
  95.    svcvs  #(.poles({-2*`PI*bw,0}) ) power_filter (v_pfilt2,vgnd,v_pfilt1,vgnd);

  96.    integer out_file;

  97.    real temp_var;

  98.    real vin_val;
  99.    real iin_val;

  100.    real v_vfilt1_val;
  101.    real v_ifilt1_val;
  102.    real v_pfilt1_val;

  103.    real irms;
  104.    real vrms;

  105.    real integ_vin_sqd; // Need to integrate squares of vin,iin because
  106.    real integ_iin_sqd; //  impedance measurement is based on rms values

  107.    real integ_iin_vin; // Need this to calculate real power

  108.    real pout_val;        // measured real power
  109.    real va_out_val;        // measured apparent power
  110.    real pf_out_val;    // measured power factor angle

  111.    real input_expr;


  112.    analog begin
  113.       @ ( initial_step ) begin
  114.          if (log_to_file) begin
  115.              out_file = $fopen( "%C:r.dat" );
  116.              $fstrobe(out_file,"# Generated by Spectre from module `%M'");
  117.          end
  118.       end

  119.       V(vgnd) <+ 0;

  120.       // so that device is not intrusive
  121.       V(iin,vp_iout) <+ 0;

  122.       vin_val = V(vp_iout,vn);
  123.       iin_val = I(iin,vp_iout);

  124.       // vrms calculation
  125.       //
  126.       if ($abstime > tstart)
  127.           input_expr = vin_val*vin_val;
  128.       else
  129.           input_expr = 0;
  130.       integ_vin_sqd  = idt(input_expr,0);

  131.       if ($abstime > tstart) begin
  132.          if (($abstime-tstart) > `ABSTOL_TIME) begin        // to avoid div by zero error
  133.             v_vfilt1_val = sqrt(integ_vin_sqd/($abstime-tstart));
  134.          end
  135.       end else begin
  136.           v_vfilt1_val = 0;
  137.       end

  138.       V(v_vfilt1) <+ v_vfilt1_val;
  139.       vrms = V(v_vfilt2);

  140.       // irms calculation
  141.       //
  142.       if ($abstime > tstart)
  143.            input_expr = iin_val*iin_val;
  144.       else
  145.            input_expr = 0.0;
  146.       integ_iin_sqd  = idt(input_expr,0 );
  147.       if ($abstime > tstart) begin

  148.          if (($abstime-tstart) > `ABSTOL_TIME) begin        // to avoid div by zero error
  149.             v_ifilt1_val = sqrt(integ_iin_sqd/($abstime-tstart));
  150.          end
  151.       end else begin
  152.           v_ifilt1_val = 0;
  153.       end

  154.       V(v_ifilt1) <+ v_ifilt1_val;
  155.       irms = V(v_ifilt2);

  156.       // apparent power calculation
  157.       va_out_val = irms*vrms;

  158.       // real power calculation
  159.       //
  160.       if ($abstime > tstart)
  161.             input_expr = iin_val*vin_val;
  162.       else
  163.             input_expr = 0;
  164.       integ_iin_vin  = idt(input_expr,0);
  165.       if ($abstime > tstart) begin

  166.          if (($abstime- tstart) > `ABSTOL_TIME) begin        // to avoid div by zero error
  167.             v_pfilt1_val = integ_iin_vin/($abstime-tstart);
  168.          end
  169.       end else begin
  170.           v_ifilt1_val = 0;
  171.       end

  172.       V(v_pfilt1) <+ v_pfilt1_val;
  173.       pout_val = V(v_pfilt2);


  174.       // pf_out_val calculation
  175.       //
  176.       if ( va_out_val > pout.potential.abstol )  begin
  177.          temp_var        = pout_val/va_out_val;
  178.          temp_var        = max(temp_var,-1);
  179.          temp_var        = min(temp_var,1);
  180.          pf_out_val = temp_var;
  181.       end else begin
  182.          pf_out_val = 0;
  183.       end

  184.       if (log_to_file) begin
  185.          $fstrobe(out_file, "%-.10g\t%-.10g\t%-.10g\t%-f",
  186.                              $abstime, pout_val, va_out_val, pf_out_val);
  187.       end

  188.       Pow(pout)    <+ pout_val;
  189.       Pow(va_out)  <+ va_out_val;
  190.       PF(pf_out) <+ pf_out_val;

  191.       @ ( final_step ) begin
  192.          if (log_to_file) $fclose(out_file);
  193.       end
  194.    end
  195. endmodule


复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-6 09:57 , Processed in 0.024965 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表