adc_ctrl.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,582 行 · 第 1/5 页
RMH
1,582 行
01570 // @10b #700: LOAD(s5,s7)00600 // @10c #701: LOAD(s6,0) ;clear result00700 // @10d #702: LOAD(s7,0)00200 // @10e #703: LOAD(s2,0) ;initialise '10' value into msb's of set [s3,s2]003a0 // @10f #704: LOAD(s3,A0)0010d // @110 #705: LOAD(s1,13) ;13 subtract and shift iterations to be performed// @111 #706: [div10_loop]1d420 // @111 #706: SUB(s4,s2) ;perform 16-bit subtract [s5,s4]-[s3,s2]1f530 // @112 #707: SUBCY(s5,s3)35916 // @113 #708: JUMP(C,div10_restore)20607 // @114 #709: SL1(s6) ;shift '1' into result because subtract was possible34119 // @115 #710: JUMP(div10_shifts)// @116 #711: [div10_restore]19420 // @116 #711: ADD(s4,s2) ;perform 32-bit addition [s5,s4]+[s3,s2]1b530 // @117 #712: ADDCY(s5,s3) ;to restore value20606 // @118 #713: SL0(s6) ;shift '0' into result because subtract was not possible// @119 #714: [div10_shifts]20700 // @119 #714: SLA(s7) ;complete 16-bit shift left2030e // @11a #715: SR0(s3) ;divide '10' value by 2 (shift right 1 place)20208 // @11b #716: SRA(s2)1c101 // @11c #717: SUB(s1,1) ;count iterations35511 // @11d #718: JUMP(NZ,div10_loop)2a000 // @11e #719: RETURN// #720: ;// #721: ;// #722: ;**************************************************************************************// #723: ;SPI communication routines for Spartan-3E Starter Kit// #724: ;**************************************************************************************// #725: ;// #726: ;These routines will work with two output ports and one input port which should be// #727: ;defined as follows using CONSTANT directives.// #728: ; (replace 'pp' with appropriate port address in each case)// #729: ;In the list of CONSTANT directives, there are ports associated with all the SPI devices// #730: ;provided on the board. Even if some devices are not used, it is vital that the remaining// #731: ;devices are disabled. Leaving all signals connected and use of these routines will ensure// #732: ;that all other devices are disabled when communicating with a particular device.// #733: ;// #734: ;// #735: ;// #736: ;CONSTANT SPI_control_port, pp ;SPI clock and chip selects// #737: ;CONSTANT SPI_sck, 01 ; SCK - bit0// #738: ;CONSTANT SPI_rom_cs, 02 ; serial rom select - bit1// #739: ;CONSTANT SPI_spare_control, 04 ; spare - bit2// #740: ;CONSTANT SPI_amp_cs, 08 ; amplifier select - bit3// #741: ;CONSTANT SPI_adc_conv, 10 ; A/D convert - bit4// #742: ;CONSTANT SPI_dac_cs, 20 ; D/A select - bit5// #743: ;CONSTANT SPI_amp_shdn, 40 ; amplifier SHDN - bit6// #744: ;CONSTANT SPI_dac_clr, 80 ; D/A clear - bit7// #745: ;// #746: ;CONSTANT SPI_output_port, pp ;SPI data output// #747: ;CONSTANT SPI_sdo, 80 ; SDO - bit7// #748: ;// #749: ;CONSTANT SPI_input_port, pp ;SPI data input// #750: ;CONSTANT SPI_sdi, 80 ; SDI - bit7// #751: ;CONSTANT SPI_amp_sdi, 40 ; amplifier SDI - bit6// #752: ;// #753: ;// #754: ;// #755: ;// #756: ;Initialise SPI bus// #757: ;// #758: ;This routine should be used to initialise the SPI bus.// #759: ;The SCK clock is made low.// #760: ;Device selections are made inactive as follows// #761: ; SPI_sck = 0 Clock is Low (required)// #762: ; SPI_rom_cs = 1 Deselect ROM// #763: ; spare = 1 spare control bit// #764: ; SPI_amp_cs = 1 Deselect amplifier// #765: ; SPI_adc_conv = 0 A/D convert ready to apply positive pulse// #766: ; SPI_dac_cs = 1 Deselect D/A// #767: ; SPI_amp_shdn = 0 Amplifier active and available// #768: ; SPI_dac_clr = 1 D/A clear off// #769: ;// @11f #770: [SPI_init]000ae // @11f #770: LOAD(s0,AE) ;normally AE2c008 // @120 #771: OUTPUT(s0,SPI_control_port)2a000 // @121 #772: RETURN// #773: ;// #774: ;// #775: ;// #776: ;// #777: ;**************************************************************************************// #778: ;SPI communication routines for Programmable Amplifier// #779: ;**************************************************************************************// #780: ;// #781: ;// #782: ;Set the A and B channel gain of the Dual Amplifier (LTC6912-1).// #783: ;// #784: ;The gain value should be provided in the s2 register with the upper nibble// #785: ;defining the gain for the B channel and lower nibble the gain for the A channel.// #786: ; 0000 = 0 hex = Gain 0 with input hi-Z and output driving// #787: ; 0001 = 1 hex = Gain -1// #788: ; 0010 = 2 hex = Gain -2// #789: ; 0011 = 3 hex = Gain -5// #790: ; 0100 = 4 hex = Gain -10// #791: ; 0101 = 5 hex = Gain -20// #792: ; 0110 = 6 hex = Gain -50// #793: ; 0111 = 7 hex = Gain -100// #794: ; 1000 = 8 hex = software shutdown (power on default). Hi-Z output.// #795: ;// #796: ;On return, the s2, register will contain the response from the LTC6912-1 amplifier.// #797: ;This will be the same format and indicate the previous setting of the amplifier.// #798: ;The response is obtained from the dedicated AMP_SDI signal since the LTC6912 output// #799: ;is always active and can not be on a shared SPI bus.// #800: ;// @122 #801: [set_amp]3011f // @122 #801: CALL(SPI_init) ;ensure known state of bus and s0 register0e008 // @123 #802: XOR(s0,SPI_amp_cs) ;select low on Amplifier chip select2c008 // @124 #803: OUTPUT(s0,SPI_control_port)00108 // @125 #804: LOAD(s1,8) ;8-bits to transmit and receive// @126 #805: [next_amp_SPI_bit]2c204 // @126 #805: OUTPUT(s2,SPI_output_port) ;output data bit0e001 // @127 #806: XOR(s0,SPI_sck) ;clock High (bit0)2c008 // @128 #807: OUTPUT(s0,SPI_control_port) ;drive clock High04301 // @129 #808: INPUT(s3,SPI_input_port) ;read input bit12340 // @12a #809: TEST(s3,SPI_amp_sdi) ;detect state of received bit20200 // @12b #810: SLA(s2) ;shift new data into result and move to next transmit bit0e001 // @12c #811: XOR(s0,SPI_sck) ;clock Low (bit0)2c008 // @12d #812: OUTPUT(s0,SPI_control_port) ;drive clock Low1c101 // @12e #813: SUB(s1,1) ;count bits35526 // @12f #814: JUMP(NZ,next_amp_SPI_bit) ;repeat until finished0e008 // @130 #815: XOR(s0,SPI_amp_cs) ;deselect the amplifier2c008 // @131 #816: OUTPUT(s0,SPI_control_port)2a000 // @132 #817: RETURN// #818: ;// #819: ;// #820: ;// #821: ;**************************************************************************************// #822: ;SPI communication routines for A/D Converter// #823: ;**************************************************************************************// #824: ;// #825: ;// #826: ;// #827: ;Sample A/D converter (LTC1407A-1) and return results.// #828: ;// #829: ;Note there is a latency of one read to obtain the value. Each read results in the// #830: ;the analogue inputs being sampled and converted but this value will only be transmitted// #831: ;during the next read and conversion cycle.// #832: ;// #833: ;The results are returned as follows.// #834: ; Channel 0 in registers [s9,s8]// #835: ; Channel 1 in registers [s7,s6]// #836: ;Where each is a 14-bit twos complement value sign extended to 16-bits.// #837: ;// #838: ;Each 14-bit value represents the analogue voltage in the range -1.25v to +1.25v// #839: ;relative to the reference voltage of 1.65v (3.3v/2). Hence the actual input voltage// #840: ;range is 0.4v to 2.9v. Since the input to the A/D is supplied via the programmable// #841: ;amplifier, the VINA and VINB inputs are inverted and may cover a smaller range if ;// #842: ;desired.// #843: ;// #844: ;Examples// #845: ; VINA = 0.65v with gain=-1 means input to A/D = 2.65v// #846: ; This is equivalent to +1.00v which is value (8192/1.25)*1 = 6553 (1999 hex)// #847: ;// #848: ; VINA = 2.65v with gain=-1 means input to A/D = 0.65v// #849: ; This is equivalent to -1.00v which is value (2048/1.25)*-1 = -6553 (E667 hex)// #850: ;// #851: ;// #852: ;Although the A/D converter claims to be an SPI device, it really// #853: ;does not conform to the normal specification of the 4-wire interface.// #854: ;// #855: ;Firstly the CONV signal is only pulsed High and does not behave like// #856: ;a normal active low select signal. Secondly, the communication is// #857: ;34 bits which does not fit a byte boundary, and thirdly, the data output// #858: ;to its SDO pin changes as a result of rising edges of SCK clock which// #859: ;is not the same as the falling edge used by other devices.// #860: ;// @133 #861: [adc_read]3011f // @133 #861: CALL(SPI_init) ;ensure known state of bus and s0 register0e010 // @134 #862: XOR(s0,SPI_adc_conv) ;Pulse AD-CONV High to take sample and start2c008 // @135 #863: OUTPUT(s0,SPI_control_port) ; conversion and transmission of data.0e010 // @136 #864: XOR(s0,SPI_adc_conv) ;AD-CONV Low2c008 // @137 #865: OUTPUT(s0,SPI_control_port)00122 // @138 #866: LOAD(s1,34) ;34 clocks to read all data// @139 #867: [next_adc_bit]0e001 // @139 #867: XOR(s0,SPI_sck) ;clock High (bit0)2c008 // @13a #868: OUTPUT(s0,SPI_control_port) ;drive clock High0e001 // @13b #869: XOR(s0,SPI_sck) ;clock Low (bit0)2c008 // @13c #870: OUTPUT(s0,SPI_control_port) ;drive clock Low04301 // @13d #871: INPUT(s3,SPI_input_port) ;read input bit12380 // @13e #872: TEST(s3,SPI_sdi) ;detect state of received bit20600 // @13f #873: SLA(s6) ;shift new data into result registers20700 // @140 #874: SLA(s7)20800 // @141 #875: SLA(s8)20900 // @142 #876: SLA(s9)1c101 // @143 #877: SUB(s1,1) ;count bits35539 // @144 #878: JUMP(NZ,next_adc_bit) ;repeat until finished2090a // @145 #879: SRX(s9) ;sign extend 14-bit result in [s9,s8]20808 // @146 #880: SRA(s8)2090a // @147 #881: SRX(s9)20808 // @148 #882: SRA(s8)2070a // @149 #883: SRX(s7) ;sign extend 14-bit result in [s7,s6]20608 // @14a #884: SRA(s6)2070a // @14b #885: SRX(s7)20608 // @14c #886: SRA(s6)2a000 // @14d #887: RETURN// #888: ;// #889: ;// #890: ;**************************************************************************************// #891: ;LCD text messages// #892: ;**************************************************************************************// #893: ;// #894: ;// #895: ;Display 'PicoBlaze' on LCD at current cursor position// #896: ;// #897: ;// @14e #898: [disp_PicoBlaze]00550 // @14e #898: LOAD(s5,character_P)301d1 // @14f #899: CALL(LCD_write_data)00569 // @150 #900: LOAD(s5,character_i)301d1 // @151 #901: CALL(LCD_write_data)00563 // @152 #902: LOAD(s5,character_c)301d1 // @153 #903: CALL(LCD_write_data)0056f // @154 #904: LOAD(s5,character_o)301d1 // @155 #905: CALL(LCD_write_data)00542 // @156 #906: LOAD(s5,character_B)301d1 // @157 #907: CALL(LCD_write_data)0056c // @158 #908: LOAD(s5,character_l)301d1 // @159 #909: CALL(LCD_write_data)00561 // @15a #910: LOAD(s5,character_a)301d1 // @15b #911: CALL(LCD_write_data)0057a // @15c #912: LOAD(s5,character_z)301d1 // @15d #913: CALL(LCD_write_data)00565 // @15e #914: LOAD(s5,character_e)301d1 // @15f #915: CALL(LCD_write_data)2a000 // @160 #916: RETURN// #917: ;// #918: ;// #919: ;Display 'ADC Control' on LCD at current cursor position// #920: ;// #921: ;// @161 #922: [disp_ADC_Control]00541 // @161 #922: LOAD(s5,character_A)301d1 // @162 #923: CALL(LCD_write_data)00544 // @163 #924: LOAD(s5,character_D)301d1 // @164 #925: CALL(LCD_write_data)00543 // @165 #926: LOAD(s5,character_C)301d1 // @166 #927: CALL(LCD_write_data)00520 // @167 #928: LOAD(s5,character_space)301d1 // @168 #929: CALL(LCD_write_data)00543 // @169 #930: LOAD(s5,character_C)301d1 // @16a #931: CALL(LCD_write_data)0056f // @16b #932: LOAD(s5,character_o)301d1 // @16c #933: CALL(LCD_write_data)0056e // @16d #934: LOAD(s5,character_n)301d1 // @16e #935: CALL(LCD_write_data)00574 // @16f #936: LOAD(s5,character_t)301d1 // @170 #937: CALL(LCD_write_data)00572 // @171 #938: LOAD(s5,character_r)301d1 // @172 #939: CALL(LCD_write_data)0056f // @173 #940: LOAD(s5,character_o)301d1 // @174 #941: CALL(LCD_write_data)0056c // @175 #942: LOAD(s5,character_l)301d1 // @176 #943: CALL(LCD_write_data)2a000 // @177 #944: RETURN// #945: ;// #946: ;// #947: ;Display 'VA=' on LCD at current cursor position// #948: ;// #949: ;// @178 #950: [disp_VA]00556 // @178 #950: LOAD(s5,character_V)301d1 // @179 #951: CALL(LCD_write_data)00541 // @17a #952: LOAD(s5,character_A)301d1 // @17b #953: CALL(LCD_write_data)0053d // @17c #954: LOAD(s5,character_equals)301d1 // @17d #955: CALL(LCD_write_data)2a000 // @17e #956: RETURN// #957: ;// #958: ;// #959: ;Display 'A/D' on LCD at current cursor position// #960: ;// #961: ;// @17f #962: [disp_AD]00541 // @17f #962: LOAD(s5,character_A)301d1 // @180 #963: CALL(LCD_write_data)0052f // @181 #964: LOAD(s5,character_divide)301d1 // @182 #965: CALL(LCD_write_data)00544 // @183 #966: LOAD(s5,character_D)301d1 // @184 #967: CALL(LCD_write_data)0053d // @185 #968: LOAD(s5,character_equals)301d1 // @186 #969: CALL(LCD_write_data)2a000 // @187 #970: RETURN// #971: ;// #972: ;// #973: ;// #974: ;**************************************************************************************// #975: ;Value to ASCII Conversions and LCD display// #976: ;**************************************************************************************// #977: ;// #978: ;Convert hexadecimal value provided in register s0 into ASCII characters// #979: ;// #980: ;The value provided must can be any value in the range 00 to FF and will be converted into// #981: ;two ASCII characters.// #982: ; The upper nibble will be represented by an ASCII character returned in register s2.// #983: ; The lower nibble will be represented by an ASCII character returned in register s1.// #984: ;// #985: ;The ASCII representations of '0' to '9' are 30 to 39 hexadecimal which is simply 30 hex// #986: ;added to the actual decimal value. The ASCII representations of 'A' to 'F' are 41 to 46// #987: ;hexadecimal requiring a further addition of 07 to the 30 already added.// #988: ;// #989: ;Registers used s0, s1 and s2.// #990: ;// @188 #991: [hex_byte_to_ASCII]01100 // @188 #991: LOAD(s1,s0) ;remember value supplied2000e // @189 #992: SR0(s0) ;isolate upper nibble2000e // @18a #993: SR0(s0)2000e // @18b #994: SR0(s0)2000e // @18c #995: SR0(s0)30194 // @18d #996: CALL(hex_to_ASCII) ;convert01200 // @18e #997: LOAD(s2,s0) ;upper nibble value in s201010 // @18f #998: LOAD(s0,s1) ;restore complete value0a00f // @190 #999: AND(s0,15) ;isolate lower nibble30194 // @191 #1000: CALL(hex_to_ASCII) ;convert01100 // @192 #1001: LOAD(s1,s0) ;lower nibble value in s12a000 // @193 #1002: RETURN// #1003: ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?