The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 2:26pm
Pages: 1
Send Topic Print
Convert binary analog outout to dec (Read 3474 times)
Streamcx
New Member
*
Offline



Posts: 3

Convert binary analog outout to dec
Apr 06th, 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
 



Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Convert binary analog outout to dec
Reply #1 - 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
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.