asm causes spontaneous reset.

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
cybermike
Posts: 2
Joined: 13 Sep 2009 14:42

asm causes spontaneous reset.

#1 Post by cybermike » 13 Sep 2009 14:49

Hey all

Inserting this ASM for a very fine time delay causes a spontaneous reset. Any ideas why ?


Code: Select all

                 linedelay = l0
                 asm
dolinedelay:
                 DEC _linedelay, _linedelay
                 BRA NZ, dolinedelay
exitlinedelay:
                 end asm

cybermike
Posts: 2
Joined: 13 Sep 2009 14:42

#2 Post by cybermike » 14 Sep 2009 13:22

It would appear as though the compiler does not interpret the address of the label in the asm area

Code: Select all


resamplesynch1:
                 temp = testbit(CMCON, 6)
                 if temp = 1 then
                 goto resamplesynch1
                 end if
                 clearbit(portb, 0)

resamplesynch2:  'time delay on horizontal scan line
                 cycle = cycle + 1
                 if cycle < l0 then
                 goto resamplesynch2
                 end if

                 linedelay = l0
                 asm
dolinedelay:
                 DEC _linedelay, _linedelay
                 BRA NZ, dolinedelay
exitlinedelay:
                 end asm
                 'clearbit(portb, 0)
                 'clearbit(portb, 0)
                 setbit(portb, 0)
                 setbit(portb, 0)
                 clearbit(portb,0)



Translates into 



$D760	$	_main_resamplesynch1:
;gpstracker54telsie.dbas,7929 :: 		temp = testbit(CMCON, 6)
$D760	$803182			MOV	CMCON, W2
$D762	$200400			MOV	#64, W0
$D764	$610100			AND	W2, W0, W2
$D766	$200060			MOV	#6, W0
$D768	$DE1100			LSR	W2, W0, W2
$D76A	$21A410			MOV	#@_temp, W0
$D76C	$784802			MOV.B	W2, [W0]
;gpstracker54telsie.dbas,7930 :: 		if temp = 1 then
$D76E	$514061			SUB.B	W2, #1, W0
$D770	$3A0002			BRA NZ	gpstracker54telsie_L_2254, gpstracker54telsie_L_2254
$D772	$	gpstracker54telsie_L_2253:
;gpstracker54telsie.dbas,7931 :: 		goto resamplesynch1
$D772	$04D760			GOTO	_main_resamplesynch1
$D776	$	gpstracker54telsie_L_2254:
;gpstracker54telsie.dbas,7932 :: 		end if
$D776	$	gpstracker54telsie_L_2255:
;gpstracker54telsie.dbas,7933 :: 		clearbit(portb, 0)
$D776	$2FFFE2			MOV	#65534, W2
$D778	$202C80			MOV	#@PORTB, W0
$D77A	$610810			AND	W2, [W0], [W0]
;gpstracker54telsie.dbas,7935 :: 		resamplesynch2:  'time delay on horizontal scan line
$D77C	$	_main_resamplesynch2:
;gpstracker54telsie.dbas,7936 :: 		cycle = cycle + 1
$D77C	$200012			MOV	#1, W2
$D77E	$EB0180			CLR	W2+2
$D780	$21CB80			MOV	#@_cycle, W0
$D782	$410230			ADD	W2, [W0++], W4
$D784	$4982A0			ADDC	W2+2, [W0--], W4+2
$D786	$88E5C4			MOV	W4, _cycle
$D788	$88E5D5			MOV	W4+2, _cycle+2
;gpstracker54telsie.dbas,7937 :: 		if cycle < l0 then
$D78A	$80EF32			MOV	_l0, W2
$D78C	$EB0180			CLR	W2+2
$D78E	$520002			SUB	W4, W2, W0
$D790	$5A8003			SUBB	W4+2, W2+2, W0
$D792	$310002			BRA GEU	gpstracker54telsie_L_2257, gpstracker54telsie_L_2257
$D794	$	gpstracker54telsie_L_2256:
;gpstracker54telsie.dbas,7938 :: 		goto resamplesynch2
$D794	$04D77C			GOTO	_main_resamplesynch2
$D798	$	gpstracker54telsie_L_2257:
;gpstracker54telsie.dbas,7939 :: 		end if
$D798	$	gpstracker54telsie_L_2258:
;gpstracker54telsie.dbas,7941 :: 		linedelay = l0
$D798	$80EF30			MOV	_l0, W0
$D79A	$891DC0			MOV	W0, _linedelay
;gpstracker54telsie.dbas,7943 :: 		dolinedelay:
$D79C	$	DOLINEDELAY:
;gpstracker54telsie.dbas,7944 :: 		DEC _linedelay, _linedelay
$D79C	$E917DC			DEC	_LINEDELAY, _LINEDELAY
;gpstracker54telsie.dbas,7945 :: 		BRA NZ, dolinedelay

$D79E	$3AFFFE			BRA NZ	NZ, DOLINEDELAY   <<<<< This address is incorrect. 

;gpstracker54telsie.dbas,7946 :: 		exitlinedelay:
$D7A0	$	EXITLINEDELAY:
;gpstracker54telsie.dbas,7950 :: 		setbit(portb, 0)
$D7A0	$801640			MOV	PORTB, W0
$D7A2	$700061			IOR	W0, #1, W0
$D7A4	$881640			MOV	W0, PORTB
;gpstracker54telsie.dbas,7951 :: 		setbit(portb, 0)
$D7A6	$700261			IOR	W0, #1, W4
$D7A8	$881644			MOV	W4, PORTB
;gpstracker54telsie.dbas,7952 :: 		clearbit(portb,0)
$D7AA	$2FFFE2			MOV	#65534, W2
$D7AC	$202C80			MOV	#@PORTB, W0
$D7AE	$620802			AND	W4, W2, [W0]

Is there a way to get paramater driven sub 1uSecond delays (+- 200nS increments)

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#3 Post by anikolic » 14 Sep 2009 15:09

Hi,
It seems that the asm routines you use are not interpreted correctly and the compiler keeps generating the wrong address of your linedelay variable. Until new PRO compiler is officially out, with these issues solved, you can do a workaround with following code:

Code: Select all

   linedelay = 10
                 asm
dolinedelay:
                 DEC.B _linedelay
                 MOV.B W0, _linedelay
                 BRA NZ, dolinedelay
exitlinedelay:
                 end asm
As you can see, I assumed that linedelay is not going to be used for longer delays, and assumed it as byte type. This is why you have .B on your DEC and MOV commands, because they are now told to work with bytes only, and not with word values, as default in dsPIC. The reason why an extra MOV is added to your code is because DEC generates previously mentioned address error, when destination is different from WREG. This is why we must load the decrement result from WREG into linedelay again. Try calculating how long this extra cycle takes, and try making the desired delay.

Best wishes,
Aleksandar
Web Department Manager

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”