⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 led_ctrl.rmh

📁 和picoblaze完全兼容的mcu ip core
💻 RMH
📖 第 1 页 / 共 2 页
字号:
// @050 #239: [update_LED2]2e012 // @050 #239: STORE(s0,LED2_sequence)300a8 // @051 #240: CALL(LED_to_duty)2e103 // @052 #241: STORE(s1,PWM_channel2)// #242: ;// #243: ;06013 // @053 #244: FETCH(s0,LED3_sequence) ;read sequence for LED314000 // @054 #245: COMPARE(s0,0)3505b // @055 #246: JUMP(Z,test_LED3_start)1c010 // @056 #247: SUB(s0,16) ;reset count if maximum35061 // @057 #248: JUMP(Z,update_LED3)18010 // @058 #249: ADD(s0,16)// @059 #250: [inc_LED3]18001 // @059 #250: ADD(s0,1) ;increment counter34061 // @05a #251: JUMP(update_LED3)// @05b #252: [test_LED3_start]06112 // @05b #252: FETCH(s1,LED2_sequence) ;start LED3 if LED2 = 414104 // @05c #253: COMPARE(s1,4)35059 // @05d #254: JUMP(Z,inc_LED3)06114 // @05e #255: FETCH(s1,LED4_sequence) ;start LED3 if LED4 = 414104 // @05f #256: COMPARE(s1,4)35059 // @060 #257: JUMP(Z,inc_LED3)// @061 #258: [update_LED3]2e013 // @061 #258: STORE(s0,LED3_sequence)300a8 // @062 #259: CALL(LED_to_duty)2e104 // @063 #260: STORE(s1,PWM_channel3)// #261: ;06014 // @064 #262: FETCH(s0,LED4_sequence) ;read sequence for LED414000 // @065 #263: COMPARE(s0,0)3506c // @066 #264: JUMP(Z,test_LED4_start)1c010 // @067 #265: SUB(s0,16) ;reset count if maximum35072 // @068 #266: JUMP(Z,update_LED4)18010 // @069 #267: ADD(s0,16)// @06a #268: [inc_LED4]18001 // @06a #268: ADD(s0,1) ;increment counter34072 // @06b #269: JUMP(update_LED4)// @06c #270: [test_LED4_start]06113 // @06c #270: FETCH(s1,LED3_sequence) ;start LED4 if LED3 = 414104 // @06d #271: COMPARE(s1,4)3506a // @06e #272: JUMP(Z,inc_LED4)06115 // @06f #273: FETCH(s1,LED5_sequence) ;start LED4 if LED5 = 414104 // @070 #274: COMPARE(s1,4)3506a // @071 #275: JUMP(Z,inc_LED4)// @072 #276: [update_LED4]2e014 // @072 #276: STORE(s0,LED4_sequence)300a8 // @073 #277: CALL(LED_to_duty)2e105 // @074 #278: STORE(s1,PWM_channel4)// #279: ;06015 // @075 #280: FETCH(s0,LED5_sequence) ;read sequence for LED514000 // @076 #281: COMPARE(s0,0)3507d // @077 #282: JUMP(Z,test_LED5_start)1c010 // @078 #283: SUB(s0,16) ;reset count if maximum35083 // @079 #284: JUMP(Z,update_LED5)18010 // @07a #285: ADD(s0,16)// @07b #286: [inc_LED5]18001 // @07b #286: ADD(s0,1) ;increment counter34083 // @07c #287: JUMP(update_LED5)// @07d #288: [test_LED5_start]06114 // @07d #288: FETCH(s1,LED4_sequence) ;start LED5 if LED4 = 414104 // @07e #289: COMPARE(s1,4)3507b // @07f #290: JUMP(Z,inc_LED5)06116 // @080 #291: FETCH(s1,LED6_sequence) ;start LED5 if LED6 = 414104 // @081 #292: COMPARE(s1,4)3507b // @082 #293: JUMP(Z,inc_LED5)// @083 #294: [update_LED5]2e015 // @083 #294: STORE(s0,LED5_sequence)300a8 // @084 #295: CALL(LED_to_duty)2e106 // @085 #296: STORE(s1,PWM_channel5)// #297: ;06117 // @086 #298: FETCH(s1,LED7_sequence) ; refresh LED6 if LED7 = 11 (0B hex) to reflect wave1410b // @087 #299: COMPARE(s1,11)3548b // @088 #300: JUMP(NZ,normal_LED6)00004 // @089 #301: LOAD(s0,4)34096 // @08a #302: JUMP(update_LED6)// @08b #303: [normal_LED6]06016 // @08b #303: FETCH(s0,LED6_sequence) ;read sequence for LED614000 // @08c #304: COMPARE(s0,0)35093 // @08d #305: JUMP(Z,test_LED6_start)1c010 // @08e #306: SUB(s0,16) ;reset count if maximum35096 // @08f #307: JUMP(Z,update_LED6)18010 // @090 #308: ADD(s0,16)// @091 #309: [inc_LED6]18001 // @091 #309: ADD(s0,1) ;increment counter34096 // @092 #310: JUMP(update_LED6)// @093 #311: [test_LED6_start]06115 // @093 #311: FETCH(s1,LED5_sequence) ;start LED6 if LED5 = 414104 // @094 #312: COMPARE(s1,4)35091 // @095 #313: JUMP(Z,inc_LED6)// @096 #314: [update_LED6]2e016 // @096 #314: STORE(s0,LED6_sequence)300a8 // @097 #315: CALL(LED_to_duty)2e107 // @098 #316: STORE(s1,PWM_channel6)// #317: ;06017 // @099 #318: FETCH(s0,LED7_sequence) ;read sequence for LED714000 // @09a #319: COMPARE(s0,0)350a1 // @09b #320: JUMP(Z,test_LED7_start)1c020 // @09c #321: SUB(s0,32) ;Count longer to ensure end stops then reset count if maximum350a4 // @09d #322: JUMP(Z,update_LED7)18020 // @09e #323: ADD(s0,32)// @09f #324: [inc_LED7]18001 // @09f #324: ADD(s0,1) ;increment counter340a4 // @0a0 #325: JUMP(update_LED7)// @0a1 #326: [test_LED7_start]06116 // @0a1 #326: FETCH(s1,LED6_sequence) ;start LED7 if LED6 = 414104 // @0a2 #327: COMPARE(s1,4)3509f // @0a3 #328: JUMP(Z,inc_LED7)// @0a4 #329: [update_LED7]2e017 // @0a4 #329: STORE(s0,LED7_sequence)300a8 // @0a5 #330: CALL(LED_to_duty)2e108 // @0a6 #331: STORE(s1,PWM_channel7)34013 // @0a7 #332: JUMP(warm_start)// #333: ;// #334: ;// #335: ; Convert LED sequence number into PWM intensity figure// #336: ;// #337: ; LEDs duty cycle values are 0,1,2,4,8,16,32 and 64 because they appear to give what// #338: ; appears to be a fairly liner change in intensity and provides a simple way to set// #339: ; the duty value.// #340: ;// #341: ; Provide sequence value in register s0 and intensity will be// #342: ; returned in register s1.// #343: ;// #344: ; s0   s1// #345: ; 00   00// #346: ; 01   01// #347: ; 02   02// #348: ; 03   04// #349: ; 04   08// #350: ; 05   10// #351: ; 06   20// #352: ; 07   40// #353: ; 08   80// #354: ; 09   40// #355: ; 0A   20// #356: ; 0B   10// #357: ; 0C   08// #358: ; 0D   04// #359: ; 0E   02// #360: ; 0F   01// #361: ; 10   00  and zero for all larger values of s0// #362: ;// @0a8 #363: [LED_to_duty]00100 // @0a8 #363: LOAD(s1,0)14000 // @0a9 #364: COMPARE(s0,0) ;test for zero2b000 // @0aa #365: RETURN(Z)00101 // @0ab #366: LOAD(s1,1) ;inject '1'// @0ac #367: [go_up_loop]1c001 // @0ac #367: SUB(s0,1)2b000 // @0ad #368: RETURN(Z)20106 // @0ae #369: SL0(s1) ;multiply by 2358b1 // @0af #370: JUMP(C,go_down)340ac // @0b0 #371: JUMP(go_up_loop)// @0b1 #372: [go_down]00140 // @0b1 #372: LOAD(s1,64)// @0b2 #373: [go_down_loop]1c001 // @0b2 #373: SUB(s0,1)2b000 // @0b3 #374: RETURN(Z)2010e // @0b4 #375: SR0(s1) ;divide by 2340b2 // @0b5 #376: JUMP(go_down_loop)// #377: ;// #378: ;// #379: ;// #380: ;**************************************************************************************// #381: ; Authentication Check and fail procedure// #382: ;**************************************************************************************// #383: ;// #384: ; The authentication check is performed by issuing and interrupt to the authentication// #385: ; processor and then observing the simple text string that it returns via the link FIFO// #386: ; buffer.// #387: ;// #388: ; PASS - Design is authorised to work.// #389: ; FAIL - Design is not authorised and should stop working normally.// #390: ;// #391: ;// #392: ;ASCII character values that are used in messages// #393: ;// #394: CONSTANT(character_A,65)// #395: CONSTANT(character_F,70)// #396: CONSTANT(character_I,73)// #397: CONSTANT(character_L,76)// #398: CONSTANT(character_P,80)// #399: CONSTANT(character_S,83)// #400: ;// #401: ;// @0b6 #402: [authentication_check]00001 // @0b6 #402: LOAD(s0,link_fifo_reset) ;clear link FIFO to ensure no unexpected characters2c020 // @0b7 #403: OUTPUT(s0,link_fifo_control_port)00000 // @0b8 #404: LOAD(s0,0)2c020 // @0b9 #405: OUTPUT(s0,link_fifo_control_port)// #406: ;00001 // @0ba #407: LOAD(s0,security_interrupt) ;generate interrupt to authentication processor2c040 // @0bb #408: OUTPUT(s0,security_request_port)00000 // @0bc #409: LOAD(s0,0)2c040 // @0bd #410: OUTPUT(s0,security_request_port)// #411: ;300f9 // @0be #412: CALL(read_link_FIFO) ;read each character and compare14050 // @0bf #413: COMPARE(s0,character_P)354cb // @0c0 #414: JUMP(NZ,fail_confirm)300f9 // @0c1 #415: CALL(read_link_FIFO)14041 // @0c2 #416: COMPARE(s0,character_A)354cb // @0c3 #417: JUMP(NZ,fail_confirm)300f9 // @0c4 #418: CALL(read_link_FIFO)14053 // @0c5 #419: COMPARE(s0,character_S)354cb // @0c6 #420: JUMP(NZ,fail_confirm)300f9 // @0c7 #421: CALL(read_link_FIFO)14053 // @0c8 #422: COMPARE(s0,character_S)354cb // @0c9 #423: JUMP(NZ,fail_confirm)34015 // @0ca #424: JUMP(normal_LED_sequence) ;Continue normal operation for PASS message// #425: ;// #426: ;// #427: ; To confirm that the authentication is really a FAIL message// #428: ; another request is made to the authentication processor and tested.// #429: ;// @0cb #430: [fail_confirm]000ff // @0cb #430: LOAD(s0,FF) ;short delay to ensure authentication processor is ready// @0cc #431: [request_delay]1c001 // @0cc #431: SUB(s0,1) ;   to respond to new interrupt request354cc // @0cd #432: JUMP(NZ,request_delay)// #433: ;00001 // @0ce #434: LOAD(s0,link_fifo_reset) ;clear link FIFO to ensure no unexpected characters2c020 // @0cf #435: OUTPUT(s0,link_fifo_control_port)00000 // @0d0 #436: LOAD(s0,0)2c020 // @0d1 #437: OUTPUT(s0,link_fifo_control_port)// #438: ;00001 // @0d2 #439: LOAD(s0,security_interrupt) ;generate interrupt to authentication processor2c040 // @0d3 #440: OUTPUT(s0,security_request_port)00000 // @0d4 #441: LOAD(s0,0)2c040 // @0d5 #442: OUTPUT(s0,security_request_port)// #443: ;300f9 // @0d6 #444: CALL(read_link_FIFO) ;read each character and compare14046 // @0d7 #445: COMPARE(s0,character_F)35415 // @0d8 #446: JUMP(NZ,normal_LED_sequence)300f9 // @0d9 #447: CALL(read_link_FIFO)14041 // @0da #448: COMPARE(s0,character_A)35415 // @0db #449: JUMP(NZ,normal_LED_sequence)300f9 // @0dc #450: CALL(read_link_FIFO)14049 // @0dd #451: COMPARE(s0,character_I)35415 // @0de #452: JUMP(NZ,normal_LED_sequence)300f9 // @0df #453: CALL(read_link_FIFO)1404c // @0e0 #454: COMPARE(s0,character_L)35415 // @0e1 #455: JUMP(NZ,normal_LED_sequence)// #456: ;// #457: ;// #458: ; When the design fails to authenticate the LEDs will appear to// #459: ; turn on and then slowly fade to off using PWM.// #460: ;// @0e2 #461: [failed_LED_sequence]000ff // @0e2 #461: LOAD(s0,FF) ;maximum intensity on all LEDs00400 // @0e3 #462: LOAD(s4,0) ;reset fade rate control// @0e4 #463: [all_LED_fade]00101 // @0e4 #463: LOAD(s1,PWM_channel0)// @0e5 #464: [all_LED_fade_loop]2f010 // @0e5 #464: STORE(s0,s1)14108 // @0e6 #465: COMPARE(s1,PWM_channel7)350ea // @0e7 #466: JUMP(Z,decay_LEDs)18101 // @0e8 #467: ADD(s1,1)340e5 // @0e9 #468: JUMP(all_LED_fade_loop)// @0ea #469: [decay_LEDs]01140 // @0ea #469: LOAD(s1,s4) ;software delay starts quickly and slows down because LEDs are non-linear.// @0eb #470: [wait_s1]00218 // @0eb #470: LOAD(s2,24)// @0ec #471: [wait_s2]003ff // @0ec #471: LOAD(s3,FF)// @0ed #472: [wait_s3]1c301 // @0ed #472: SUB(s3,1)354ed // @0ee #473: JUMP(NZ,wait_s3)1c201 // @0ef #474: SUB(s2,1)354ec // @0f0 #475: JUMP(NZ,wait_s2)1c101 // @0f1 #476: SUB(s1,1)354eb // @0f2 #477: JUMP(NZ,wait_s1)14000 // @0f3 #478: COMPARE(s0,0) ;test for fully off350f8 // @0f4 #479: JUMP(Z,stop_completely)1c001 // @0f5 #480: SUB(s0,1) ;fade LEDs18401 // @0f6 #481: ADD(s4,1) ;slow fade rate as intensity decreases340e4 // @0f7 #482: JUMP(all_LED_fade)// #483: ;// @0f8 #484: [stop_completely]340f8 // @0f8 #484: JUMP(stop_completely)// #485: ;// #486: ;**************************************************************************************// #487: ; Read Byte from Link FIFO// #488: ;**************************************************************************************// #489: ;// #490: ; The routine first tests the FIFO buffer to see if data is present.// #491: ; If the FIFO is empty, the routine waits until there is a character to read.// #492: ; the read value is returned in register s0.// #493: ;// #494: ;// @0f9 #495: [read_link_FIFO]04001 // @0f9 #495: INPUT(s0,link_FIFO_status_port) ;test FIFO buffer12001 // @0fa #496: TEST(s0,link_FIFO_data_present) ;wait if empty350f9 // @0fb #497: JUMP(Z,read_link_FIFO)04002 // @0fc #498: INPUT(s0,link_FIFO_read_port) ;read data from FIFO2a000 // @0fd #499: RETURN// #500: ;// #501: ;// #502: ;**************************************************************************************// #503: ; Interrupt Service Routine (ISR)// #504: ;**************************************************************************************// #505: ;// #506: ; Interrupts occur at 3.92us intervals and are used to generate the PWM pulses generated// #507: ; at a PRF of 1KHz. The 3.92us interrupt rate corresponds with a resolution of 256 steps// #508: ; over the 1ms associated with the 1KHz PRF.// #509: ;// #510: ; The ISR is self contained and all registers used are preserved. Scratch pad memory// #511: ; locations are used to determine the desired duty factor for each of 8 channels.// #512: ;// #513: ; Note that an interrupt is generated every 196 clock cycles. This means that there is// #514: ; only time to execute 98 instructions between each interrupt. This ISR is 35 instructions// #515: ; long. A further 3 instructions are also consumed by the interrupt process// #516: ; (abandoned instruction, virtual CALL to 3FF and the interrupt vector JUMP) and hence// #517: ; PicoBlaze has approximately 63% of its time available for other tasks in the main program.// #518: ;// #519: ; Although a loop would normal be employed in software to process each of 8 channels,// #520: ; the implementation of a loop would increase the number of instructions which needed to// #521: ; be executed significantly reduce the time available for the main program to operate.// #522: ; Consequently the code is written out in a linear fashion which consumes more program// #523: ; space but which executes faster.// #524: ;// @0fe #525: [ISR]2e00d // @0fe #525: STORE(s0,ISR_preserve_s0) ;preserve registers to be used2e10e // @0ff #526: STORE(s1,ISR_preserve_s1)2e20f // @100 #527: STORE(s2,ISR_preserve_s2)// #528: ;Determine the number of steps currently through the 1ms PWM cycle06100 // @101 #529: FETCH(s1,PWM_duty_counter) ;read 8-bit counter of steps18101 // @102 #530: ADD(s1,1) ;increment counter (will roll over to zero)2e100 // @103 #531: STORE(s1,PWM_duty_counter) ;update count value in memory for next interrupt.// #532: ;Read duty factor for each channel and compare it with the duty counter and set or// #533: ;reset a bit in register s2 accordingly.06008 // @104 #534: FETCH(s0,PWM_channel7) ;read desired setting of pulse width15100 // @105 #535: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @106 #536: SLA(s2) ;shift carry into register s206007 // @107 #537: FETCH(s0,PWM_channel6) ;read desired setting of pulse width15100 // @108 #538: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @109 #539: SLA(s2) ;shift carry into register s206006 // @10a #540: FETCH(s0,PWM_channel5) ;read desired setting of pulse width15100 // @10b #541: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @10c #542: SLA(s2) ;shift carry into register s206005 // @10d #543: FETCH(s0,PWM_channel4) ;read desired setting of pulse width15100 // @10e #544: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @10f #545: SLA(s2) ;shift carry into register s206004 // @110 #546: FETCH(s0,PWM_channel3) ;read desired setting of pulse width15100 // @111 #547: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @112 #548: SLA(s2) ;shift carry into register s206003 // @113 #549: FETCH(s0,PWM_channel2) ;read desired setting of pulse width15100 // @114 #550: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @115 #551: SLA(s2) ;shift carry into register s206002 // @116 #552: FETCH(s0,PWM_channel1) ;read desired setting of pulse width15100 // @117 #553: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @118 #554: SLA(s2) ;shift carry into register s206001 // @119 #555: FETCH(s0,PWM_channel0) ;read desired setting of pulse width15100 // @11a #556: COMPARE(s1,s0) ;set carry flag if duty factor > duty counter20200 // @11b #557: SLA(s2) ;shift carry into register s22c280 // @11c #558: OUTPUT(s2,LED_port) ;drive LEDs0600d // @11d #559: FETCH(s0,ISR_preserve_s0) ;restore register values0610e // @11e #560: FETCH(s1,ISR_preserve_s1)0620f // @11f #561: FETCH(s2,ISR_preserve_s2)38001 // @120 #562: RETURNI(ENABLE)// #563: ;// #564: ;// #565: ;**************************************************************************************// #566: ; Interrupt Vector// #567: ;**************************************************************************************// #568: ;@3ff // #569: ADDRESS(1023)340fe // @3ff #570: JUMP(ISR)// #571: ;// #572: ;

⌨️ 快捷键说明

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