Shop OBEX P1 Docs P2 Docs Learn Events
Big numbers - great big numbers - doable? — Parallax Forums

Big numbers - great big numbers - doable?

N8YXN8YX Posts: 18
edited 2005-12-10 18:23 in BASIC Stamp
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?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-22 16:05
    Tracy Allen has information on 32-bit numbers in PBASIC on his web site: www.emesystems.com

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-11-22 16:22
    N8YX,

    Working on the Dword representation of IPs?

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • N8YXN8YX Posts: 18
    edited 2005-11-22 17:29
    "Working on the Dword representation of IPs?"

    No...but now that you mention it, such a thing could be handy for use in my day job. scool.gif

    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!
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-22 18:50
    This subject (numerics for the AD9850 series) has come up before on the forum.

    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
  • N8YXN8YX Posts: 18
    edited 2005-11-23 12:30
    OK...checked Tracy's site; got the following:

    <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
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-23 18:39
    The counter routine quoted is meant to work with an increment of 1 only, not 43, 430 or 4300. For that, you need to use the double precision addition or substraction routines that are found farther down on the same web page.

    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
  • N8YXN8YX Posts: 18
    edited 2005-11-24 14:44
    "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?"

    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... burger.gif
  • TomSTomS Posts: 128
    edited 2005-12-10 18:23
    I've been following this thread and I believe I'm doing something similar with an AD9834 DDS. I'm using an optical encoder to "fine tune" a not too accurate cyrstal. Using the 7-bit counter value to change the control word of the AD9834, which is the reference for the PLL. I'm interested in the way you are doing it. Please look my schematic (simplified) over and if you could use it or make a suggestion, please do so.
Sign In or Register to comment.