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
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
I'm really sorry guys, but I still don't understand what I'm doing wrong. Because you insist on programming the chip without taking the time to understand the chip. If you have no idea of the chips architecture, how in the world do you expect to be able to calculate a delay. C is wonderful, but (especially in the embedded world) it does not release you from understanding what you are working with. Erik
The output is low for 3 instructions and high for 2. This is why the high time and low time are not equal.
?C0003: BSET Testpin ; Output Low NOP ; Output High BCLR Testpin ; Output High NOP ; Output Low JMP cc_UC,?C0003 ; Output Low
GOT IT! Thanks everybody for your help. @Walter: This is exactly the information I needed. @Erik: I wish I had the time to get to know the chip better but unfortunately I don't. Fabian
This is exactly the information I needed. Good, just remember that the things that Mike spoke of will definitely affect timing. If you need to get down to that level of detail, you will have to take those things into account.
I wish I had the time to get to know the chip better but unfortunately I don't. Good luck, you will need it. Erik
"I wish I had the time to get to know the chip better but unfortunately I don't." Doesn't the very fact that you needed to start this thread (plus the fact that it took so long for the penny to drop) rather suggest that you really do need that understanding...?