altaj
Junior Member
![* *](https://designers-guide.org/forum/Templates/Forum/default/starblue.gif)
Offline
Posts: 11
|
I have a module for an oscillator that works as follows: When the ENB (enable_bar, so active low) is set low, the output goes to zero. Great. When ENB is set high, the output resumes. Also great. However, the timebase of the oscillator is as it was before the reset. That is to say, it behaves like a continuouslly running oscillator with an outout enable.
I want to modify the module so that when ENB is set low, the oscillator will always start from the same state, regardless of the abstime. I've tried messing with the n and next variables, making them hold position while ENB is high, but am getting nowhere.
If anyone has a suggestion, I would like to hear it. I'm a novice, so, as always, if you see something silly or wrong in the module, I'm always open to learning a better way!
Here is the module: module osc (enb, out);
input enb; output out; voltage enb,out;
parameter real freq=1 from (0:inf), // output frequency vl=-1, // high output voltage vh=1, // low output voltage vth=(vh-vl)/2, tt=0.01/freq from (0:inf); // transition time of output
integer n, enable; real next;
analog begin
@(cross(V(enb) - vth, -1 )) enable = 1; @(cross(V(enb) - vth, +1 )) enable = 0; @(initial_step) next = (0.5/freq + $abstime); @(timer(next)) begin n = !n; next = next + 0.5/freq; end V(out) <+ transition(n ? enable*vh : vl, 0, tt);
end endmodule
Thanks! John
|