+ Post New Thread
Results 1 to 1 of 1
  1. #1
    Newbie level 1
    Points: 62, Level: 1

    Join Date
    Apr 2017
    Posts
    1
    Helped
    0 / 0
    Points
    62
    Level
    1

    sine wave ( input, output) code segment

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    module vco(in, out) ; 
    `define  M_PI  3 
    parameter real amplitude = 1.0, centre_frequency = 1K, gain = 1K ; 
    parameter integer steps_per_cycle=20 ; 
    localparam real omegac = 2.0 * `M_PI * centre_frequency, omega_gain = 2.0 * `M_PI * gain ; 
     
    electrical in, out ; 
     
    analog begin : main 
     
    real vin, instantaneousFreq ; 
     
    vin = V(in) ; 
    V(out) <+ amplitude*sin(idt(vin*omega_gain+omegac,0.0)) ; 
     
    // Use $bound_step system task to limit time step 
    // This is to ensure that sine wave is rendered with 
    // adequate detail. 
    instantaneousFreq = centre_frequency + gain * vin ; 
    $bound_step (1.0 / instantaneousFreq / steps_per_cycle) ; 
    end 
    endmodule
    Last edited by BradtheRad; 10th April 2017 at 05:23. Reason: Added code formatted window

    •   Alt10th April 2017, 03:39

      advertising

        
       

--[[ ]]--