Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

My PIC16F628 doubt threat

Status
Not open for further replies.
AHH! So you mean that d1 decrements like this:

77, zero? No. $+2, goto Delay_0 again. 76.. zero? No.. etc.. Zero? Yes. Skip $+2 decrement 196 decimal to 195 decimal, goto Delay_0, starts decrementing again the 78 decimal.. and so on until the 196 reach 0. When he reach 0 he goto nop (spending more cycles) and then goes back to the main routine. That's it? BTW, it's necessary to add the goto $+1 and nop?
No. Not quite. When d1 reaches zero and d2 gets decremented, the code goes back and decrements d1 again. An unsigned byte can't be negative, so when you decrement that byte with a value of zero it becomes $ff (255). So after the first time d1 is $ff every time through. It's not getting reloaded with $4e, you see?

Also, every time decfsz hits zero, it becomes a two-cycle instruction for the branch. Also, goto is a two cycle instruction, so count in all those extra cycles.
 
Last edited:
Hmm.. let me recapitulate:

77, zero? No. $+2, goto Delay_0 again. 76.. zero? No.. etc.. Zero? Yes. Skip $+2 decrement 196 decimal to 195 decimal, goto Delay_0, starts decrementing again but now from 255. 254, zero? No. goto Delay_0. 253.. Zero? No.. etc.. zero? Yes. Skip $+2 decrement d2 to 194 and so on until the 196 reach 0. When he reach 0 he goto nop (spending more cycles) and then goes back to the main routine.

He doesn't goes back to 78 because the 0 was saved in the W register?

If is what I wrote above, how do you calculate the amount of time? In this case, 250mS. How do I have to calculate the cycles? (or how is called)

1 Cycle is 1uS with 4MHz XTAL right?
 
He doesn't goes back to 78 because the 0 was saved in the W register?
When d1 reaches zero, the code decrements d2 and jumps back to Delay_0. d1 is still zero from before, so it now gets decremented and becomes 255.

If is what I wrote above, how do you calculate the amount of time? In this case, 250mS. How do I have to calculate the cycles? (or how is called)
See previous post. Where it mentions that decfsz is sometimes a 2-cycle instruction and that goto is always a 2-cycle instruction. Counting cycles gets a whole lot more complex when you have to figure those in.

1 Cycle is 1uS with 4MHz XTAL right?
Yes.
 
Last edited:
Heres a little tip:

Instructions Per Second = Crystal (in mhz) * 1,000,000 / 4
or (they are the same)
Instructions Per Second = Crystal (in mhz) * 250,000

EXAMPLE: 20Mhz * 250,000 = 5,000,000 IPS (instructions per second)

Knowing that we can get how long each instruction takes. We have o divide the 1 by IPS

EXAMPLE...
X = 1 / 5,000,000 = 0.0000002 Seconds (s) Per Cycle

Note the .0 Places. The "," is there only as a visual helper. You rather see .000001 or .000,001. They are the same but easier to see the places with a comma.

.001 - .999 = mS (3 places) (Thousands)
.000,001 - .000,999 = uS (6 places) (Hundred Thousands)
.000,000,001 - .000,000,999 = nS (9 places) (Hundred Millions)

X falls into the nS range being .000,000,2 so we have to multiply it by its places. So:
X = .000,000,2 * 1,000,000,000 = 200nS Per Instruction

If im wrong tell me now lol :D
 
Last edited:
Hello there. I'm trying to do a simple tutorial from your website.. preciselly the 1.9 and I've a doubt here.

This is a short sample o the main loop that calls a table:

Code:
Start	clrf	count			;set counter register to zero
Read	movf	count, w		;put counter value in W
	call	Table	
	movwf	LEDPORT
	call	Delay

and here is my doubt:

Code:
 Table	ADDWF   PCL, f			;data table for bit pattern
	retlw	b'10000000'
        retlw   b'01000000'
        retlw   b'00100000'

Could you explain me why and how it works the ADDWF PCL, f?
 
Dou you expect to solve ALL your doubts posting here until when?

What if for any reason you are left with no access to Internet for three months?

Use MPLAB to simulate and try to reply your own questions. Do the hard part first.

Believe it or not, it is a friendly advice.

Buena suerte.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top