PicBasic code will work with that part?
PicBasic code will work with that part?
Dave
Always wear safety glasses while programming.
Not sure if this will help but please consider;
Fr (frequency resolution) = 360000000/2^32 = 0.08381903171539306640625 Hz
FTW = INT(Fo / Fr)
FTW = INT(10000000 / 0.08381903171539306640625) = 119304647
or using reciprocal multiplication (with a constant 1 / Fr = 11.9304647);
FTW = INT(Fo * (1 / Fr))
FTW = INT(10000000 * (11.930464711111111111111111111111)) = 119304647
Good luck on your project...
Cheerful regards, Mike, K8LH
Last edited by Mike, K8LH; - 20th October 2010 at 03:58.
PBP doesn't have decimals, and (2^32 * 10e6) takes more than 32-bit LONGs.
But using some 64-bit math works out pretty good.
With the N-Bit_Math module from ... http://www.picbasic.co.uk/forum/showthread.php?t=12433
Which shows a result of ...Code:<font color="#000000"><b>PRECISION </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>8 </b></font><b>SYSTEM </b><font color="#0000FF"><b><i>' 8 bytes = 64-bit </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">"N-Bit_Math.pbp" </font><b>Base </b><font color="#008000"><b>VAR BYTE</b></font>[<b>PRECISION</b>] <b>Fo </b><font color="#008000"><b>VAR BYTE</b></font>[<b>PRECISION</b>] <b>Fs </b><font color="#008000"><b>VAR BYTE</b></font>[<b>PRECISION</b>] <b>FTW </b><font color="#008000"><b>VAR BYTE</b></font>[<b>PRECISION</b>] <font color="#008000"><b>ASM </b></font><font color="#000080">MOVE?CP 4294967295, _Base </font><font color="#0000FF"><b><i>; 2^32 - 1 </i></b></font><font color="#000080">MOVE?CP 10000000, _Fo </font><font color="#0000FF"><b><i>; desired frequency out </i></b></font><font color="#000080">MOVE?CP 360000000, _Fs </font><font color="#0000FF"><b><i>; DDS clock </i></b></font><font color="#000080">MATH_MUL _Base, _Fo, _FTW </font><font color="#0000FF"><b><i>; 2^32 * Fo </i></b></font><font color="#000080">MATH_DIV _FTW, _Fs, _FTW </font><font color="#0000FF"><b><i>; / Fs </i></b></font><font color="#008000"><b>ENDASM HSEROUT </b></font>[<font color="#FF0000">" FTW="</font>,<font color="#008000"><b>HEX2 </b></font><b>FTW</b>(<font color="#800000"><b>3</b></font>),<font color="#008000"><b>HEX2 </b></font><b>FTW</b>(<font color="#800000"><b>2</b></font>),<font color="#008000"><b>HEX2 </b></font><b>FTW</b>(<font color="#800000"><b>1</b></font>),<font color="#008000"><b>HEX2 </b></font><b>FTW</b>(<font color="#800000"><b>0</b></font>),<font color="#800000"><b>13</b></font>,<font color="#800000"><b>10</b></font>] <font color="#008000"><b>STOP </b></font>
FTW=071C71C7
Which is the hex value for 119,304,647
The value is located in the lower 4 bytes of the FTW array and can be easily shifted out to the DDS.
HTH,
DT
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
Bookmarks