pwm_ctrl.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 966 行 · 第 1/3 页
RMH
966 行
// #450: ;// #451: ;// #452: ; Convert string held in scratch pad memory to upper case.// #453: ;// #454: ; Registers used s0, s1// #455: ;// @08b #456: [upper_case_string]00130 // @08b #456: LOAD(s1,string_start)// @08c #457: [ucs_loop]07010 // @08c #457: FETCH(s0,s1)1400d // @08d #458: COMPARE(s0,character_CR)2b000 // @08e #459: RETURN(Z)30085 // @08f #460: CALL(upper_case)2f010 // @090 #461: STORE(s0,s1)18101 // @091 #462: ADD(s1,1)3408c // @092 #463: JUMP(ucs_loop)// #464: ;// #465: ;// #466: ; Convert character '0' to '9' to numerical value in range 0 to 9// #467: ;// #468: ; The character supplied in register s0. If the character is in the// #469: ; range '0' to '9', it is converted to the equivalent decimal value.// #470: ; Characters not in the range '0' to '9' are signified by the return// #471: ; with the CARRY flag set.// #472: ;// #473: ; Registers used s0.// #474: ;// @093 #475: [onechar_to_value]180c6 // @093 #475: ADD(s0,C6) ;reject character codes above '9' (39 hex)2b800 // @094 #476: RETURN(C) ;carry flag is set1c0f6 // @095 #477: SUB(s0,F6) ;reject character codes below '0' (30 hex)2a000 // @096 #478: RETURN ;carry is set if value not in range// #479: ;// #480: ;// #481: ;// #482: ; Convert the HEX ASCII characters contained in 's3' and 's2' into// #483: ; an equivalent hexadecimal value in register 's0'.// #484: ; The upper nibble is represented by an ASCII character in register s3.// #485: ; The lower nibble is represented by an ASCII character in register s2.// #486: ;// #487: ; Input characters must be in the range 00 to FF hexadecimal or the CARRY flag// #488: ; will be set on return.// #489: ;// #490: ; Registers used s0, s2 and s3.// #491: ;// @097 #492: [ASCII_byte_to_hex]01030 // @097 #492: LOAD(s0,s3) ;Take upper nibble300a4 // @098 #493: CALL(ASCII_to_hex) ;convert to value2b800 // @099 #494: RETURN(C) ;reject if out of range01300 // @09a #495: LOAD(s3,s0) ;remember value20306 // @09b #496: SL0(s3) ;multiply value by 16 to put in upper nibble20306 // @09c #497: SL0(s3)20306 // @09d #498: SL0(s3)20306 // @09e #499: SL0(s3)01020 // @09f #500: LOAD(s0,s2) ;Take lower nibble300a4 // @0a0 #501: CALL(ASCII_to_hex) ;convert to value2b800 // @0a1 #502: RETURN(C) ;reject if out of range0d030 // @0a2 #503: OR(s0,s3) ;merge in the upper nibble with CARRY reset2a000 // @0a3 #504: RETURN// #505: ;// #506: ;// #507: ; Routine to convert ASCII data in 's0' to an equivalent HEX value.// #508: ;// #509: ; If character is not valid for hex, then CARRY is set on return.// #510: ;// #511: ; Register used s0// #512: ;// @0a4 #513: [ASCII_to_hex]180b9 // @0a4 #513: ADD(s0,B9) ;test for above ASCII code 46 ('F')2b800 // @0a5 #514: RETURN(C)1c0e9 // @0a6 #515: SUB(s0,E9) ;normalise 0 to 9 with A-F in 11 to 16 hex2b800 // @0a7 #516: RETURN(C) ;reject below ASCII code 30 ('0')1c011 // @0a8 #517: SUB(s0,17) ;isolate A-F down to 00 to 05 hex35cae // @0a9 #518: JUMP(NC,ASCII_letter)18007 // @0aa #519: ADD(s0,7) ;test for above ASCII code 46 ('F')2b800 // @0ab #520: RETURN(C)1c0f6 // @0ac #521: SUB(s0,F6) ;convert to range 00 to 092a000 // @0ad #522: RETURN// @0ae #523: [ASCII_letter]1800a // @0ae #523: ADD(s0,10) ;convert to range 0A to 0F2a000 // @0af #524: RETURN// #525: ;// #526: ;// #527: ;// #528: ;**************************************************************************************// #529: ; Text messages// #530: ;**************************************************************************************// #531: ;// #532: ;// #533: ; Send Carriage Return to the UART// #534: ;// @0b0 #535: [send_CR]00f0d // @0b0 #535: LOAD(UART_data,character_CR)3005d // @0b1 #536: CALL(send_to_UART)2a000 // @0b2 #537: RETURN// #538: ;// #539: ; Send a space to the UART// #540: ;// @0b3 #541: [send_space]00f20 // @0b3 #541: LOAD(UART_data,character_space)3005d // @0b4 #542: CALL(send_to_UART)2a000 // @0b5 #543: RETURN// #544: ;// #545: ;// #546: ;// #547: ;Send a back space to the UART// #548: ;// @0b6 #549: [send_backspace]00f08 // @0b6 #549: LOAD(UART_data,character_BS)3005d // @0b7 #550: CALL(send_to_UART)2a000 // @0b8 #551: RETURN// #552: ;// #553: ;// #554: ; Send 'PicoBlaze Servo Control' string to the UART// #555: ;// @0b9 #556: [send_welcome]300b0 // @0b9 #556: CALL(send_CR)300b0 // @0ba #557: CALL(send_CR)00f50 // @0bb #558: LOAD(UART_data,character_P)3005d // @0bc #559: CALL(send_to_UART)00f69 // @0bd #560: LOAD(UART_data,character_i)3005d // @0be #561: CALL(send_to_UART)00f63 // @0bf #562: LOAD(UART_data,character_c)3005d // @0c0 #563: CALL(send_to_UART)00f6f // @0c1 #564: LOAD(UART_data,character_o)3005d // @0c2 #565: CALL(send_to_UART)00f42 // @0c3 #566: LOAD(UART_data,character_B)3005d // @0c4 #567: CALL(send_to_UART)00f6c // @0c5 #568: LOAD(UART_data,character_l)3005d // @0c6 #569: CALL(send_to_UART)00f61 // @0c7 #570: LOAD(UART_data,character_a)3005d // @0c8 #571: CALL(send_to_UART)00f7a // @0c9 #572: LOAD(UART_data,character_z)3005d // @0ca #573: CALL(send_to_UART)00f65 // @0cb #574: LOAD(UART_data,character_e)3005d // @0cc #575: CALL(send_to_UART)300b3 // @0cd #576: CALL(send_space)00f50 // @0ce #577: LOAD(UART_data,character_P)3005d // @0cf #578: CALL(send_to_UART)00f57 // @0d0 #579: LOAD(UART_data,character_W)3005d // @0d1 #580: CALL(send_to_UART)00f4d // @0d2 #581: LOAD(UART_data,character_M)3005d // @0d3 #582: CALL(send_to_UART)300b3 // @0d4 #583: CALL(send_space)00f43 // @0d5 #584: LOAD(UART_data,character_C)3005d // @0d6 #585: CALL(send_to_UART)00f6f // @0d7 #586: LOAD(UART_data,character_o)3005d // @0d8 #587: CALL(send_to_UART)00f6e // @0d9 #588: LOAD(UART_data,character_n)3005d // @0da #589: CALL(send_to_UART)00f74 // @0db #590: LOAD(UART_data,character_t)3005d // @0dc #591: CALL(send_to_UART)00f72 // @0dd #592: LOAD(UART_data,character_r)3005d // @0de #593: CALL(send_to_UART)00f6f // @0df #594: LOAD(UART_data,character_o)3005d // @0e0 #595: CALL(send_to_UART)00f6c // @0e1 #596: LOAD(UART_data,character_l)3005d // @0e2 #597: CALL(send_to_UART)300b0 // @0e3 #598: CALL(send_CR)300b0 // @0e4 #599: CALL(send_CR)2a000 // @0e5 #600: RETURN// #601: ;// #602: ;// #603: ;Send 'KCPSM3>' prompt to the UART// #604: ;// @0e6 #605: [send_prompt]300b0 // @0e6 #605: CALL(send_CR) ;start new line00f4b // @0e7 #606: LOAD(UART_data,character_K)3005d // @0e8 #607: CALL(send_to_UART)00f43 // @0e9 #608: LOAD(UART_data,character_C)3005d // @0ea #609: CALL(send_to_UART)00f50 // @0eb #610: LOAD(UART_data,character_P)3005d // @0ec #611: CALL(send_to_UART)00f53 // @0ed #612: LOAD(UART_data,character_S)3005d // @0ee #613: CALL(send_to_UART)00f4d // @0ef #614: LOAD(UART_data,character_M)3005d // @0f0 #615: CALL(send_to_UART)00f33 // @0f1 #616: LOAD(UART_data,character_3)3005d // @0f2 #617: CALL(send_to_UART)// #618: ;// #619: ;Send '>' character to the UART// #620: ;// @0f3 #621: [send_greater_than]00f3e // @0f3 #621: LOAD(UART_data,character_greater_than)3005d // @0f4 #622: CALL(send_to_UART)2a000 // @0f5 #623: RETURN// #624: ;// #625: ;// #626: ;Send 'Overflow Error' to the UART// #627: ;// @0f6 #628: [send_Overflow_Error]00f4f // @0f6 #628: LOAD(UART_data,character_O)3005d // @0f7 #629: CALL(send_to_UART)00f76 // @0f8 #630: LOAD(UART_data,character_v)3005d // @0f9 #631: CALL(send_to_UART)00f65 // @0fa #632: LOAD(UART_data,character_e)3005d // @0fb #633: CALL(send_to_UART)00f72 // @0fc #634: LOAD(UART_data,character_r)3005d // @0fd #635: CALL(send_to_UART)00f66 // @0fe #636: LOAD(UART_data,character_f)3005d // @0ff #637: CALL(send_to_UART)00f6c // @100 #638: LOAD(UART_data,character_l)3005d // @101 #639: CALL(send_to_UART)00f6f // @102 #640: LOAD(UART_data,character_o)3005d // @103 #641: CALL(send_to_UART)00f77 // @104 #642: LOAD(UART_data,character_w)3005d // @105 #643: CALL(send_to_UART)// @106 #644: [send_space_Error]300b3 // @106 #644: CALL(send_space)// #645: ;// #646: ;Send 'Error' to the UART// #647: ;// @107 #648: [send_Error]00f45 // @107 #648: LOAD(UART_data,character_E)3005d // @108 #649: CALL(send_to_UART)00f72 // @109 #650: LOAD(UART_data,character_r)3005d // @10a #651: CALL(send_to_UART)3005d // @10b #652: CALL(send_to_UART)00f6f // @10c #653: LOAD(UART_data,character_o)3005d // @10d #654: CALL(send_to_UART)00f72 // @10e #655: LOAD(UART_data,character_r)3005d // @10f #656: CALL(send_to_UART)340b0 // @110 #657: JUMP(send_CR)// #658: ;// #659: ;// #660: ;Send 'OK' to the UART// #661: ;// @111 #662: [send_OK]300b0 // @111 #662: CALL(send_CR)00f4f // @112 #663: LOAD(UART_data,character_O)3005d // @113 #664: CALL(send_to_UART)00f4b // @114 #665: LOAD(UART_data,character_K)3005d // @115 #666: CALL(send_to_UART)340b0 // @116 #667: JUMP(send_CR)// #668: ;// #669: ;// #670: ;**************************************************************************************// #671: ; Interrupt Service Routine (ISR)// #672: ;**************************************************************************************// #673: ;// #674: ; Interrupts occur at 3.92us intervals and are used to generate the PWM pulses generated// #675: ; at a PRF of 1KHz. The 3.92us interrupt rate corresponds with a resolution of 256 steps// #676: ; over the 1ms associated with the 1KHz PRF.// #677: ;// #678: ; The ISR is self contained and all registers used are preserved. Scratch pad memory// #679: ; locations are used to determine the desired duty factor for each of 12 channels.// #680: ;// #681: ; Note that an interrupt is generated every 196 clock cycles. This means that there is// #682: ; only time to execute 98 instructions between each interrupt. This ISR is 48 instructions// #683: ; long. A further 3 instructions are also consumed by the interrupt process// #684: ; (abandoned instruction, virtual CALL to 3FF and the interrupt vector JUMP) and hence// #685: ; PicoBlaze has approximately half of its time available for other tasks in the main program.// #686: ;// #687: ; Although a loop would normal be employed in software to process each of 12 channels,// #688: ; the implementation of a loop would increase the number of instructions which needed to// #689: ; be executed to such an extent that this 12 channel implementation would not be possible.// #690: ; Consequently the code is written out in a linear fashion which consumes more program// #691: ; space but which executes faster.// #692: ;// @117 #693: [ISR]2e00d // @117 #693: STORE(s0,ISR_preserve_s0) ;preserve registers to be used2e10e // @118 #694: STORE(s1,ISR_preserve_s1)2e20f // @119 #695: STORE(s2,ISR_preserve_s2)// #696: ;Determine the number of steps currently through the 1ms PWM cycle06100 // @11a #697: FETCH(s1,PWM_duty_counter) ;read 8-bit counter of steps18101 // @11b #698: ADD(s1,1) ;increment counter (will roll over to zero)2e100 // @11c #699: STORE(s1,PWM_duty_counter) ;update count value in memory for next interrupt.// #700: ;Read duty factor for each channel and compare it with the duty counter and set or// #701: ;reset a bit in register s2 accordingly.0600c // @11d #702: FETCH(s0,PWM_channel11) ;read desired setting of pulse width15100 // @11e #703: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @11f #704: SLA(s2) ;shift carry into register s20600b // @120 #705: FETCH(s0,PWM_channel10) ;read desired setting of pulse width15100 // @121 #706: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @122 #707: SLA(s2) ;shift carry into register s20600a // @123 #708: FETCH(s0,PWM_channel9) ;read desired setting of pulse width15100 // @124 #709: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @125 #710: SLA(s2) ;shift carry into register s206009 // @126 #711: FETCH(s0,PWM_channel8) ;read desired setting of pulse width15100 // @127 #712: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @128 #713: SLA(s2) ;shift carry into register s22c240 // @129 #714: OUTPUT(s2,simple_port) ;drive pins on connector J406008 // @12a #715: FETCH(s0,PWM_channel7) ;read desired setting of pulse width15100 // @12b #716: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @12c #717: SLA(s2) ;shift carry into register s206007 // @12d #718: FETCH(s0,PWM_channel6) ;read desired setting of pulse width15100 // @12e #719: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @12f #720: SLA(s2) ;shift carry into register s206006 // @130 #721: FETCH(s0,PWM_channel5) ;read desired setting of pulse width15100 // @131 #722: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @132 #723: SLA(s2) ;shift carry into register s206005 // @133 #724: FETCH(s0,PWM_channel4) ;read desired setting of pulse width15100 // @134 #725: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @135 #726: SLA(s2) ;shift carry into register s206004 // @136 #727: FETCH(s0,PWM_channel3) ;read desired setting of pulse width15100 // @137 #728: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @138 #729: SLA(s2) ;shift carry into register s206003 // @139 #730: FETCH(s0,PWM_channel2) ;read desired setting of pulse width15100 // @13a #731: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @13b #732: SLA(s2) ;shift carry into register s206002 // @13c #733: FETCH(s0,PWM_channel1) ;read desired setting of pulse width15100 // @13d #734: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @13e #735: SLA(s2) ;shift carry into register s206001 // @13f #736: FETCH(s0,PWM_channel0) ;read desired setting of pulse width15100 // @140 #737: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @141 #738: SLA(s2) ;shift carry into register s22c280 // @142 #739: OUTPUT(s2,LED_port) ;drive LEDs0600d // @143 #740: FETCH(s0,ISR_preserve_s0) ;restore register values0610e // @144 #741: FETCH(s1,ISR_preserve_s1)0620f // @145 #742: FETCH(s2,ISR_preserve_s2)38001 // @146 #743: RETURNI(ENABLE)// #744: ;// #745: ;// #746: ;**************************************************************************************// #747: ; Interrupt Vector// #748: ;**************************************************************************************// #749: ;@3ff // #750: ADDRESS(1023)34117 // @3ff #751: JUMP(ISR)// #752: ;// #753: ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?