programming DDS core


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    France
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    But... I have tried to use a variable for Frequency output and it doesn't work anymore...

    Code:
    PRECISION  CON 8 SYSTEM         ' 8 bytes = 64-bit
    INCLUDE "N-Bit_Math.pbp"
    
    define osc 4
    
    FOUT    var LONG
    Base  VAR BYTE[PRECISION]
    Fo    VAR BYTE[PRECISION]
    Fs    VAR BYTE[PRECISION]
    FTW   VAR BYTE[PRECISION]
    
    high portc.6
    
    FOUT = 1000000
    
    ASM
       MOVE?CP  4294967295, _Base    ; 2^32 - 1
       MOVE?CP  _FOUT, _Fo        ; desired frequency out
       MOVE?CP  360000000, _Fs       ; DDS clock
       
       MATH_MUL _Base, _Fo, _FTW     ; 2^32 * Fo
       MATH_DIV _FTW, _Fs, _FTW      ; / Fs
    ENDASM
    
    serout2 portc.6,84,[" FTW=",HEX2 FTW(3),HEX2 FTW(2),HEX2 FTW(1),HEX2 FTW(0),13,10]
    STOP

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    MOVE?CP is for constants.

    Use MOVE?LP for LONG variables.
    DT

  3. #3
    Join Date
    Sep 2005
    Location
    France
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Darrel... you're wonderful !

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    ADDED:
    Since you are using PBPL, you can also move the result back to a LONG...
    Code:
    PRECISION  CON 8 SYSTEM         ' 8 bytes = 64-bit
    INCLUDE "N-Bit_Math.pbp"
    
    FOUT    var LONG
    Base  VAR BYTE[PRECISION]
    Fo    VAR BYTE[PRECISION]
    Fs    VAR BYTE[PRECISION]
    FTW   VAR BYTE[PRECISION]
    FTWL  VAR LONG
    
    high portc.6
    
    FOUT = 10000000
    
    ASM
       MOVE?CP  4294967295, _Base    ; 2^32 - 1
       MOVE?LP  _FOUT, _Fo           ; desired frequency out
       MOVE?CP  360000000, _Fs       ; DDS clock
       
       MATH_MUL _Base, _Fo, _FTW     ; 2^32 * Fo
       MATH_DIV _FTW, _Fs, _FTW      ; / Fs
       MOVE?PL  _FTW, _FTWL          ; move result to a LONG var
    ENDASM
    
    serout2 portc.6,84,[" FTW=",HEX8 FTWL," = ",DEC FTWL,13,10]
    STOP
    DT

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts