module vco ( vin, clk100m, fout ) ;
// You will probably want to flush out the nature of these port declarations:
input real vin;
input reg clk100m;
output reg fout;
// Implement the module here
reg[21:0] freq; // out freq
reg[15:0] freqcnt;
reg[21:0] cntr100m; // clk10m counter
However, a VCO in general is designed to take a control voltage as input and produce a square or sine wave with a frequency controlled by that input voltage. From what you have shown above, with a clk100m input resulting in a pulse at 100kHz, are you truly seeking a VCO?
From what you have shown above, with a clk100m input resulting in a pulse at 100kHz, are you truly seeking a VCO?
I seeking a VCO.
I don’t use clk100m as a control voltage.In my circuit, control voltage is vin.
As below code. assign freq = 291(vin-3.3)+3840000;* assign freqcnt = (1001000000)/freq;*
I use clk100m to count frequency period(freqcnt).
As below code. always @(posedge clk100m) begin if (cntr100m == freqcnt) begin cntr100m = 0; end else begin cntr100m = cntr100m + 1; end end
always @(cntr100m) begin if (cntr100m < 2) begin fout = 1; end else begin fout = 0; end endf
My problem is solved now, by using C++ code.
↓↓↓
extern “C” __declspec(dllexport) void vco(void **opaque, double t, union uData *data)
{
double vin = data[0].d; // input
bool clk = data[1].b; // input
bool &fout = data[2].b; // output
// Implement module evaluation code here:
unsigned long freq=0;
unsigned long freqcnt=0;
char clk_pre = 0;
@lpoma
This VCO can control the frequency by vin.
Pulse repeted frequency is described by the following fomula. freq = 291(vin-3.3)+3840000
But, It is necessary to compile this code in order to control pulse width.
The pulse width is 1Terra Clock*1000 in this C++ code. fout=(cnt<=1000)?1:0;