File size: 1,752 Bytes
7df9186 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | `timescale 1ns / 1ns
`define AUTOMATIC_self
`define AUTOMATIC_decode
`define AUTOMATIC_noise_couple
`define AUTOMATIC_resonator
`define AUTOMATIC_prng
`include "cav_mech_auto.vh"
module cav_mech(
input clk,
input start_eig,
input start_outer,
output signed [17:0] mech_x,
output signed [17:0] noise_eig_drive,
input signed [17:0] eig_drive,
// Output status
output res_clip,
`AUTOMATIC_self
);
`undef AUTOMATIC_self
`AUTOMATIC_decode
parameter n_mech_modes = 7;
parameter n_cycles = n_mech_modes * 2;
// Couple randomness to mechanical drive
wire signed [17:0] environment; // filled in later
(* lb_automatic *)
outer_prod noise_couple // auto
(.clk(clk), .start(start_outer), .x(environment), .result(noise_eig_drive),
`AUTOMATIC_noise_couple
);
// Instantiate the mechanical resonance computer
(* lb_automatic *)
resonator resonator // auto
(.clk(clk), .start(start_eig),
.drive(eig_drive),
.position(mech_x), .clip(res_clip),
`AUTOMATIC_resonator
);
// Pseudorandom number subsystem
wire [31:0] rnda, rndb;
(* lb_automatic *)
prng prng // auto
(.clk(clk), .rnda(rnda), .rndb(rndb),
`AUTOMATIC_prng);
// Create a white noise term for environment
// This is a strangely-scaled CIC filter
// Each iteration adds a variance of 12, consuming 6 bits of PRNG
// Result has variance of n_cycles*12, mean of 0, possible peak n_cycles*7
// e.g. if n_cycles=14, std.dev.=12.96, peak=98, peak/rms=7.56
reg signed [11:0] noise_accum=0, noise_1=0, noise_out=0;
always @(posedge clk) begin
noise_accum <= noise_accum + rndb[2:0] - rndb[5:3];
if (start_eig) begin
noise_1 <= noise_accum;
noise_out <= noise_1-noise_accum;
end
end
assign environment = noise_out;
`undef AUTOMATIC_prng
endmodule // cav_mech
|