Chaoping
Newbie level 4
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 a moderator: