# Just one second!

Status
Not open for further replies.

#### Skyknight

##### New Member
Hello all! I need your neurons :twisted:

I'm working with a PIC16F629, writing a program in its assembly:

http://chips.uvigo.es/~skyknight/Electronica/12F675.pdf

I want to make a passive wait of one second (what I want to say with passive is that I want the timer interrupts me when finish counting that single second, I don't want to be checking once and again till the second is past, ok?). So, here is what I've got:

Internal RC clock of 4MHz
TMR0 [8 bits, prescaled 1:256]
TMR1 [16 bits, prescaled 1:8]

I don't need an exact second (I mean, 1.1 second is ok too)

Now, pleeease. Be kind and suggest me some ideas about how to do it. I thought about chaining both timers. The key is I've never worked with any 16 bit timer and I'm quite confused about how to make it work together the other timer. :?

#### Skyknight

##### New Member
Can't anyone help me :?:

#### Skyknight

##### New Member
No, thanks, kindalgp. But in the end, the way they think the timing in those tutorials results unuseful for my needs.

I think I'll change the way I'm doing things or I'll never end this. Thanks anyway.

##### New Member
How about counting down your own counter (on or two bytes) with each clock interrupt in the ISR ? Then if you reach zero, deactivate the timer, set a flag for the rest of your program, preload again for one second and start when needed again.

#### Skyknight

##### New Member
I think I understand you: You're suggesting me to make myself another
timer, isn't it? But, can you explain me this you wrote in another way,please?

"...with each clock interrupt in the ISR?"

#### moki

##### New Member
Have you posted your question on the Piclist? Lots of help there!

#### TheAnimus

##### New Member
Hi timing problems like this are realy quite easy, the first thing to remeber is that the PIC has an instruction cycle of 1MHz (4 / 1)

0.000001s per instruction, a 8bit timer with 256 prescaler would have an interval of 0.000001 * 256 * 256

so that is now 0.065536second interval

a simple way of getting somthign like a second, would be to stack a file register with 15 and at the top of your ISR (Interupt Service Routine, where the TM0 int will goto)
have something like
Code:
DECFSZ    0x20 ; some file reg
GOTO    ENDINT
MOVLW     d'15'
MOVWF     0x20 ;

ENDINT:
BCF    INTCON, T0IF
RETFIE
Hope that helps!

#### TheAnimus

##### New Member
Darn phpBB messed up with a nice error about a missing email template :?

bit strange as i hand't asked for a notify me when a reply is posted!

Status
Not open for further replies.