adc_ctrl.rmh

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

RMH
1,582
字号
// #405: ;      -50            -200   (FF38)// #406: ;     -100            -100   (FF9C)// #407: ;06200 // @03d #408: FETCH(s2,ADC0_lsb) ;Read A/D channel 0 value06301 // @03e #409: FETCH(s3,ADC0_msb)06404 // @03f #410: FETCH(s4,amp_A_gain) ;read A gain and select appropiate gain setting000ef // @040 #411: LOAD(s0,EF) ;scaling value for amplifier gain of -1001d8 // @041 #412: LOAD(s1,D8)14401 // @042 #413: COMPARE(s4,1)3505a // @043 #414: JUMP(Z,mult_VINA)00077 // @044 #415: LOAD(s0,119) ;scaling value for amplifier gain of -2001ec // @045 #416: LOAD(s1,EC)14402 // @046 #417: COMPARE(s4,2)3505a // @047 #418: JUMP(Z,mult_VINA)00030 // @048 #419: LOAD(s0,48) ;scaling value for amplifier gain of -5001f8 // @049 #420: LOAD(s1,F8)14403 // @04a #421: COMPARE(s4,3)3505a // @04b #422: JUMP(Z,mult_VINA)00018 // @04c #423: LOAD(s0,24) ;scaling value for amplifier gain of -10001fc // @04d #424: LOAD(s1,FC)14405 // @04e #425: COMPARE(s4,5)3505a // @04f #426: JUMP(Z,mult_VINA)0000c // @050 #427: LOAD(s0,12) ;scaling value for amplifier gain of -20001fe // @051 #428: LOAD(s1,FE)14406 // @052 #429: COMPARE(s4,6)3505a // @053 #430: JUMP(Z,mult_VINA)00038 // @054 #431: LOAD(s0,56) ;scaling value for amplifier gain of -50001ff // @055 #432: LOAD(s1,FF)14401 // @056 #433: COMPARE(s4,1)3505a // @057 #434: JUMP(Z,mult_VINA)0009c // @058 #435: LOAD(s0,156) ;scaling value for amplifier gain of -100001ff // @059 #436: LOAD(s1,FF)// @05a #437: [mult_VINA]300e4 // @05a #437: CALL(mult_16x16s) ;[s7,s6,s5,s4]=[s3,s2]x[s1,s0]20506 // @05b #438: SL0(s5) ;round value before truncation1a600 // @05c #439: ADDCY(s6,0)1a700 // @05d #440: ADDCY(s7,0)18672 // @05e #441: ADD(s6,VREF_lsb) ;add 1.65v offset represented at 1650 (0672 hex)1a706 // @05f #442: ADDCY(s7,VREF_msb)// #443: ;// #444: ;The register pair [s7,s6] now holds the binary value// #445: ;representing the VINA input level in milli-volts.// #446: ;This must be a positive value due to the offset of 1.65v// #447: ;being greater than the maximum relative range of -1.25v to +1.25v.// #448: ;This binary value can now be converted to a decimal digits// #449: ;and displayed on the LCD.// #450: ;// #451: ;If the A/D value is maximum negative (E000) or maximum positive (1FFF)// #452: ;then an indication of the actual value being applied being greater or// #453: ;less than that computed will be made.// #454: ;00517 // @060 #455: LOAD(s5,23) ;Line 1 position 730211 // @061 #456: CALL(LCD_cursor)30178 // @062 #457: CALL(disp_VA) ;display VA=06200 // @063 #458: FETCH(s2,ADC0_lsb) ;Read A/D channel 0 value06301 // @064 #459: FETCH(s3,ADC0_msb)143e0 // @065 #460: COMPARE(s3,E0) ;test for maximum negative3546c // @066 #461: JUMP(NZ,test_max_pos)14200 // @067 #462: COMPARE(s2,0)3546c // @068 #463: JUMP(NZ,test_max_pos)0053e // @069 #464: LOAD(s5,character_greater_than) ;display >301d1 // @06a #465: CALL(LCD_write_data)34072 // @06b #466: JUMP(disp_VINA_volts)// @06c #467: [test_max_pos]1431f // @06c #467: COMPARE(s3,31) ;test for maximum positive35472 // @06d #468: JUMP(NZ,disp_VINA_volts)142ff // @06e #469: COMPARE(s2,FF)35472 // @06f #470: JUMP(NZ,disp_VINA_volts)0053c // @070 #471: LOAD(s5,character_less_than) ;display <301d1 // @071 #472: CALL(LCD_write_data)// @072 #473: [disp_VINA_volts]30074 // @072 #473: CALL(disp_volts) ;display 4 digit value as X.XXXv34014 // @073 #474: JUMP(warm_start)// #475: ;// #476: ;// #477: ;**************************************************************************************// #478: ;Display voltage level at in the form X.XXX on the LCD at current cursor position// #479: ;**************************************************************************************// #480: ;// #481: ;Value to be displayed must be unsigned (positive) in the// #482: ;[s7,s6] register pair. Only the lower 4 digits are displayed.// #483: ;// @074 #484: [disp_volts]30102 // @074 #484: CALL(integer16_to_BCD) ;convert [s7,s6] to BCD in scratch pad memory0650a // @075 #485: FETCH(s5,decimal3)18530 // @076 #486: ADD(s5,48) ;convert to ASCII301d1 // @077 #487: CALL(LCD_write_data)0052e // @078 #488: LOAD(s5,character_stop)301d1 // @079 #489: CALL(LCD_write_data)06509 // @07a #490: FETCH(s5,decimal2)18530 // @07b #491: ADD(s5,48) ;convert to ASCII301d1 // @07c #492: CALL(LCD_write_data)06508 // @07d #493: FETCH(s5,decimal1)18530 // @07e #494: ADD(s5,48) ;convert to ASCII301d1 // @07f #495: CALL(LCD_write_data)06507 // @080 #496: FETCH(s5,decimal0)18530 // @081 #497: ADD(s5,48) ;convert to ASCII301d1 // @082 #498: CALL(LCD_write_data)00520 // @083 #499: LOAD(s5,character_space) ;ensure next position is cleared301d1 // @084 #500: CALL(LCD_write_data)2a000 // @085 #501: RETURN// #502: ;// #503: ;**************************************************************************************// #504: ;Changing amplifier gain using press buttons// #505: ;**************************************************************************************// #506: ;// #507: ;Possible gain values are// #508: ;   Gain   Amplifier// #509: ;            code// #510: ;    -1        1// #511: ;    -2        2// #512: ;    -5        3// #513: ;   -10        4// #514: ;   -20        5// #515: ;   -50        6// #516: ;  -100        7// #517: ;// @086 #518: [gain_increase]3c000 // @086 #518: DISABLE(INTERRUPT) ;stop normal operation06004 // @087 #519: FETCH(s0,amp_A_gain) ;read current gain18001 // @088 #520: ADD(s0,1)14008 // @089 #521: COMPARE(s0,8) ;test for too big35492 // @08a #522: JUMP(NZ,new_gain_set)00007 // @08b #523: LOAD(s0,7) ;maximum gain34092 // @08c #524: JUMP(new_gain_set)// @08d #525: [gain_decrease]3c000 // @08d #525: DISABLE(INTERRUPT) ;stop normal operation06004 // @08e #526: FETCH(s0,amp_A_gain) ;read current gain1c001 // @08f #527: SUB(s0,1)35492 // @090 #528: JUMP(NZ,new_gain_set)00001 // @091 #529: LOAD(s0,1) ;minimum gain// @092 #530: [new_gain_set]2e004 // @092 #530: STORE(s0,amp_A_gain) ;store new value06205 // @093 #531: FETCH(s2,amp_B_gain) ;form the amplifier control byte20206 // @094 #532: SL0(s2) ;B amplifier set by upper 4 bits20206 // @095 #533: SL0(s2)20206 // @096 #534: SL0(s2)20206 // @097 #535: SL0(s2)0d200 // @098 #536: OR(s2,s0) ;A amplifier set by lower30122 // @099 #537: CALL(set_amp) ;set SPI amplifier// #538: ;display gain setting on LCD00510 // @09a #539: LOAD(s5,16) ;Line 1 position 030211 // @09b #540: CALL(LCD_cursor)00547 // @09c #541: LOAD(s5,character_G)301d1 // @09d #542: CALL(LCD_write_data)0053d // @09e #543: LOAD(s5,character_equals)301d1 // @09f #544: CALL(LCD_write_data)0052d // @0a0 #545: LOAD(s5,character_minus)301d1 // @0a1 #546: CALL(LCD_write_data)06004 // @0a2 #547: FETCH(s0,amp_A_gain) ;read A gain setting14001 // @0a3 #548: COMPARE(s0,1) ;determine actual gain value354ac // @0a4 #549: JUMP(NZ,test_A2)00531 // @0a5 #550: LOAD(s5,character_1) ;gain is -1301d1 // @0a6 #551: CALL(LCD_write_data)00520 // @0a7 #552: LOAD(s5,character_space)301d1 // @0a8 #553: CALL(LCD_write_data)00520 // @0a9 #554: LOAD(s5,character_space)301d1 // @0aa #555: CALL(LCD_write_data)340df // @0ab #556: JUMP(wait_no_press)// @0ac #557: [test_A2]14002 // @0ac #557: COMPARE(s0,2)354b5 // @0ad #558: JUMP(NZ,test_A3)00532 // @0ae #559: LOAD(s5,character_2) ;gain is -2301d1 // @0af #560: CALL(LCD_write_data)00520 // @0b0 #561: LOAD(s5,character_space)301d1 // @0b1 #562: CALL(LCD_write_data)00520 // @0b2 #563: LOAD(s5,character_space)301d1 // @0b3 #564: CALL(LCD_write_data)340df // @0b4 #565: JUMP(wait_no_press)// @0b5 #566: [test_A3]14003 // @0b5 #566: COMPARE(s0,3)354be // @0b6 #567: JUMP(NZ,test_A4)00535 // @0b7 #568: LOAD(s5,character_5) ;gain is -5301d1 // @0b8 #569: CALL(LCD_write_data)00520 // @0b9 #570: LOAD(s5,character_space)301d1 // @0ba #571: CALL(LCD_write_data)00520 // @0bb #572: LOAD(s5,character_space)301d1 // @0bc #573: CALL(LCD_write_data)340df // @0bd #574: JUMP(wait_no_press)// @0be #575: [test_A4]14004 // @0be #575: COMPARE(s0,4)354c7 // @0bf #576: JUMP(NZ,test_A5)00531 // @0c0 #577: LOAD(s5,character_1) ;gain is -10301d1 // @0c1 #578: CALL(LCD_write_data)00530 // @0c2 #579: LOAD(s5,character_0)301d1 // @0c3 #580: CALL(LCD_write_data)00520 // @0c4 #581: LOAD(s5,character_space)301d1 // @0c5 #582: CALL(LCD_write_data)340df // @0c6 #583: JUMP(wait_no_press)// @0c7 #584: [test_A5]14005 // @0c7 #584: COMPARE(s0,5)354d0 // @0c8 #585: JUMP(NZ,test_A6)00532 // @0c9 #586: LOAD(s5,character_2) ;gain is -20301d1 // @0ca #587: CALL(LCD_write_data)00530 // @0cb #588: LOAD(s5,character_0)301d1 // @0cc #589: CALL(LCD_write_data)00520 // @0cd #590: LOAD(s5,character_space)301d1 // @0ce #591: CALL(LCD_write_data)340df // @0cf #592: JUMP(wait_no_press)// @0d0 #593: [test_A6]14006 // @0d0 #593: COMPARE(s0,6)354d9 // @0d1 #594: JUMP(NZ,gain_A7)00535 // @0d2 #595: LOAD(s5,character_5) ;gain is -50301d1 // @0d3 #596: CALL(LCD_write_data)00530 // @0d4 #597: LOAD(s5,character_0)301d1 // @0d5 #598: CALL(LCD_write_data)00520 // @0d6 #599: LOAD(s5,character_space)301d1 // @0d7 #600: CALL(LCD_write_data)340df // @0d8 #601: JUMP(wait_no_press)// @0d9 #602: [gain_A7]00531 // @0d9 #602: LOAD(s5,character_1) ;gain is -100301d1 // @0da #603: CALL(LCD_write_data)00530 // @0db #604: LOAD(s5,character_0)301d1 // @0dc #605: CALL(LCD_write_data)00530 // @0dd #606: LOAD(s5,character_0)301d1 // @0de #607: CALL(LCD_write_data)// @0df #608: [wait_no_press]301ae // @0df #608: CALL(delay_20ms) ;delay to help avoid switch bounce04000 // @0e0 #609: INPUT(s0,switch_port) ;check for release of press buttons12005 // @0e1 #610: TEST(s0,5) ;north and south buttons354df // @0e2 #611: JUMP(NZ,wait_no_press)34014 // @0e3 #612: JUMP(warm_start)// #613: ;// #614: ;**************************************************************************************// #615: ;16-bit by 16-bit Signed multiplier// #616: ;**************************************************************************************// #617: ;// #618: ;16 bit signed multiplication using shift and add technique.// #619: ;The full precision 32-bit product is returned.// #620: ;// #621: ;The key to signed multiplication is to think of all bits of the second operand// #622: ;[s1,s0] as being positive except for the most significant bit. This means that// #623: ;the first operand is added to the result in all cases when there is a '1' in the// #624: ;second operand except for the MSB case when the first operand is subtracted if there// #625: ;is a '1'.// #626: ;// #627: ;[s7,s6,s5,s4]=[s3,s2]x[s1,s0]// #628: ;// #629: ;Registers used s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sA// #630: ;// @0e4 #631: [mult_16x16s]00700 // @0e4 #631: LOAD(s7,0) ;clear accumulator00600 // @0e5 #632: LOAD(s6,0)00500 // @0e6 #633: LOAD(s5,0) ;Set bit 14 to act as a bit shift counter00400 // @0e7 #634: LOAD(s4,0)00800 // @0e8 #635: LOAD(s8,0) ;sign extend [s3,s2] to form [s9,s8,s3,s2]12380 // @0e9 #636: TEST(s3,128) ;test sign of first operand350ec // @0ea #637: JUMP(Z,m16s_pos)008ff // @0eb #638: LOAD(s8,FF)// @0ec #639: [m16s_pos]01980 // @0ec #639: LOAD(s9,s8) ;[s9,s8,s3,s2]=0000xxxx or FFFFxxxx as required00a0f // @0ed #640: LOAD(sA,15) ;15 positive shift and add operations to perform// @0ee #641: [m16s_loop]2010e // @0ee #641: SR0(s1) ;shift right operand [s1,s0]20008 // @0ef #642: SRA(s0)35cf5 // @0f0 #643: JUMP(NC,m16s_noadd) ;test for a '1'19420 // @0f1 #644: ADD(s4,s2) ;32-bit addition [s7,s6,s5,s4]=[s7,s6,s5,s4]+[s9,s8,s3,s2]1b530 // @0f2 #645: ADDCY(s5,s3)1b680 // @0f3 #646: ADDCY(s6,s8)1b790 // @0f4 #647: ADDCY(s7,s9)// @0f5 #648: [m16s_noadd]20206 // @0f5 #648: SL0(s2) ;multiply first operand by 220300 // @0f6 #649: SLA(s3)20800 // @0f7 #650: SLA(s8)20900 // @0f8 #651: SLA(s9)1ca01 // @0f9 #652: SUB(sA,1)354ee // @0fa #653: JUMP(NZ,m16s_loop) ;move to next unsigned bit12001 // @0fb #654: TEST(s0,1) ;test sign bit of operand [s1,s0]35d01 // @0fc #655: JUMP(NC,m16s_nosub)1d420 // @0fd #656: SUB(s4,s2) ;32-bit subtraction [s7,s6,s5,s4]=[s7,s6,s5,s4]-[s9,s8,s3,s2]1f530 // @0fe #657: SUBCY(s5,s3)1f680 // @0ff #658: SUBCY(s6,s8)1f790 // @100 #659: SUBCY(s7,s9)// @101 #660: [m16s_nosub]2a000 // @101 #660: RETURN// #661: ;// #662: ;// #663: ;// #664: ;**************************************************************************************// #665: ;16-bit positive integer to 5 digit decimal conversion// #666: ;**************************************************************************************// #667: ;// #668: ;Convert the 16 bit value in register set [s7,s6]// #669: ;into the BCD decimal equivalent located in the scratch pad memory// #670: ;locations 'decimal0' to 'decimal4' which must be in ascending locations.// #671: ;// #672: ;Register set [s9,s8,s7,s6] are preserved.// #673: ;// #674: ;// #675: ;Each digit is formed in turn starting with the least significant.// #676: ;// #677: ;Registers used s0,s1,s2,s3,s4,s5,s6,s7,s8// #678: ;// @102 #679: [integer16_to_BCD]00005 // @102 #679: LOAD(s0,5) ;5 digits to be formed from value up to 6553500807 // @103 #680: LOAD(s8,decimal0) ;pointer for LS-Digit// @104 #681: [int_to_BCD_loop]3010a // @104 #681: CALL(divide_16bit_by_10) ;[s7,s6]=[s7,s6]/10  with remainder in s42f480 // @105 #682: STORE(s4,s8) ;remainder becomes digit value18801 // @106 #683: ADD(s8,1) ;move to next most significant digit1c001 // @107 #684: SUB(s0,1) ;one less digit to compute35504 // @108 #685: JUMP(NZ,int_to_BCD_loop)2a000 // @109 #686: RETURN// #687: ;// #688: ;Divide 16-bit binary integer by 10// #689: ;// #690: ;The value to be divided is held in register set [s7,s6]// #691: ;and this is where the result is returned to.// #692: ;// #693: ;At then end of the integer division the remainder in the range 0 to 9// #694: ;will be in register s4.// #695: ;// #696: ;Registers used s1,s2,s3,s4,s5,s6,s7// #697: ;Other registers are used but are preserved// #698: ;// @10a #699: [divide_16bit_by_10]01460 // @10a #699: LOAD(s4,s6) ;copy input value to [s5,s4]

⌨️ 快捷键说明

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