The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 25th, 2024, 4:39am
Pages: 1
Send Topic Print
constrain number of bits (Read 2387 times)
aaron_do
Senior Fellow
******
Offline



Posts: 1398

constrain number of bits
Nov 13th, 2013, 10:35pm
 
Hi all,


first off I am new to Veriloga. I am trying to model a digital control loop, but I am storing variables as "real" type. I would like to constrain the resolution of my signals to a certain number of bits to make the system more realistic. Is there any way to do this?

I'm thinking I need the simplest possible ADC function. What I've come up with is :

var = var - var % resolution;

where var is the number I want to constrain, and % is the modulus function. Not sure if this works or if there's a better way though.


thanks,
Aaron
Back to top
 
 

there is no energy in matter other than that received from the environment - Nikola Tesla
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: constrain number of bits
Reply #1 - Nov 14th, 2013, 6:26am
 
Hi Aaron,
your idea is equivalent to rounding towards zero in steps of resolution (sign of % is sign of first operand).
Alternatives are Code:
resolution * ceil(var / resolution) 

or Code:
resolution * floor(var / resolution) 

(rounding towards +/-infinity).
- B O E
Back to top
 
 
View Profile   IP Logged
aaron_do
Senior Fellow
******
Offline



Posts: 1398

Re: constrain number of bits
Reply #2 - Nov 14th, 2013, 8:55pm
 
Thanks!
Back to top
 
 

there is no energy in matter other than that received from the environment - Nikola Tesla
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.