fg_ctrl.rmh

来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,476 行 · 第 1/5 页

RMH
1,476 行
字号
// @076 #631: [fill_max]2fab0 // @076 #631: STORE(sA,sB)14b0b // @077 #632: COMPARE(sB,BCD_digit8) ;check if filled to 100MHz digit35046 // @078 #633: JUMP(Z,edit_display)18b01 // @079 #634: ADD(sB,1) ;fill next higher digit34076 // @07a #635: JUMP(fill_max)// #636: ;// @07b #637: [end_edit_mode]3007d // @07b #637: CALL(wait_switch_release) ;wait for end of switch press3401f // @07c #638: JUMP(move_mode) ;then go to move cursor mode// #639: ;// #640: ;// #641: ; Routine to poll the press switch with de-bounce delay and wait for it to be// #642: ; released. Any rotation inputs detected by the interrupt// #643: ; service routine are cleared before returning.// #644: ;// @07d #645: [wait_switch_release]301c8 // @07d #645: CALL(delay_20ms) ;delay to aid switch de-bounce04000 // @07e #646: INPUT(s0,rotary_port) ;read rotary encoder12002 // @07f #647: TEST(s0,rotary_press) ;test if button is still being pressed3547d // @080 #648: JUMP(NZ,wait_switch_release)00000 // @081 #649: LOAD(s0,0) ;clear flag indicating any rotary events2e000 // @082 #650: STORE(s0,rotary_status)2a000 // @083 #651: RETURN// #652: ;// #653: ;**************************************************************************************// #654: ; Compute DDS control words from currently display frequency value// #655: ;**************************************************************************************// #656: ;// #657: ; This routine reads the current BCD value and converts it into a 32-bit binary// #658: ; integer. It then multiplies it by a 48-bit scaling factor (see notes in the// #659: ; constants section above) to form a full precision 80-bit product.// #660: ;// #661: ; From this product the 32-bit DDS control word must be extracted. For frequencies of// #662: ; 50MHz or above the DDS control word is formed by shifting the product left by 2 places// #663: ; (multiply by 4) and then keeping only the most significant 32-bits (4 bytes).// #664: ;// #665: ; Also for frequencies of 50MHz and above, there is no additional division performed// #666: ; after the DCM which multiplies frequency and reduces the jitter. Therefore the DDS_scaling// #667: ; word will be set to zero and the output of the DCM will divide by 2.// #668: ;// #669: ;   Freq     DDS control word    DDS Scaling      Synthesized Frequency// #670: ;                                                  of Phase Accumulator// #671: ;// #672: ;  50MHz      08000000              00                   6.25MHz// #673: ; 100MHz      10000000              00                  12.50MHz// #674: ;// #675: ; You will notice that for frequencies of 50MHz and above, the upper byte of the// #676: ; DDS control word is 08 hex or greater. In other words, bit3 and/or bit4 of that byte// #677: ; are High (bits 27 and/or 28 of the full 32-bit word). This is the indication that// #678: ; the control words are complete.// #679: ;// #680: ; For frequencies below 50MHz an additional process is required. The reason for this// #681: ; becomes clear if we think about the lowest frequency of 1Hz. In that case the 80-bit// #682: ; product is the same as the 48-bit scaling constant 00000000ABCC77118462. Once this// #683: ; has been multiplied by 4 (shifted left 2 places) it becomes 00000002AF31DC461188 and the// #684: ; most significant 32-bits are only 00000002 hex. If we put this back into the basic// #685: ; equations for the phase accumulator we find that the output frequency of the phase// #686: ; accumulator would be// #687: ;// #688: ;    Fout = M x clk x N / (2^p)// #689: ;// #690: ;         = 8 x 200MHz x 2 / (2^32) = 0.745 Hz// #691: ;// #692: ; There are two important observations we can make. Firstly we have lost accuracy because// #693: ; the resolution of the DDS control word has become too granular at low amplitudes.// #694: ; Secondly this would never even work because the frequency synthesized by the phase// #695: ; accumulator would be 0.745/8 = 0.0931 Hz which is seriously slow and a way below the// #696: ; frequency at which the DCM can even work.// #697: ;// #698: ; The solution to both of these issues is to ensure that the DDS control word is always// #699: ; formed to be in the range that would result in an output of 50MHz or above. In other// #700: ; words to keep the phase accumulator output in the range 6.25MHz to 12.5MHz such that// #701: ; the DCM is able to work and only has to deal with one octave of input variation. This// #702: ; can be achieved by shifting the 80-bit product left more times until bits 27 and 28// #703: ; of the most significant 32-bits are not zero.// #704: ;// #705: ; For each shift left the synthesized frequency is being doubled and therefore the final// #706: ; output from the DCM must be divided by a further factor of 2. This is achieved using// #707: ; a multiplexer which is guided to select the appropriate output from a simple binary// #708: ; counter.// #709: ;// #710: ; Returning to the example of 1Hz, the 80-bit product will be shifted left by the default// #711: ; 2 places (multiplied by 4), but will then need to be shifted left by a further 26 places// #712: ; which is like multiplying by 67108864 (04000000 hex).// #713: ;// #714: ;                            00000000ABCC77118462// #715: ;                          x                    4// #716: ;                            --------------------// #717: ;                            00000002AF31DC461188// #718: ;// #719: ;// #720: ;                          x             04000000// #721: ;                            --------------------// #722: ;                            0ABCC771184620000000// #723: ;// #724: ; So now the DDS control word is 0ABCC771 (180143985 decimal)and the frequency synthesized// #725: ; by the phase accumulator will be....// #726: ;// #727: ;   Fpa = clk x N / (2^p) = 200MHz x 180143985 / (2^32) = 8388608Hz// #728: ;// #729: ; The DCM will multiply this by a factor of 16 to give 134217728Hz and this will then// #730: ; be divided by the counter of which the 26th bit selected (26 decimal = 1A hex).// #731: ;// #732: ;   Fout = Fpa x 16 / (2^(D+1)) =  8388608Hz x 16 / (2^(26+1)) = 0.99999999947 Hz// #733: ;// #734: ;     'D' is the DDS Scaling factor// #735: ;         Note that bit0 of a counter is a clock division by 2 and hence the 'D+1'// #736: ;// #737: ; Clearly this implementation style has provided much greater accuracy and enables// #738: ; the DCM to work for all desired frequencies.// #739: ;// #740: ;// #741: ;   Freq     DDS control word    DDS Scaling      Synthesized Frequency// #742: ;                                                  of Phase Accumulator// #743: ;// #744: ; 100 MHz      10000000              00                  12.50MHz// #745: ;  50 MHz      08000000              00                   6.25MHz// #746: ;  25 MHz      08000000              01                   6.25MHz// #747: ;  12.5 MHz    08000000              02                   6.25MHz// #748: ;// #749: ;    1Hz       0ABCC771              1A                   8.388608 MHz// #750: ;// #751: ;// #752: ;// #753: ; In order to ensure the DCM is always provided with a frequency in an acceptable// #754: ; range, the value of absolute zero is never implemented and instead just a very low// #755: ; frequency is produced.// #756: ;   6.25MHz x 16 / (2^31+1) = 0.0233 Hz// #757: ;       which is 1 cycle every 43 seconds and that is pretty slow  :-)// #758: ;// #759: ;// #760: ;// #761: ;// @084 #762: [compute_DDS_words]300e5 // @084 #762: CALL(BCD_to_integer) ;convert BCD display value to 32-bit value30119 // @085 #763: CALL(scale_frequency) ;80-bit product of 32-bit frequency x 48-bit scaling value06a1b // @086 #764: FETCH(sA,product9) ;read the upper part of the 80-bit product into [sA,s9,s8,s7,s6,s5,s4]0691a // @087 #765: FETCH(s9,product8) ; The least significant 24-bits of the 80-bit product will never06819 // @088 #766: FETCH(s8,product7) ; be used for frequencies above 1Hz.06718 // @089 #767: FETCH(s7,product6) ;The final 32-bit DDS control word will be formed in06617 // @08a #768: FETCH(s6,product5) ; [sA,s9,s8,s7]06516 // @08b #769: FETCH(s5,product4)06415 // @08c #770: FETCH(s4,product3)300a1 // @08d #771: CALL(shift80_left) ;multiply DDS control word by 4 to achieve default value300a1 // @08e #772: CALL(shift80_left)00b00 // @08f #773: LOAD(sB,0) ;default scaling factor is 2 (select counter bit0)// @090 #774: [normalise_loop]12a18 // @090 #774: TEST(sA,24) ;Test bits 27 and 28 of 32-bit DDS control word3549a // @091 #775: JUMP(NZ,store_DDS_words) ;DDS control word is normalised to above 50MHz output300a1 // @092 #776: CALL(shift80_left) ;multiply DDS control word by 218b01 // @093 #777: ADD(sB,1) ;Divide final value by 2 to compensate14b1f // @094 #778: COMPARE(sB,31) ;Test for maximum division factor35490 // @095 #779: JUMP(NZ,normalise_loop)00a08 // @096 #780: LOAD(sA,8) ;Set for minimum frequency00900 // @097 #781: LOAD(s9,0) ; with phase accumulator set to generate 6.25MHz00800 // @098 #782: LOAD(s8,0)00700 // @099 #783: LOAD(s7,0)// @09a #784: [store_DDS_words]2e71c // @09a #784: STORE(s7,DDS_control0) ;store local copy of control word2e81d // @09b #785: STORE(s8,DDS_control1) ;store local copy of control word2e91e // @09c #786: STORE(s9,DDS_control2) ;store local copy of control word2ea1f // @09d #787: STORE(sA,DDS_control3) ;store local copy of control word2eb20 // @09e #788: STORE(sB,DDS_scaling)300a9 // @09f #789: CALL(drive_DDS_words) ;output control words to DDS circuit2a000 // @0a0 #790: RETURN// #791: ;// @0a1 #792: [shift80_left]20406 // @0a1 #792: SL0(s4) ;shift (most of the) 80-bit value in20500 // @0a2 #793: SLA(s5) ;  [sA,s9,s8,s7,s6,s5,s4] left 1 place20600 // @0a3 #794: SLA(s6)20700 // @0a4 #795: SLA(s7)20800 // @0a5 #796: SLA(s8)20900 // @0a6 #797: SLA(s9)20a00 // @0a7 #798: SLA(sA)2a000 // @0a8 #799: RETURN// #800: ;// #801: ;**************************************************************************************// #802: ; Set DDS control words// #803: ;**************************************************************************************// #804: ;// #805: ; Because multiple ports are used, the idea is to update all of them in// #806: ; rapid succession to avoid too much disturbance in the frequency synthesis.// #807: ;// #808: ; dds_control_word should be supplied in register set [sA,s9,s8,s7]// #809: ; dds_scaling_word should be supplied in register s6.// #810: ;// @0a9 #811: [drive_DDS_words]0671c // @0a9 #811: FETCH(s7,DDS_control0)0681d // @0aa #812: FETCH(s8,DDS_control1)0691e // @0ab #813: FETCH(s9,DDS_control2)06a1f // @0ac #814: FETCH(sA,DDS_control3)06620 // @0ad #815: FETCH(s6,DDS_scaling)2c702 // @0ae #816: OUTPUT(s7,DDS_control0_port)2c804 // @0af #817: OUTPUT(s8,DDS_control1_port)2c908 // @0b0 #818: OUTPUT(s9,DDS_control2_port)2ca10 // @0b1 #819: OUTPUT(sA,DDS_control3_port)2c620 // @0b2 #820: OUTPUT(s6,DDS_scaling_port)2a000 // @0b3 #821: RETURN// #822: ;// #823: ;// #824: ;**************************************************************************************// #825: ; Display frequency on top line of the LCD and DDS data on the lower line// #826: ;**************************************************************************************// #827: ;// #828: ; The BCD value should be stored in scratch pad memory in 9 ascending locations// #829: ; called BCD_digit0 to BCD_digit8.// #830: ;// #831: ; The value is displayed in the format      xxx.xxx xxxMHz// #832: ;// #833: ; However, the most significant 2 digits will be blanked if zero.// #834: ;// #835: ; registers used s0,s1,s2,s3,s4,s5,s6,s7// #836: ;// #837: ;// @0b4 #838: [display_freq]3015d // @0b4 #838: CALL(display_DDS_data) ;display DDS information on lower line00512 // @0b5 #839: LOAD(s5,18) ;Line 1 position 23022b // @0b6 #840: CALL(LCD_cursor)0650b // @0b7 #841: FETCH(s5,BCD_digit8) ;read 100MHz digit14500 // @0b8 #842: COMPARE(s5,0) ;test for blanking350be // @0b9 #843: JUMP(Z,blank_100M_digit)300df // @0ba #844: CALL(display_digit) ;display non zero digit0650a // @0bb #845: FETCH(s5,BCD_digit7) ;read 10MHz digit and display300df // @0bc #846: CALL(display_digit)340c5 // @0bd #847: JUMP(disp_1M_digit)// #848: ;// @0be #849: [blank_100M_digit]300e2 // @0be #849: CALL(display_space) ;blank 100MHz digit0650a // @0bf #850: FETCH(s5,BCD_digit7) ;read 10MHz digit14500 // @0c0 #851: COMPARE(s5,0) ;test for blanking350c4 // @0c1 #852: JUMP(Z,blank_10M_digit)300df // @0c2 #853: CALL(display_digit) ;display non zero digit340c5 // @0c3 #854: JUMP(disp_1M_digit)// #855: ;// @0c4 #856: [blank_10M_digit]300e2 // @0c4 #856: CALL(display_space) ;blank 10MHz digit// #857: ;// @0c5 #858: [disp_1M_digit]06509 // @0c5 #858: FETCH(s5,BCD_digit6) ;read 1MHz digit and display300df // @0c6 #859: CALL(display_digit)0052e // @0c7 #860: LOAD(s5,character_stop) ;display decimal point301eb // @0c8 #861: CALL(LCD_write_data)// #862: ;00208 // @0c9 #863: LOAD(s2,BCD_digit5) ;set pointer to 100KHz digit300d8 // @0ca #864: CALL(display_3_digits)300e2 // @0cb #865: CALL(display_space)00205 // @0cc #866: LOAD(s2,BCD_digit2) ;set pointer to 100Hz digit300d8 // @0cd #867: CALL(display_3_digits)0054d // @0ce #868: LOAD(s5,character_M) ;display 'MHz'301eb // @0cf #869: CALL(LCD_write_data)00548 // @0d0 #870: LOAD(s5,character_H)301eb // @0d1 #871: CALL(LCD_write_data)0057a // @0d2 #872: LOAD(s5,character_z)301eb // @0d3 #873: CALL(LCD_write_data)// #874: ;06510 // @0d4 #875: FETCH(s5,cursor_position) ;reposition edit cursor on display18510 // @0d5 #876: ADD(s5,16) ;on line 13022b // @0d6 #877: CALL(LCD_cursor)2a000 // @0d7 #878: RETURN// #879: ;// @0d8 #880: [display_3_digits]00303 // @0d8 #880: LOAD(s3,3) ;3 digits to display// @0d9 #881: [threedigit_loop]07520 // @0d9 #881: FETCH(s5,s2)300df // @0da #882: CALL(display_digit)1c201 // @0db #883: SUB(s2,1) ;decrement digit pointer1c301 // @0dc #884: SUB(s3,1) ;count digits displayed354d9 // @0dd #885: JUMP(NZ,threedigit_loop)2a000 // @0de #886: RETURN// #887: ;// @0df #888: [display_digit]18530 // @0df #888: ADD(s5,48) ;convert BCD to ASCII character301eb // @0e0 #889: CALL(LCD_write_data)2a000 // @0e1 #890: RETURN// #891: ;// @0e2 #892: [display_space]00520 // @0e2 #892: LOAD(s5,character_space)301eb // @0e3 #893: CALL(LCD_write_data)2a000 // @0e4 #894: RETURN// #895: ;// #896: ;// #897: ;**************************************************************************************// #898: ; Convert 9 digit BCD frequency into 32-bit binary integer// #899: ;**************************************************************************************// #900: ;// #901: ;Both values are stored in scratch pad memory// #902: ;    BCD values in ascending locations BCD_digit0 to BCD_digit8// #903: ;    Binary frequency in ascending locations frequency0 to frequency3// #904: ;// #905: ;Each digit is read in turn and its value is determined by repeated// #906: ;decrement until reaching zero. Each decrement causes a value to be added// #907: ;to the memory locations forming the frequency value as binary integer.// #908: ;The process requires approximately 1600 instructions to convert the highest// #909: ;value 999,999,999 which is approximately 64us at 50MHz clock rate.// #910: ;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?