The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Convert binary analog outout to dec
https://designers-guide.org/forum/YaBB.pl?num=1302145251

Message started by Streamcx on Apr 6th, 2011, 8:00pm

Title: Convert binary analog outout to dec
Post by Streamcx on Apr 6th, 2011, 8:00pm

I have 8 inputs. Each input represents discharge in binary.
For example: In0 - LSB, ..., In7 - MSB.
I have 1 output. I want that to out decimal code. And i want change period optionally.

I want know how to use "analog begin", and timer to write my code, because I don`t know how it works jointly.
I have write some code, that works but I have one's doubts about correct work. Is this works only when binary digit grows up? I need this to work when binary digit  downs (or grows).
But I don`t know how this works, beacuse I do not know how timer works. Is decimal out refresh out digits depending on timer or  decimal out saves constantly his digits?



Code:
// VerilogA for Kuykin_ADC, ladder, veriloga

`include "constants.vams"
`include "disciplines.vams"

module outdec (in0, in1, in2, in3, in4, in5, in6, in7, out);
input in0, in1, in2, in3, in4, in5, in6, in7;
electrical in0, in1, in2, in3, in4, in5, in6, in7;
output out;
electrical out;

// is it periodic? Set to 0 if you want it to be one shot
parameter integer periodic = 1;
parameter real initial_delay = 0;
parameter real period = 1u;

analog begin

     @(timer(initial_delay,period))
     begin
     
     end
       if (V(in0) > 4.5)
     V(out) <+ 1;
       else V(out) <+ 0;
     if (V(in1) > 4.5)
     V(out) <+ 2;
     else V(out) <+ 0;
     if (V(in2) > 4.5)
     V(out) <+ 4;
     else V(out) <+ 0;
     if (V(in3) > 4.5)
     V(out) <+ 8;
     else V(out) <+ 0;
     if (V(in4) > 4.5)
     V(out) <+ 16;
     else V(out) <+ 0;
     if (V(in5) > 4.5)
     V(out) <+ 32;
     else V(out) <+ 0;
     if (V(in6) > 4.5)
     V(out) <+ 64;
     else V(out) <+ 0;
     if (V(in7) > 4.5)
     V(out) <+ 128;      
     else V(out) <+ 0;            
end
endmodule



Title: Re: Convert binary analog outout to dec
Post by boe on Apr 7th, 2011, 2:25am

Streamcx,

Your code constantly updates the output; it also creates a discontinuity every time the input changes. If you want to change it at the timer events, you should convert your input inside the timer event and then assign it to the output through a transition filter.

B O E

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.