auto_pwm.rmh

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

RMH
884 行
字号
// @095 #369: [update_LED6]2e016 // @095 #369: STORE(s0,LED6_sequence)300a7 // @096 #370: CALL(LED_to_duty)2e107 // @097 #371: STORE(s1,PWM_channel6)// #372: ;06017 // @098 #373: FETCH(s0,LED7_sequence) ;read sequence for LED714000 // @099 #374: COMPARE(s0,0)350a0 // @09a #375: JUMP(Z,test_LED7_start)1c020 // @09b #376: SUB(s0,32) ;Count longer to ensure end stops then reset count if maximum350a3 // @09c #377: JUMP(Z,update_LED7)18020 // @09d #378: ADD(s0,32)// @09e #379: [inc_LED7]18001 // @09e #379: ADD(s0,1) ;increment counter340a3 // @09f #380: JUMP(update_LED7)// @0a0 #381: [test_LED7_start]06116 // @0a0 #381: FETCH(s1,LED6_sequence) ;start LED7 if LED6 = 414104 // @0a1 #382: COMPARE(s1,4)3509e // @0a2 #383: JUMP(Z,inc_LED7)// @0a3 #384: [update_LED7]2e017 // @0a3 #384: STORE(s0,LED7_sequence)300a7 // @0a4 #385: CALL(LED_to_duty)2e108 // @0a5 #386: STORE(s1,PWM_channel7)34014 // @0a6 #387: JUMP(warm_start)// #388: ;// #389: ;// #390: ; Convert LED sequence number into PWM intensity figure// #391: ;// #392: ; LEDs duty cycle values are 0,1,2,4,8,16,32 and 64 because they appear to give what// #393: ; appears to be a fairly liner change in intensity and provides a simple way to set// #394: ; the duty value.// #395: ;// #396: ; Provide sequence value in register s0 and intensity will be// #397: ; returned in register s1.// #398: ;// #399: ; s0   s1// #400: ; 00   00// #401: ; 01   01// #402: ; 02   02// #403: ; 03   04// #404: ; 04   08// #405: ; 05   10// #406: ; 06   20// #407: ; 07   40// #408: ; 08   80// #409: ; 09   40// #410: ; 0A   20// #411: ; 0B   10// #412: ; 0C   08// #413: ; 0D   04// #414: ; 0E   02// #415: ; 0F   01// #416: ; 10   00  and zero for all larger values of s0// #417: ;// @0a7 #418: [LED_to_duty]00100 // @0a7 #418: LOAD(s1,0)14000 // @0a8 #419: COMPARE(s0,0) ;test for zero2b000 // @0a9 #420: RETURN(Z)00101 // @0aa #421: LOAD(s1,1) ;inject '1'// @0ab #422: [go_up_loop]1c001 // @0ab #422: SUB(s0,1)2b000 // @0ac #423: RETURN(Z)20106 // @0ad #424: SL0(s1) ;multiply by 2358b0 // @0ae #425: JUMP(C,go_down)340ab // @0af #426: JUMP(go_up_loop)// @0b0 #427: [go_down]00140 // @0b0 #427: LOAD(s1,64)// @0b1 #428: [go_down_loop]1c001 // @0b1 #428: SUB(s0,1)2b000 // @0b2 #429: RETURN(Z)2010e // @0b3 #430: SR0(s1) ;divide by 2340b1 // @0b4 #431: JUMP(go_down_loop)// #432: ;// #433: ;**************************************************************************************// #434: ; UART communication routines// #435: ;**************************************************************************************// #436: ;// #437: ; Read one character from the UART// #438: ;// #439: ; Character read will be returned in a register called 'UART_data'.// #440: ;// #441: ; The routine first tests the receiver FIFO buffer to see if data is present.// #442: ; If the FIFO is empty, the routine waits until there is a character to read.// #443: ; As this could take any amount of time the wait loop could include a call to a// #444: ; subroutine which performs a useful function.// #445: ;// #446: ;// #447: ; Registers used s0 and UART_data// #448: ;// @0b5 #449: [read_from_UART]04000 // @0b5 #449: INPUT(s0,status_port) ;test Rx_FIFO buffer12004 // @0b6 #450: TEST(s0,rx_data_present) ;wait if empty354b9 // @0b7 #451: JUMP(NZ,read_character)340b5 // @0b8 #452: JUMP(read_from_UART)// @0b9 #453: [read_character]04f01 // @0b9 #453: INPUT(UART_data,UART_read_port) ;read from FIFO2a000 // @0ba #454: RETURN// #455: ;// #456: ;// #457: ;// #458: ; Transmit one character to the UART// #459: ;// #460: ; Character supplied in register called 'UART_data'.// #461: ;// #462: ; The routine first tests the transmit FIFO buffer to see if it is full.// #463: ; If the FIFO is full, then the routine waits until it there is space.// #464: ;// #465: ; Registers used s0// #466: ;// @0bb #467: [send_to_UART]04000 // @0bb #467: INPUT(s0,status_port) ;test Tx_FIFO buffer12002 // @0bc #468: TEST(s0,tx_full) ;wait if full350bf // @0bd #469: JUMP(Z,UART_write)340bb // @0be #470: JUMP(send_to_UART)// @0bf #471: [UART_write]2cf20 // @0bf #471: OUTPUT(UART_data,UART_write_port)2a000 // @0c0 #472: RETURN// #473: ;// #474: ;// #475: ;// #476: ;**************************************************************************************// #477: ; Text messages// #478: ;**************************************************************************************// #479: ;// #480: ;// #481: ; Send Carriage Return to the UART// #482: ;// @0c1 #483: [send_CR]00f0d // @0c1 #483: LOAD(UART_data,character_CR)300bb // @0c2 #484: CALL(send_to_UART)2a000 // @0c3 #485: RETURN// #486: ;// #487: ; Send a space to the UART// #488: ;// @0c4 #489: [send_space]00f20 // @0c4 #489: LOAD(UART_data,character_space)300bb // @0c5 #490: CALL(send_to_UART)2a000 // @0c6 #491: RETURN// #492: ;// #493: ;// #494: ;// #495: ; Send 'PicoBlaze Servo Control' string to the UART// #496: ;// @0c7 #497: [send_welcome]300c1 // @0c7 #497: CALL(send_CR)300c1 // @0c8 #498: CALL(send_CR)00f50 // @0c9 #499: LOAD(UART_data,character_P)300bb // @0ca #500: CALL(send_to_UART)00f69 // @0cb #501: LOAD(UART_data,character_i)300bb // @0cc #502: CALL(send_to_UART)00f63 // @0cd #503: LOAD(UART_data,character_c)300bb // @0ce #504: CALL(send_to_UART)00f6f // @0cf #505: LOAD(UART_data,character_o)300bb // @0d0 #506: CALL(send_to_UART)00f42 // @0d1 #507: LOAD(UART_data,character_B)300bb // @0d2 #508: CALL(send_to_UART)00f6c // @0d3 #509: LOAD(UART_data,character_l)300bb // @0d4 #510: CALL(send_to_UART)00f61 // @0d5 #511: LOAD(UART_data,character_a)300bb // @0d6 #512: CALL(send_to_UART)00f7a // @0d7 #513: LOAD(UART_data,character_z)300bb // @0d8 #514: CALL(send_to_UART)00f65 // @0d9 #515: LOAD(UART_data,character_e)300bb // @0da #516: CALL(send_to_UART)300c4 // @0db #517: CALL(send_space)00f41 // @0dc #518: LOAD(UART_data,character_A)300bb // @0dd #519: CALL(send_to_UART)00f75 // @0de #520: LOAD(UART_data,character_u)300bb // @0df #521: CALL(send_to_UART)00f74 // @0e0 #522: LOAD(UART_data,character_t)300bb // @0e1 #523: CALL(send_to_UART)00f6f // @0e2 #524: LOAD(UART_data,character_o)300bb // @0e3 #525: CALL(send_to_UART)300c4 // @0e4 #526: CALL(send_space)00f50 // @0e5 #527: LOAD(UART_data,character_P)300bb // @0e6 #528: CALL(send_to_UART)00f57 // @0e7 #529: LOAD(UART_data,character_W)300bb // @0e8 #530: CALL(send_to_UART)00f4d // @0e9 #531: LOAD(UART_data,character_M)300bb // @0ea #532: CALL(send_to_UART)300c4 // @0eb #533: CALL(send_space)00f41 // @0ec #534: LOAD(UART_data,character_A)300bb // @0ed #535: CALL(send_to_UART)00f63 // @0ee #536: LOAD(UART_data,character_c)300bb // @0ef #537: CALL(send_to_UART)00f74 // @0f0 #538: LOAD(UART_data,character_t)300bb // @0f1 #539: CALL(send_to_UART)00f69 // @0f2 #540: LOAD(UART_data,character_i)300bb // @0f3 #541: CALL(send_to_UART)00f76 // @0f4 #542: LOAD(UART_data,character_v)300bb // @0f5 #543: CALL(send_to_UART)00f65 // @0f6 #544: LOAD(UART_data,character_e)300bb // @0f7 #545: CALL(send_to_UART)300c1 // @0f8 #546: CALL(send_CR)300c1 // @0f9 #547: CALL(send_CR)2a000 // @0fa #548: RETURN// #549: ;// #550: ;// #551: ;Send 'OK' to the UART// #552: ;// @0fb #553: [send_OK]300c1 // @0fb #553: CALL(send_CR)00f4f // @0fc #554: LOAD(UART_data,character_O)300bb // @0fd #555: CALL(send_to_UART)00f4b // @0fe #556: LOAD(UART_data,character_K)300bb // @0ff #557: CALL(send_to_UART)340c1 // @100 #558: JUMP(send_CR)// #559: ;// #560: ;// #561: ;**************************************************************************************// #562: ; Interrupt Service Routine (ISR)// #563: ;**************************************************************************************// #564: ;// #565: ; Interrupts occur at 3.92us intervals and are used to generate the PWM pulses generated// #566: ; at a PRF of 1KHz. The 3.92us interrupt rate corresponds with a resolution of 256 steps// #567: ; over the 1ms associated with the 1KHz PRF.// #568: ;// #569: ; The ISR is self contained and all registers used are preserved. Scratch pad memory// #570: ; locations are used to determine the desired duty factor for each of 12 channels.// #571: ;// #572: ; Note that an interrupt is generated every 196 clock cycles. This means that there is// #573: ; only time to execute 98 instructions between each interrupt. This ISR is 48 instructions// #574: ; long. A further 3 instructions are also consumed by the interrupt process// #575: ; (abandoned instruction, virtual CALL to 3FF and the interrupt vector JUMP) and hence// #576: ; PicoBlaze has approximately half of its time available for other tasks in the main program.// #577: ;// #578: ; Although a loop would normal be employed in software to process each of 12 channels,// #579: ; the implementation of a loop would increase the number of instructions which needed to// #580: ; be executed to such an extent that this 12 channel implementation would not be possible.// #581: ; Consequently the code is written out in a linear fashion which consumes more program// #582: ; space but which executes faster.// #583: ;// @101 #584: [ISR]2e00d // @101 #584: STORE(s0,ISR_preserve_s0) ;preserve registers to be used2e10e // @102 #585: STORE(s1,ISR_preserve_s1)2e20f // @103 #586: STORE(s2,ISR_preserve_s2)// #587: ;Determine the number of steps currently through the 1ms PWM cycle06100 // @104 #588: FETCH(s1,PWM_duty_counter) ;read 8-bit counter of steps18101 // @105 #589: ADD(s1,1) ;increment counter (will roll over to zero)2e100 // @106 #590: STORE(s1,PWM_duty_counter) ;update count value in memory for next interrupt.// #591: ;Read duty factor for each channel and compare it with the duty counter and set or// #592: ;reset a bit in register s2 accordingly.0600c // @107 #593: FETCH(s0,PWM_channel11) ;read desired setting of pulse width15100 // @108 #594: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @109 #595: SLA(s2) ;shift carry into register s20600b // @10a #596: FETCH(s0,PWM_channel10) ;read desired setting of pulse width15100 // @10b #597: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @10c #598: SLA(s2) ;shift carry into register s20600a // @10d #599: FETCH(s0,PWM_channel9) ;read desired setting of pulse width15100 // @10e #600: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @10f #601: SLA(s2) ;shift carry into register s206009 // @110 #602: FETCH(s0,PWM_channel8) ;read desired setting of pulse width15100 // @111 #603: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @112 #604: SLA(s2) ;shift carry into register s22c240 // @113 #605: OUTPUT(s2,simple_port) ;drive pins on connector J406008 // @114 #606: FETCH(s0,PWM_channel7) ;read desired setting of pulse width15100 // @115 #607: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @116 #608: SLA(s2) ;shift carry into register s206007 // @117 #609: FETCH(s0,PWM_channel6) ;read desired setting of pulse width15100 // @118 #610: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @119 #611: SLA(s2) ;shift carry into register s206006 // @11a #612: FETCH(s0,PWM_channel5) ;read desired setting of pulse width15100 // @11b #613: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @11c #614: SLA(s2) ;shift carry into register s206005 // @11d #615: FETCH(s0,PWM_channel4) ;read desired setting of pulse width15100 // @11e #616: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @11f #617: SLA(s2) ;shift carry into register s206004 // @120 #618: FETCH(s0,PWM_channel3) ;read desired setting of pulse width15100 // @121 #619: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @122 #620: SLA(s2) ;shift carry into register s206003 // @123 #621: FETCH(s0,PWM_channel2) ;read desired setting of pulse width15100 // @124 #622: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @125 #623: SLA(s2) ;shift carry into register s206002 // @126 #624: FETCH(s0,PWM_channel1) ;read desired setting of pulse width15100 // @127 #625: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @128 #626: SLA(s2) ;shift carry into register s206001 // @129 #627: FETCH(s0,PWM_channel0) ;read desired setting of pulse width15100 // @12a #628: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @12b #629: SLA(s2) ;shift carry into register s22c280 // @12c #630: OUTPUT(s2,LED_port) ;drive LEDs0600d // @12d #631: FETCH(s0,ISR_preserve_s0) ;restore register values0610e // @12e #632: FETCH(s1,ISR_preserve_s1)0620f // @12f #633: FETCH(s2,ISR_preserve_s2)38001 // @130 #634: RETURNI(ENABLE)// #635: ;// #636: ;// #637: ;**************************************************************************************// #638: ; Interrupt Vector// #639: ;**************************************************************************************// #640: ;@3ff // #641: ADDRESS(1023)34101 // @3ff #642: JUMP(ISR)// #643: ;// #644: ;

⌨️ 快捷键说明

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