Hi forum! I need a delay in a programm but _nop_() seems not to work. Thus I wrote the following code in the main function where x is an IO pin: while(1) { x = 1; _nop_(); x = 0; _nop_(); } Only the second _nop_() causes a delay but not the first one. µVsioin2 is used. Can anybody help me? Thanks Fabian
Post the relevant section of the .cod file.
Only the second _nop_() causes a delay but not the first one. µVsioin2 is used. Can anybody help me? what does the generated assembler look loke? Erik
Here it is:
#pragma large #pragma MOD167 FIX167 #include "intrins.h" #include "regst10F269.h" #include "absacc.h" #include "math.h" #include "stdio.h" sbit Testpin = P3^7; void main(void) { while(1) { Testpin = 1; _nop_(); Testpin = 0; _nop_(); } }
Here's the assembler file:
:020000020000FC :0E014A00E6E3C0007FE2CC007EE2CC000DFBBD :10000400A55AA5A5D180E6120C000A86FFCD1A8652 :1000140006D61A8903FB0A89FF44E6F10070F6F15B :10002400E0F1D190E6E80005E6E80004E60C0810EB :10003400E68ACD06E60D0820E68BC904E60A0CFA2A :10004400E6000000E6010100E6020300E60800FC09 :10005400B54AB5B5E6F00090E6F90000E6F8000010 :10006400F01870192D29E005DC0998282D25F032A7 :10007400DC099848AAF21BE0AAF20EF0F0347C33B3 :100084000EF306F300FDE0154C549150685BB85331 :10009400084128213DF30DE7DC099838DC44B9A375 :1000A4000831184076F300C028217DF80DDCB9A48E :1000B400084128217DFC0DD7E6F90100E6F800800F :1000C400E6030300DC09A8282D3C08821890AAF254 :1000D40029F0F04266F2FF3F3D05E004DC09A82860 :1000E40008821890DC09A838088218908AF406E07F :1000F400F6F306FEDC09A83808821890DC09A9A8E2 :1001040008811890B9A308318AF406E08AF304E060 :100114000603010076F300C028213DF09AF8D000D0 :1001240008810DCEC0435C1376F300FDE014F1A505 :100134004C458AF203709140684B0D01784BB843EB :060144000DBFFA004A01A4 :020000021000EC :0280000000007E :020000020000FC :04000000FA000400FE :00000001FF
what does the generated assembler look loke? Here it is: Hardly, neither C source not object is the "generated assembler". The generated assembler is in the .lst file Erik
Sorry, Erik. Hope this is the right one. I'm new to this stuff.
C166 COMPILER V4.27, SLREGELUNG 09/07/2005 16:28:48 PAGE 1 C166 COMPILER V4.27, COMPILATION OF MODULE SLREGELUNG OBJECT MODULE PLACED IN slregelung.OBJ COMPILER INVOKED BY: C:\Keil\C166\BIN\C166.EXE slregelung.c LARGE BROWSE NODPPSAVE SAVEUSR REORDER MOD167 DEBUG stmt lvl source 1 #pragma large 2 #pragma MOD167 FIX167 3 4 #include "intrins.h" 5 #include "regst10F269.h" 6 #include "absacc.h" 7 #include "math.h" 8 9 sbit Testpin = P3^7; 10 11 #include "stdio.h" 12 13 void main(void) 14 { 15 1 DP3 = 0x00C0; 16 1 17 1 while(1) 18 1 { 19 2 Testpin = 1; 20 2 _nop_(); 21 2 Testpin = 0; 22 2 _nop_(); 23 2 } 24 1 } 25 // ---------------------------------- E N D E --------------------------------------- 26 27 MODULE INFORMATION: INITIALIZED UNINITIALIZED CODE SIZE = 14 -------- NEAR-CONST SIZE = -------- -------- FAR-CONST SIZE = -------- -------- HUGE-CONST SIZE = -------- -------- XHUGE-CONST SIZE = -------- -------- NEAR-DATA SIZE = -------- -------- FAR-DATA SIZE = -------- -------- XHUGE-DATA SIZE = -------- -------- IDATA-DATA SIZE = -------- -------- SDATA-DATA SIZE = -------- -------- BDATA-DATA SIZE = -------- -------- HUGE-DATA SIZE = -------- -------- BIT SIZE = -------- -------- INIT'L SIZE = -------- -------- END OF MODULE INFORMATION. C166 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
you must have a flag or something set "wrong" this does not show assembler either. Maybe one of the Current 166 users can help find it, I have not been in 166 for quite a while. Erik
What about this code:
ASSUME DPP3 : SYSTEM EXTRN ?C_STARTUP : FAR REGDEF R0 - R15 ?PR?SLREGELUNG SECTION CODE WORD 'FCODE' ; line 1: #pragma large ; line 2: #pragma src ; line 3: #pragma MOD167 FIX167 ; line 4: ; line 5: #include "intrins.h" ; line 6: #include "regst10F269.h" ; line 7: #include "absacc.h" ; line 8: #include "math.h" ; line 9: ; line 10: sbit Testpin = P3^7; ; line 11: ; line 12: #include "stdio.h" ; line 13: ; line 14: void main(void) main PROC FAR GLOBAL main ; FUNCTION main (BEGIN RMASK = @0x8000) ; line 15: { ; line 16: DP3 = 0x00C0; MOV DP3,#192 ; line 17: ; line 18: while(1) ?C0003: ; line 19: { ; line 20: Testpin = 1; BSET Testpin ; line 21: _nop_(); NOP ; line 22: Testpin = 0; BCLR Testpin ; line 23: _nop_(); NOP ; line 24: } JMP cc_UC,?C0003 ; FUNCTION main (END RMASK = @0x8000) main ENDP ?PR?SLREGELUNG ENDS ; line 25: } ; line 26: // ; line 27: ; line 28: END
diluted:
; FUNCTION main (BEGIN RMASK = MOV DP3,#192 BSET Testpin NOP BCLR Testpin NOP
Do I get you right? The assembler code is ok but the measurement is wrong. Here's kind of a truth table: 1. and 2. _nop_() are set: high=100ns, low=150ns Only 1. _nop_() is set: high=100ns, low=100ns Only 2. _nop_() is set: high=100ns, low=150ns Neither _nop_() is set: high=100ns, low=100ns Fabian
Don't forget that your output is zero during the time that the JMP instruction is executing also.
I think Walter just caught what is making you see what confuses you. Erik
WE need an edit button, the above is gobbelygook It should be I think Walter just caught what confuses you. or I think Walter just caught what is making you confused. Erik
If I understan Walter right, the low time should be longer than the high time. Here's the code:
main PROC FAR GLOBAL main ; FUNCTION main (BEGIN RMASK = @0x8000) ; line 15: { ; line 16: DP3 = 0x00C0; MOV DP3,#192 ; line 17: ; line 18: while(1) ?C0003: ; line 19: { ; line 20: Testpin = 1; BSET Testpin ; line 21: //_nop_(); ; line 22: Testpin = 0; BCLR Testpin ; line 23: //_nop_(); ; line 24: } JMP cc_UC,?C0003 ; FUNCTION main (END RMASK = @0x8000) main ENDP ?PR?SLREGELUNG ENDS ; line 25: } ; line 26: ; line 27: ; line 28: END
I'm really sorry guys, but I still don't understand what I'm doing wrong. Tell us what you are trying to achieve. With the C166 CPU core (and even more so with the C166 v2 core) you cannot expect program execution time to be a simple arithmetic sum of execution times of each instruction because of things like CPU pipeline, jump cache and so on. By the way, what microcontroller are you using? Is it the older C16x family, or the newer XC16x family? Regards, - mike