#revision 4.21 'Analyser-Stan VA3SMM #picaxe 28x2 setfreq em64 #Terminal 76800 #slot 3 '5-digit slow gate mode #rem ************************************************************************************ LEGAL RESTRICTIONS ON PROGRAM USE ************************************************************************************ This program is fully protected by the provisions of the Commonwealth Copyright Act (Australia). Although any form of reproduction contravenes the Act, the author is not concerned about bona fide electronic hobbyists (and particularly radio amateurs) making single copies of it for their own personal use. However, commercial organisations should note that no significant part of this software can be offered for sale or sold, either on its own or as part of an assembly, unless a licence to do so has been obtained from myself-James Tregellas, 14 Sheringa Drive, Morphett Vale 5162 June 2005 ************************************************************************************ SYMBOL DECLARATIONS ************************************************************************************ #endrem symbol SLOWCLOCK = w16 symbol FASTCLOCK = w17 symbol Vcutoff = w18 symbol V50res = 50 'V50 sensing resistor symbol Rgt500 = 80 'The following are all storage registers symbol Rin1 = 81 symbol Rin2 = 82 symbol Rin3 = 83 symbol Xgt500 = 84 symbol Xin1 = 85 symbol Xin2 = 86 symbol Xin3 = 87 symbol SWRgt10 = 88 symbol SWR1 = 89 symbol SWR2 = 90 symbol SWR3 = 91 symbol FREQ1 = 92 symbol FREQ2 = 93 symbol FREQ3 = 94 symbol FREQ4 = 95 symbol FREQ5 = 96 symbol Vres = 97 symbol V50 = 98 symbol Vreact = 99 symbol SWRA = 100 symbol MODEFLAG = 101 symbol ZSCALE = 102 symbol OCFLAG = 103 symbol SCFLAG = 104 symbol DIVIDEND = 105 symbol DIVISOR = 106 symbol STARTUP_DONE = 107 symbol FREQ_LSB = 108 symbol FREQ_MSB = 109 symbol L_LSB = 110 symbol L_MSB = 111 symbol C_LSB = 112 symbol C_MSB = 113 symbol X_LSB = 114 symbol X_MSB = 115 symbol R_LSB = 116 symbol R_MSB = 117 symbol RES1 = 118 symbol RES2 = 119 symbol RES3 = 120 symbol ANGL1 = 121 symbol ANGL2 = 122 '************************************************************************************ ' MEASURE FREQUENCY '************************************************************************************ main: readadc 3,b0 'Check voltage peek DIVIDEND,b20 'Inserts your battery check dividend peek DIVISOR,b21 'Inserts your battery check divisor w20=b0*b20 w20=w20/b21 'If less than 12.0 volts then shut down if w20w2 then square 'impossible output from network w2>w3+w4 if w5=w2 then square '-modify w2 and treat as pure resistance w2=w5 square: w5=w4 'save vout for later w2=w2*w2 'calculate w2 squared-VIN squared w3=w3*w3 'calculate w3 squared-V50 squared w4=w4*w4 'calculate w4 squared-VOUT squared w6=w3+w4 if w220 (approx) if w2<10 and w6>50 then swr2large if w2<20 and w6>100 then swr2large if w2<50 and w6>150 then swr2large if w6>250 then swr2large if w2>500 then swr2large goto printr swr2large: poke SWRgt10,10 'set flag to print "SWR>10" #rem ************************************************************************************ inputs w2-ADC output for network input volts (0-255max 240max preferred) w3-ADC output for volts across 50 ohm series R (network current) w4-ADC output for network output volts (volts across load) outputs w2-unknown series load resistance in ohms w6-unknown reactance in ohms voltage across aerial load resistance is in 97 voltage across 50 ohm series resistor is in 98 voltage across aerial load reactance is in 99 ************************************************************************************ #endrem printr: if w2>500 then r2large w0=w2 'recover individual digits from w2 (resistance) w1=w0/100 w2=w0//100 w2=w2/10 w3=w0//10 w1=w1+$30 'Convert individual digits to ASCII w2=w2+$30 w3=w3+$30 poke Rin1,b2 poke Rin2,b4 poke Rin3,b6 sertxd(b2,b4,b6,",") 'Serial out for resistance, comma delimited goto printx r2large: poke Rgt500,10 'set flag to print "R>500 ohms" printx: if w6>500 then x2large w0=w6 'recover individual digits from w6 (reactance) w1=w0/100 w2=w0//100 w2=w2/10 w3=w0//10 w1=w1+$30 'Convert individual digits to ASCII w2=w2+$30 w3=w3+$30 poke Xin1,b2 poke Xin2,b4 poke Xin3,b6 sertxd(b2,b4,b6,",") 'Serial out for reactance, comma delimited goto calca x2large: poke Xgt500,10 'set flag to print "X>500 ohms" '************************************************************************************ ' SWR CALCULATIONS '************************************************************************************ calca: peek SWRgt10,b10 if b10>0 then freq peek Vres,b4 peek V50,b5 peek Vreact,b6 w4=b6*b6 w5=b5+b4 w5=w5*w5 w4=w4+w5 'w4= A squared in swr equation w6=sqr w4 'Square root calcb: poke SWRA,b12 'save value of A for later if b4>=b5 then calcb1 w4=b6*b6 w5=b5-b4 w5=w5*w5 w4=w4+w5 goto squrt calcb1: w4=b6*b6 w5=b4-b5 w5=w5*w5 w4=w4+w5 'w4=B squared in swr equation squrt: w6=sqr w4 'Square root swr: peek SWRA,b4 w3=b4+b12 w3=w3*100 w4=b4-b12 w3=w3/w4 printswr: if w3>999 then swr2large1 w0=w3 'recover individual digits from w5 (resistance) w1=w0/100 w2=w0//100 w2=w2/10 w3=w0//10 w1=w1+$30 'Convert individual digits to ASCII w2=w2+$30 w3=w3+$30 poke SWR1,b2 poke SWR2,b4 poke SWR3,b6 sertxd(b2,".",b4,b6) 'Serial out for SWR goto freq swr2large1: poke SWRgt10,10 goto freq #rem ************************************************************************************ MESSAGE ROUTINES ************************************************************************************ #endrem cactus: b1=1 gosub wrins b0=0 'display message "RF OSC KAPUT" at start of display line 1 loop7: lookup b0,("RF OSC KAPUT "),b1 b0=b0+1 gosub wrchr if b0<16 then loop7 goto main freq: b1=128 'display frequency "xx.xxxMHz" at start of display line 1 gosub wrins peek FREQ1,b4 if b4<>$30 then freqnxt 'Check for a leading disp zero b4=$20 'Simply deposit a space char freqnxt: 'Add a label peek FREQ2,b5 peek FREQ3,b6 peek FREQ4,b7 peek FREQ5,b8 b0=0 loop0: lookup b0,(b4,b5,".",b6,b7,b8,"MHz"),b1 b0=b0+1 gosub wrchr if b0<9 then loop0 peek OCFLAG,b4 peek SCFLAG,b5 if b4>0 then open if b5>0 then short goto rwrite open: b1=192 gosub wrins b0=0 'display message "OPEN CCT LOAD " at start of line 2 loop8: lookup b0,("OPEN CCT LOAD "),b1 b0=b0+1 gosub wrchr if b0<16 then loop8 goto main short: b1=192 gosub wrins b0=0 'display message "SHORT CCT LOAD " at start of line 2 loop9: lookup b0,("SHORT CCT LOAD "),b1 b0=b0+1 gosub wrchr if b0<16 then loop9 goto main rwrite: peek Rgt500,b11 if b11>0 then r2 peek Rin1,b3 peek Rin2,b4 peek Rin3,b5 if b3>$30 then rwrite1 'leading zero suppression if b4=$30 then rwrite2 goto rwrite3 rwrite2: b4=$20 rwrite3: b3=$20 rwrite1: b0=0 'Append message "R=xxx ohms" to end of display line 1 loop1: lookup b0,(" R=",b3,b4,b5,$f4),b1 b0=b0+1 gosub wrchr if b0<7 then loop1 goto xwrite r2: b0=0 'Append message "R>500 ohms" to end of display line 1 loop2: lookup b0,(" R>500",$f4),b1 b0=b0+1 gosub wrchr if b0<7 then loop2 xwrite: b1=192 gosub wrins peek Xgt500,b11 if b11>0 then x2 peek Xin1,b3 peek Xin2,b4 peek Xin3,b5 if b3>$30 then xwrite1 'leading zero suppression if b4=$30 then xwrite2 goto xwrite3 xwrite2: b4=$20 xwrite3: b3=$20 xwrite1: b0=0 'display message "X=xxx ohms" at start of display line 2 loop3: lookup b0,("X=",b3,b4,b5,$f4),b1 b0=b0+1 gosub wrchr if b0<6 then loop3 goto swrwrite x2: 'display message "X>500 0hms" at start of display line 2 b0=0 loop4: lookup b0,("X>500",$f4),b1 b0=b0+1 gosub wrchr if b0<6 then loop4 swrwrite: peek SWRgt10,b4 peek SWR1,b5 peek SWR2,b6 peek SWR3,b7 if b4>0 then swr10 b0=0 'append message "SWR=x.xx" to line 2 loop5: lookup b0,(" SWR=",b5,".",b6,b7),b1 b0=b0+1 gosub wrchr if b0<10 then loop5 swr10: b0=0 'append message "SWR>10" to line 2 loop6: lookup b0,(" SWR>10 "),b1 b0=b0+1 gosub wrchr if b0<10 then loop6 goto main shutdown: b1 = 10 'Turn off the LCD gosub wrins end 'Stop the program and processor function to save power. '************************************************************************************ ' HD44780 LCD DISPLAY ROUTINES '************************************************************************************ init: 'INITIALISE DISPLAY subroutine pinsB = 0 'Clear all output lines b0=0 'Reset variable b0 pause 800 'Wait 200ms for lcd to reset pinsB = $30 'Set to 8 bit operation pulsout B.3,4 'Send data by pulsing enable line pause 40 'Wait 10ms pulsout B.3,4 'Send data by pulsing enable line pulsout B.3,4 'Send data by pulsing enable line pinsB = $20 'Set to 4 bit operation pulsout B.3,4 'Send data by pulsing enable line pulsout B.3,4 'Send data by pulsing enable line pinsB = $80 'Set to 2 line operation pulsout B.3,4 'Send data by pulsing enable line b1=$0E 'Screen on, cursor on operation gosub wrins 'Write instruction to lcd return 'Return to main program wrchr: 'WRITE CHARACTER subroutine pinsB = b1&%11110000 'Mask high nibble of b1 into b2 high B.2 'Make sure RS is high(character mode) pause 4 pulsout B.3,4 'Send data by pulsing enable line b2=b1*$10 'Put low nibble of b1 into b2 pinsB = b2&%11110000 'Mask the high nibble of b2 high B.2 'Make sure RS is high pause 4 pulsout B.3,4 'Send data by pulsing enable line return 'Return to main program wrins: 'WRITE INSTRUCTION subroutine pinsB = b1&%11110000 'Mask high nibble of b1 into b2 low B.2 'Make sure RS is low(instruction mode) pause 4 pulsout B.3,4 'Send data by pulsing enable line b2=b1*$10 'Put low nibble of b1 into b2 pinsB = b2&%11110000 'Mask the high nibble of b2 low B.2 'Make sure RS is low pause 4 pulsout B.3,4 'Send data by pulsing enable line high B.2 'Back to character mode pause 4 return 'Return to main program '************************************************************************************