This code was written using Parallax's new PBasic 2.5 and requires their new editor.
AmQRP Homebrewer, Issue #5 2 Copyright 2005, AmQRP, All rights reserved
This code was written using Parallax's new PBasic 2.5 and requires their new editor.
AD9850_Loader.bsx
'{$STAMP BS2sx}
'{$PBASIC 2.5}
'
' AD9850/NJQRP DDS Daughtercard Loader Version 1.
' By Wade Lake - KR7K '
' The following Data table contains 32 bit hex values representing Frequency in Hertz.
' Digits 0-9 FOR the 1's, 10's, 100,s, 1000's,... 1,000,000's decimal places and digits 0-4 ' for the 10,000,000's decimal place. This totals 75 - 32 bit values. The main idea is this:
' If you add one decimal places value to the next, keeping a running total, when all the decimal ' places individual values are added, the correct 32 bit frequency tuning word is calculated.
' This table is only valid for a reference oscillator frequency of 100MHz (Like the NJQRP DDS Kit).
DATA $00,$00,$00,$00,$00,$00,$00,$2b,$00,$00,$00,$56,$00,$00,$00,$81,$00,$00,$00,$AC,$00,$00,$00,$D7,
FREQOUT 5,400,600,900 'This is the section that actually loads the DDS.
DEBUG CR, HEX sum4, HEX sum3, HEX sum2, HEX sum1 'The "Load Beep" is sounded indicating that a new SHIFTOUT 1,4,0,[sum1,sum2,sum3,sum4,$00] 'frequency has been calculated and is being loaded.
HIGH 2 'I used pin 1 for Data (P1-3 on DDS board)and pin 4
LOW 2 'for clock (P1-2 on DDS board) and pin 2 for freq.
'update or "Load" (P1-1 on DDS board). These stamp 'I/O pins were selected for my convenience. (my old
'stamp has a few blown I/O pins from years of experimenting) 'These could easily be changed to suit. Like, making the
sum1=0 'pinout match the DDS Board pinout might be a good idea.
sum2=0 sum3=0 sum4=0
DEBUG CR, "Frequency in Hertz? " 'This section first aquires the digits and then indexes GOSUB button_detect 'the data table for the given digit value. For each digit IF digit > "4" THEN GOTO start 'the math subroutine is executed. It reads the indexed digit=(((digit-$30)*4)+280) '32 bit hex values from the data table and performs 32 bit
GOSUB The_Math 'addition to keep a running total. Notice the IF THEN
'statement at the 3rd line of this section, it is in the GOSUB button_detect '10,000,000's decimal place part of the code and does not digit=(((digit-$30)*4)+240) 'allow a digit value greater than 4. Since the DDS board GOSUB The_Math 'does not work well much above 30MHz, allowing a 4 here is
'actually overdoing it a bit. Also important to know is the GOSUB button_detect 'frequency must be entered starting with the most significant digit=(((digit-$30)*4)+200) 'decimal place value. If it is zero then the zero MUST be GOSUB The_Math 'entered. This holds true for all leading zeros. For instance
'If I were loading a frequency of 1.160MHz I would enter
GOSUB button_detect '"01160000" on the keypad or in the hyperterminal window.
IF digit=0 OR digit//40=0 THEN FREQOUT 5,300,900,900 ELSE FREQOUT 5,300,600,600 'A Beep is generated indicating 'that a digit has been aquired.
READ digit+3,term1 'This section is the 32 bit adding routine.
test=term1+sum1 'It reads the values from the data table IF test>=256 THEN sum2=sum2+1 'and adds them to the running total.
sum1=sum1+term1
'If pin 6 is tied high at power-up then the digits can 'be entered in the debug window or using hyperterminal.
button_detect: 'This is the subroutine that aquires the digit values from 'a standard 4x4 keypad. This is done using 8 I/O lines, IF IN6=1 THEN GOTO hyperterminal 'pins 8 thru 15 on the stamp. 8 thru 11 corresponds with
'"C" nibble (predefined by the basic stamp) and are wired DIRC=%1111 'to the corresponding "Rows" on the keypad. Row 1 being port DIRD=%0000 'C's LSB. 12 thru 15 correspond with the "D" nibble and are
OUTC=%1111 'wired to the "columns".
'
Waiting_for_button_press: ' Two important notes:
'1) Pull down resistors are required on pins 8 thru 15 and IF IND=0 THEN GOTO Waiting_for_button_press ' on pin 6.
'2) When entering frequencies using a terminal, I found it find_digit: ' easiest to just use the Basic Stamp software's debug window.
' If hyperterminal is to be used then the special cable ' used for stamp programming CAN NOT be used. Only use row=IND ' the 3 standard wires, TX, RX, GND. No "loopback" wires
OUTC=%0000 ' were needed in my testing.
DIRC=%0000
AmQRP Homebrewer, Issue #5 4 Copyright 2005, AmQRP, All rights reserved
IF digit="#" AND INC=0 THEN GOTO start ' If a "#" is entered the program accepts the frequency entry and
IF digit<>"#" AND INC=0 THEN RETURN ' loads it, disregarding the remaining decimal places or "trailing zeros".
GOTO loop1 ' It works like an "enter" key for the keypad. For example, if I ' were to load a frequency of 1.160MHz I could enter "0116#"
hyperterminal:
DEBUGIN digit ' If pin 6 is high the frequency is entered in through the serial IF digit=CR THEN GOTO start ' port. This section takes care of that. The frequency can be
RETURN ' entered without all the trailing zeros by simply hitting the
' "Enter" key. Like with the keypad, all leading zeros MUST be ' entered.
All material in HOMEBREWER is copyright 2005 and may not be reprinted in any form without express written permission from the American QRP Club and the individual author. Articles have not been tested and no guarantee of success is implied. Safe constructions practices should always be followed and the builder assumes all risks. HOMEBREWER Magazine is a quarterly journal of the American QRP Club, published on CD-ROM. Each issue typically contains over 200 pages of QRP-related homebrewing construction and technical articles intended for builders, experimenters, ham radio operators and low power enthusiasts all around the world. HOMEBREWER features include construction projects for beginners all the way up to the advanced digital and RF experimenters. Annual subscriptions are $15 (for US & Canada) and $20 (for foreign addresses). For information, contact editor/publisher George Heron, N2APB at[email protected]or visit HOMEBREWER Magazine home page atwww.amqrp.org/homebrewer.
Dave Ek, NKØE