programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: High Level Definition for U*/

From: Bee <200309_at_scshop.com>
Date: Thu, 8 Nov 2007 11:21:51 -0800

On Nov 8, 2007, at 10:52 AM, Bob Nash wrote:
> Many thanks. That seems to work fine. There is one LSB difference
> between the GForth calculation and the Swift Forth calculation. As
> the calculation produces a 28-bit result to be loaded (via SPI) into a
> Direct Digital Synthesis chip, the difference is inconsequential.

If the LSB is important, you could add the round up.

Anthony Senerchia wrote:
\ U*/ is an unsigned */ with the twist of rounding up.
\ It adds one less than the divisor to the dividend before dividing.

If I understand correctly:

: u*/mod ( u1 u2 u3 -- r q ) >r um* r@ 1- 0 d+ r> um/mod ;
: u*/ ( u1 u2 u3 -- q ) u*/mod nip ;

It works for the example you gave, but you should test it further.

> Just in case anybody out there needs to calculate a DDS tuning word
> for the Analog Devices AD9833 chip (or others in this family), here is
> the definition I use (courtesy of Charley Shattuck of Intellasys):
>
> 268435456 constant 2^28
> 24574507 constant freq \ 24.57 MHz clock input to MCLK
> \ : u*/mod ( u1 u2 -- r q ) >r um* r> um/mod ; \ GForth only
> \ : u*/ ( u1 u2 u3 -- q ) u*/mod nip ; \ GForth only
> : (hz) ( n1 - n2) 2^28 freq u*/ ;
> : hz ( freq -) (hz) hex . decimal ;
>
> \ Usage: 25000 hz --> 42ABC (SF) or 42ABB (GForth)
>
> P.S. I haven't had the time to test the CODE definition so kindly
> transmitted by Anthony Senerechia, but I must admit it caused some
> embarrassment: it didn't occur to me that both SwiftForth and GForth
> use the same Intel processor (perhaps not the same register
> assignments for Forth, but still ...). The CODE definition is
> probably the better way to go.

Well... I use gforth on a PPC Mac, so the CODE definition would be of
no use.

--
Bill Muench
Santa Cruz, California
----------------------------------------------------------------------
sftalk_at_forth.com      The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users.  For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Thu Nov 08 2007 - 11:23:00 PST

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:43 PST