Big numbers - great big numbers - doable?
N8YX
Posts: 18
Got a little dilemna here and was wondering if anyone has solved it:
I need to keep track of a large numeric value which ranges
from 210453397 to 240518168 (decimal). I also need to dynamically
add or subtract 43, 430 or 4300 from the value - the operator being
dependent on external inputs to the Stamp.
The resultant number will then be converted to a hex dword and sent
serially to an external device, one byte at a time.
Before I attempt to reinvent the wheel - has anyone done a similar
routine with the BS2p series?
I need to keep track of a large numeric value which ranges
from 210453397 to 240518168 (decimal). I also need to dynamically
add or subtract 43, 430 or 4300 from the value - the operator being
dependent on external inputs to the Stamp.
The resultant number will then be converted to a hex dword and sent
serially to an external device, one byte at a time.
Before I attempt to reinvent the wheel - has anyone done a similar
routine with the BS2p series?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Working on the Dword representation of IPs?
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com
No...but now that you mention it, such a thing could be handy for use in my day job.
The task I'm trying to accomplish is the control of an AD9851 DDS chip in my synthesizer project. Got the
offset tuning function completed (ADC0381/PCF8591, etc reading the transceiver's "clarifier"
control voltage then outputting a byte of position data); next is the bit where I look at encoder inputs
and determine if a tuning change is required...then calculate the amount of change, add or subtract the
"offset tuning" value and recalculate the DDS control dword.
Jim, W4ATK did this via a lookup table and a VBasic entry screen; he enters the frequency
directly and the tuning dword is subsequently calculated before being sent to the DDS chip.
I need to do it with a rotary encoder - adding or subtracting one "step" at a time. A step of "43",
"430" or "4300" gives me a tuning change of 1hz, 10hz or 100hz, respectively.
Coming up with the routines in to do this in 8-bit-land will be interesting. Jon, I'll check the link
you provided; hopefully it'll give me a bit of insight.
Thanks!
Here is a starting point:
http://forums.parallax.com/showthread.php?p=549275
That has links back to previous yahoo-groups discussion of how to read the thumbswitches and do a calculation that may be close to what you want. (Note the yahoo groups stuff is now archived here too in forums.parallax.com/forums/search.aspx?f=19, but I don't have a direct link to the same threads there)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
<snip, snip>
x0 var word ' low word of the count
x1 var word ' high word
x0=9990 ' arbitrary starting value
loop:
x0=x0+1//10000 ' up to 9999
x1=x1 + 1-(x0 max 1) ' ten-thousands
' note the term in () equals zero only when x0=0
' so x1 is incremented only when x0 rolls over from 9999 to 0000
debug dec x1,dec4 x0,cr ' display double precision
next
<snip, snip>
I added the required code snippets and changed the starting values of x0 and x1
to reflect the initial start values as needed in my program...that much of
it appears to function correctly, as does the up-count routine.
My program currently increments x0 in steps of 43. This equals a 1hz change at
the DDS, given its clock frequency. (I'll eventually need to change x0 in steps of 430
and 4300 to get 10hz and 100hz DDS changes, respectively...)
The up-counter works at present. However, the rollover function doesn't. (When x0 gets to
9999 or thereabouts, it apparently rolls to 5000 instead of 0...and x1 doesn't increment.)
I need a "down-counter" function as well. Thoughts on where to proceed and what to do to get
x1 to roll over properly?
Tracy: Jim, W4ATK referenced on this forum an AD9850 example which uses a lookup table
and VBasic terminal program to perform the data entry and conversion routines. I
need to perform the function dynamically, through the use of a counter driven
by an optical encoder (think "tuning knob"). I am planning to reuse his EEPROM
R/W and DDS control sequences, however...
(Edit: I did a little more digging on Tracy's site and -might- have found the answer there...won't
get a chance to test it out until after Turkey Day, as I'm going to be away from the Stamp
development system I've set up.)
Post Edited (N8YX) : 11/23/2005 12:40:01 PM GMT
Maybe that is what you need?
I think one of the other posts was about a project where tthe desired frequency was going to come off of BCD thumbwheels. The problem became how to renromalize the decimal input over to the number base requried by the DDS chip. That took a multiple precisiion division. If I read right, your system will take the frequency changes incrementally off of an encoder, so the increments can be made by addition and subtraction directly in the units expected by the DDS. Is that it?
Good luck with the wishbone!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Exactly.
It'll also read an ADC and get a value for "offset tuning". Most communications gear has a provision
for the received frequency to be shifted slightly up or down from the transmit frequency; this is so
an operator can tune in any stations which may be a little off his frequency. I'm using an ADC0831
to do this...tuning either side of "center" (a DEC "128" output from the ADC) gives me a +/- offset
variable. This ranges from 1-127. The program multiplies that value with 43 (for 1hz per step offset),
430 (10hz) or 4300 (for 100hz per step offset). The resultant data will be added to or subtracted from
the control dword before the dword is sent to the DDS.
I thought that I would be out of town for the day...but we got some serious lake-effect snow overnight
and travel plans are on hold. So I just may take a break from the T-day dinner table to do a bit more
research on the math I'll need to make all this work...