sine wave (input, output) code segment

Status
Not open for further replies.

Chaoping

Newbie level 4
Joined
Apr 10, 2017
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,336
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:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…