Home |
Search |
Today's Posts |
#1
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
hello
I am relatively new to PIC programming, I have written a short sequence with a nested loop delay that last about 0.2 seconds ------------------------------------------------------------------------------------------ ;SUBROUTINE SECTION. DELAY MOVLW D'255' ;LOAD 255 MOVWF COUNT1 ;IN COUNT1 LOAD2 MOVLW D'255' MOVWF COUNT2 DEC2 DECFSZ COUNT2,F GOTO DEC2 DECFSZ COUNT1,F GOTO LOAD2 RETURN ------------------------------------------------------------------------------------------------ I need to create a delay of 10 seconds though and have tried to add another loop to the code by creating a COUNT3 and decrementing it. I could not get this to work. I also tried creating another subroutine that called DELAY by simply going DELAY2 GOTO DELAY GOTO DELAY RETURN This did not work either. I finally turned to the delay code generator http://www.piclist.com/techref/picli...egen/delay.htm but this also did not work, and I didn't understand what the command $+2 meant Can someone help with code for the 10 second delay? Cheers Ash |
#2
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
I am relatively new to PIC programming
Ash If you are going to be messing with PICs, you need to investigate this mailing list.[1] http://72.14.207.104/search?q=cache:...g-List-Archive The archive is a useful resource so you won't have to ask questions that have been posed a billion times before. .. .. [1] The 1st thing you'll learn is that the 16F84 is obsolete. http://groups.google.com/groups?q=PI...n-PICs+-jeffm_ |
#3
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
"Ash" schreef in bericht oups.com... hello I am relatively new to PIC programming, I have written a short sequence with a nested loop delay that last about 0.2 seconds ------------------------------------------------------------------------------------------ ;SUBROUTINE SECTION. DELAY MOVLW D'255' ;LOAD 255 MOVWF COUNT1 ;IN COUNT1 LOAD2 MOVLW D'255' MOVWF COUNT2 DEC2 DECFSZ COUNT2,F GOTO DEC2 DECFSZ COUNT1,F GOTO LOAD2 RETURN ------------------------------------------------------------------------------------------------ I need to create a delay of 10 seconds though and have tried to add another loop to the code by creating a COUNT3 and decrementing it. I could not get this to work. I also tried creating another subroutine that called DELAY by simply going DELAY2 GOTO DELAY GOTO DELAY RETURN This did not work either. I finally turned to the delay code generator http://www.piclist.com/techref/picli...egen/delay.htm but this also did not work, and I didn't understand what the command $+2 meant Can someone help with code for the 10 second delay? Cheers Ash OK, I can give you some help. 1st: You probably have another chip than the 16F84. 2nd the $ means the current PC 3rd don't use instructions that are for another family PIC's, the 16FXXX don't support DECFSZ. Look at the instruction set in the manual. Somhow RTFM (of the right chip) pops into my mind. Alexander |
#4
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
"Alexander" wrote in message ... OK, I can give you some help. 1st: You probably have another chip than the 16F84. Why would you say that? They are still quite available. 2nd the $ means the current PC 3rd don't use instructions that are for another family PIC's, the 16FXXX don't support DECFSZ. Look at the instruction set in the manual. Er, umm....yes they do. Somhow RTFM (of the right chip) pops into my mind. I heard that. ;-) Looks to me like the OP needs to use CALL instead of GOTO. |
#5
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
"Anthony Fremont" schreef in bericht ... "Alexander" wrote in message ... OK, I can give you some help. 1st: You probably have another chip than the 16F84. Why would you say that? They are still quite available. The 16F84 is like the 16C84 obsolete! The chip in question is more likely to be a 16F84A 2nd the $ means the current PC 3rd don't use instructions that are for another family PIC's, the 16FXXX don't support DECFSZ. Look at the instruction set in the manual. Er, umm....yes they do. You're right, my mistake. I was thinking of other skip options like carry. Somhow RTFM (of the right chip) pops into my mind. I heard that. ;-) Looks to me like the OP needs to use CALL instead of GOTO. That's for the whole routine. Maybe the OP can give more information, does it wait forever or doesn't it wait at all? Does the PIC run at all? |
#6
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
"Alexander" wrote in message ... "Anthony Fremont" schreef in bericht ... "Alexander" wrote in message ... OK, I can give you some help. 1st: You probably have another chip than the 16F84. Why would you say that? They are still quite available. The 16F84 is like the 16C84 obsolete! The chip in question is more likely to be a 16F84A 2nd the $ means the current PC 3rd don't use instructions that are for another family PIC's, the 16FXXX don't support DECFSZ. Look at the instruction set in the manual. Er, umm....yes they do. You're right, my mistake. I was thinking of other skip options like carry. SKPC, SKPZ, SETC, SETZ, MOVFW filereg and the like are also available on the 16Fs since they are basically built-in macros that substitute for "BTFSS STATUS,C", "BTFSS STATUS,Z", "BSF STATUS,C", "BSF STATUS,Z", and "MOVF filereg, W" respectively. Too bad microchip won't change the SUBLW mnemonic by switching it to SUBWL as it should have been. Somhow RTFM (of the right chip) pops into my mind. I heard that. ;-) Looks to me like the OP needs to use CALL instead of GOTO. That's for the whole routine. Maybe the OP can give more information, does it wait forever or doesn't it wait at all? Does the PIC run at all? I think the OP got the short delay routines to work, but couldn't figure out how to extend it. He indicated that he'd made another routine to "call" the working delay routines, but his pasted code shows that he has GOTO statements. That will never work. He's probably underflowing the stack. |
#7
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
Unfortunately I am using the 16F84A chip and cannot change that, I do
not have a manual for it as such but a few pieces of paper defining the 35 commands it supports (which include decfsz) and overview of what the chip is capable of. The code I quoted before does work, giving an 0.2 sec delay so the PIC is functioning fine and successfully decrements counters, my question was how can I extend this delay to 10 seconds as I have tried and failed at numerous attempts loops. I have tried using the CALL command but it did not work when I programmed the chip. On the simulation in MPLAB it never seemed to exit the second subroutine despite the RETURN command at the end of the routine with all the different variations of coding I tried. |
#8
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
"Ash" schreef in bericht ups.com... Unfortunately I am using the 16F84A chip and cannot change that, I do not have a manual for it as such but a few pieces of paper defining the 35 commands it supports (which include decfsz) and overview of what the chip is capable of. The code I quoted before does work, giving an 0.2 sec delay so the PIC is functioning fine and successfully decrements counters, my question was how can I extend this delay to 10 seconds as I have tried and failed at numerous attempts loops. I have tried using the CALL command but it did not work when I programmed the chip. On the simulation in MPLAB it never seemed to exit the second subroutine despite the RETURN command at the end of the routine with all the different variations of coding I tried. If the code placed in the OP worked for a 0.2sec delay, you simply use the following: MOVLW, D'50'; 50 times 0.2 should be 10 MOVWF COUNT3 ; make variable first DELAY10SEC CALL SECTION DECFSZ COUNT3 GOTO DELEY10SEC Then paste the subroutine somewhere outside the main code, but before "end"! Alexander p.s. I have not tested anything |
#9
Posted to alt.electronics
|
|||
|
|||
nested loop delay for 16F84 PIC
"Ash" wrote in message ups.com... Unfortunately I am using the 16F84A chip and cannot change that, I do not have a manual for it as such but a few pieces of paper defining the 35 commands it supports (which include decfsz) and overview of what the chip is capable of. Why not? http://www.microchip.com/stellent/id...cName=en010230 The code I quoted before does work, giving an 0.2 sec delay so the PIC is functioning fine and successfully decrements counters, my question was how can I extend this delay to 10 seconds as I have tried and failed at numerous attempts loops. I have tried using the CALL command but it did not work when I programmed the chip. On the simulation in MPLAB it never seemed to exit the second subroutine despite the RETURN command at the end of the routine with all the different variations of coding I tried. "I also tried creating another subroutine that called DELAY by simply going" DELAY2 GOTO DELAY GOTO DELAY RETURN Did you try changing the above code to: DELAY2 CALL DELAY CALL DELAY RETURN Another thing to check, the stack is only 8 levels deep so too much nesting of calls will make it wrap around. Watch the stack level closely in MPLAB |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
OT - Where Your Poltical Donations Go | Metalworking | |||
OT - DeLay, DeLay | Metalworking | |||
OT - Delay, Delay | Metalworking | |||
Time Delay RCDs | UK diy |