I am trying to make a ring oscillator inside of a Xilinx's CoolRunner-II CPLD and trying to measure how many ring-oscillator cycle fits inside a low half of external 10MHz clock. Below is simple code i made using 5 inverters.
module Top(
input clk,
input trig,
output TXD
);
wire node1;
wire node2;
wire node3;
wire node4;
wire node5;
wire node6;
wire node7;
reg[31:0] counter;
reg[31:0] counterBuf;
assign node1 = ~node7;
assign node2 = ~node1;
assign node3 = ~node2;
assign node4 = ~node3;
assign node5 = ~node4;
assign node6 = ~node5;
assign node7 = ~node6;
always @(posedge node5) begin //use ring counter clock
//increase counter only during low period of clock
if(clk==0) counter = counter + 1;
else begin
counterBuf = counter;//save counter value for later use
counter = 0;//restart counter
end
end
However, I try to read counterBuf, it always reads 0. If i comment out "counter=0;", counterBuf shows some change in value. Is the code wrong in esetting the counter?
How can I implement otherwise using verilog?