[dsPIC 4.0.0.0] asm code generation misses a NOP ?

Discuss about beta versions of mikroC compiler.
Post Reply
Author
Message
picdog
Posts: 390
Joined: 28 Feb 2006 09:32

[dsPIC 4.0.0.0] asm code generation misses a NOP ?

#1 Post by picdog » 21 Jul 2007 19:53

Hello,
according to the dsPIC33 family datasheet "one instruction cycle is required between a port direction change or port write operation and a read operation of the same port. Typically, this instruction would be a NOP." (Microchip dsPIC family datasheet, section 10.4 I/O Port Write/Read Timing)

I tried to compile this simple code snippet:

Code: Select all

unsigned int a;
void main(void) {
	TRISB=0xFFFF;
	a = PORTB;
}
and the result is:

Code: Select all

;experiment.c,3 :: 		void main(void) {
;experiment.c,4 :: 		TRISB=0xFFFF;
$0206	$2FFFF0			MOV	#65535, W0
$0208	$881630			MOV	W0, TRISB
;experiment.c,5 :: 		a = PORTB;
$020A	$801640			MOV	PORTB, W0
$020C	$88C000			MOV	W0, _a
;experiment.c,6 :: 		}
a similar thing happens compiling a write operation followed by a read:

Code: Select all

PORTB = 0xABCD;
a = PORTB;
according to the datasheet there would be necessary a NOP or other instruction just after the TRIS or write before to MOV PORTB to something.

So as a workaround it is possible to put a NOP manually; indeed it would be better to generate this code ad the compile level.

Hope this helps you.

picdog
[/code]
... a proud user of MikroElektronica EasyPic3, EasyPic4, BigPic4, MikroC for PIC, EasydsPIC2, dsPIC-Pro2, LV24-33 and MikroC for dsPIC :)

Post Reply

Return to “mikroC Beta testing”