'DDS-3-4-3 17.2.2014 OH1TV 'Push-button frequency setting and 'Encoder tuning 'with Picaxe-20X2 639/4096 bytes '------------------------------------------------------------------------------ 'This is control SW for AD9850 based DDS-VFO, EIM377 or similar '- Good for setting frequencies in 3.9Hz steps '- Calculation error is 0.003ppm, less than 0.1Hz '- Displays frequency in format 14.195.01 '- The serial display is 2x SparkFun COM-11443 with SPI feed (50kHz) '- Bands 160-10m can be selected with up and down push button '- Up and down 10kHz push buttons '- Up and down 1kHz push buttons '- Calibration with multiplier decimal b7 '- Rotaty encoder step size is 12Hz,(4Hz smallest step possible) '- 128 steps/revolution means 1.5kHz/ revolution '- TX offset -500Hz '- PIC clock 64MHz '- SPI clock 50kHz, display and DDS '------------------------------------------------------------------------------ 'Picaxe-20X2 PINOUT: 'pin 1 = +5V pin 20= 0V 'pin 2 = serial in pin 19= A.0 =serial out 'pin 3 = C.7 =1kHz dwn pin 18= B.0 =display,SDI 'pin 4 = C.6 =1kHz up pin 17= B.1 =display SCK 'pin 5 = C.5 =10kHz dwn pin 16= B.2 =encoder 'pin 6 = C.4 =10kHz up pin 15= B.3 =encoder 'pin 7 = C.3 =band up pin 14= B.4 =display CC1 LS4 'pin 8 = C.2 =band dwn pin 13= B.5 =display CC2 MS4 'pin 9 = C.1 =DDS data pin 12= B.6 =DDS FQ_UD 'pin 10= C.0 =tx offset pin 11= B.7 =DDS clock 'VARIABLES available in X2 b0-b55 or w0-w27 'b0 = band counter w20= sub-kHz target+1000 'b1 = bit8-bit11 encoder bits w21= sub-kHz 'w1 = Fout in kHz w22= , b45=tx offset flag 'w2 = multiplier w23= 'w3 = b6= decimals of Fout w24= 'w3 = b7= decimals of multiplier w25= 'w4 = byte x byte, display data w26= 'w5 = byte x byte, display data w27= 'w6 = byte x byte, display data 'w7 = byte x byte, display data 'w8 = byte x byte, display data 'w9 = byte x byte 'w10= byte x byte 'w11= byte x byte 'w12= byte x byte 'w13= LSB sum 'w14= MSB sum carry 'w15= LSB sum 'w16= MSB sum carry 'w17= LSB sum 'w18= MSB sum carry 'w19= MSB, LSB sum '--------------------------------------------------------------------------- 'MULTIPLYING PRINCIPLE,(256 based numeral system) ' ' w1,b6 b3 b2 b6 Fout ' w2,b7 b5 b4 b7 multiplier ' ---------------------------- ' w6 w5 w4 ' w9 w8 w7 ' w12 w11 w10 ' ---------------------------- ' w19 w17 w15 w13 LSB ' w18 w16 w14 MSB carry ' '---------------------------------------------------------------------------- low C.1 'DDS data low B.6 'DDS FQ_UD pause 500 'let display to start up low B.5 'MS4 device select spiout B.1, B.0,MSBFirst_L,(118) 'clear display,set cursor spiout B.1, B.0,MSBFirst_L,(0,72,1,0) 'send OH1O high B.5 low B.4 'LS4 device select spiout B.1, B.0,MSBFirst_L,(118) 'clear,set cursor spiout B.1, B.0,MSBFirst_L,(76,3,4,3) 'send version number spiout B.1, B.0,MSBFirst_L,(119,%00001111) 'set decimal points high B.4 pause 3000 low B.5 'MS4 device select spiout B.1, B.0,MSBFirst_L,(119,%00000100) 'set decimal point high B.5 low B.4 'LS4 device select spiout B.1, B.0,MSBFirst_L,(119,%00000010) 'set decimal point high B.4 w2=34359 'multiplier, b5=124, b4=55 b7=120 'decimal byte of the multiplier 'nominal 189, use for calibration b0=6 'band selection when opening setfreq m64 goto Band Main: 'read push buttons if PinC.7 =0 then b0=b0-1 'step one band down if b0>254 then b0=b0+9 endif goto Band elseif PinC.6 =0 then b0=b0+1 'step one band up if b0>8 then b0=b0-9 endif goto Band elseif PinC.4 =0 then w1=w1+10 'step 10kHz up b1=1 pause 2000 'set stepping time goto Display elseif PinC.5 =0 then w1=w1-10 'step 10kHz down b1=1 ' let display pause 2000 goto Display elseif PinC.2 =0 then w1=w1+1 'step 1kHz up b1=1 'let display pause 2000 goto Display elseif PinC.3 =0 then w1=w1-1 'step 1kHz down b1=1 pause 2000 goto Display elseif PinC.0 =0 then 'TX offset if b45 =1 then goto Display 'with flag just repeat display w20=w20-128 'no flag>degrease by 500Hz b45=1 'set offset flag goto Display elseif PinC.0=1 then 'return from TX offset if b45=1 then 'with offset flag increase by 500Hz w20=w20+128 b45=0 'remove offset flag goto Display 'update frequency endif endif 'Encoder begins ===================================================== Phase_a: 'channel a triggers bit8=PinB.3:bit9=PinB.2 'read encoder data a,b if bit8>bit10 then goto Mode_1 'data a from 0 to 1 goto Phase_b Mode_1: if bit9>0 then 'VFO direction w20=w20+3 '12Hz steps elseif bit9=0 then w20=w20-3 endif bit10=bit8: bit11=bit9 goto Display Phase_b: 'channel b triggers bit8=PinB.3:bit9=PinB.2 'read encoder data a,b if bit9<>bit11 then 'data b changed bit10=bit8:bit11=bit9 endif goto Main 'Encoder ends ======================================================== Band: lookup b0,(1830,3520,7020,10110,14020,18080,21020,24900,28020),w1 w20=1000 'set decimal bias pause 2500 'set stepping time Display: if w20<1000 then 'carry/borrow from/to sub-kHz w20=w20+256 w1=w1-1 'borrow -1kHz elseif w20>1255 then w20=w20-256 w1=w1+1 'carry +1kHz endif b6=w20-1000 'remove bias w21=b6*39 'scale sub-kHz data bintoascii w21,b12,b11,b10,b9,b8 'convert sub-kHz into ascii bintoascii w1,b17,b16,b15,b14,b13 'convert kHz's into ascii if b17=48 then b17=32 'blank first number if zero endif low B.5 'MS4 device select spiout B.1, B.0,MSBFirst_L,(121,0,32,b17,b16,b15) 'set cursor,send first 4 numbers high B.5 low B.4 'LS4 device select spiout B.1, B.0,MSBFirst_L,(121,0,b14,b13,b11,b10) 'set cursor,send last 4 numbers high B.4 Multiply: 'byte x byte as in table above w4=b7*b6 w5=b7*b2 w6=b7*b3 w7=b4*b6 w8=b4*b2 w9=b4*b3 w10=b5*b6 w11=b5*b2 w12=b5*b3 'sum and carry as in table above w13=b9+b10+b14 'LSB,s w14=b27+b11+b15 'MSB's, carry w15=w14+b12+b16+b20 'LSBy's w16=b31+b13+b17+b21 'MSBy's,carry w17=w16+b18+b22 'LSBy's w18=b35+b19+b23 'MSBy's carry w19=w18+w12 'MSB, LSB 'The binary result with 4 bytes is b39,b38,b34,b30 AD9850: spiout B.7, C.1,LSBFirst_L,(b30,b34,b38,b39,0) 'send control word to DDS high B.6 'FQ_UD on low B.6 'FQ_UD off goto Phase_b '------------------------------------------------------------------------------- 'In AD9850 module EIM377 ' -Parallel input pins D2-D6 shall be grounded, D0, D1 and D7 are left open.. ' -Reset shall be grounded '-------------------------------------------------------------------------------