1. 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.
    Dismiss Notice

Just one second!

Discussion in 'Microcontrollers' started by Skyknight, May 17, 2003.

  1. Skyknight

    Skyknight New Member

    Joined:
    May 1, 2003
    Messages:
    97
    Likes:
    0
    Location:
    Spain
    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. :?

    Thanks in advance!
     
  2. Skyknight

    Skyknight New Member

    Joined:
    May 1, 2003
    Messages:
    97
    Likes:
    0
    Location:
    Spain
    Can't anyone help me :?: :(
     
  3. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA
    What about the links I had PM'ed you? Didn't they help you in any way?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Skyknight

    Skyknight New Member

    Joined:
    May 1, 2003
    Messages:
    97
    Likes:
    0
    Location:
    Spain

    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.
     
  6. Madmartin

    Madmartin New Member

    Joined:
    May 21, 2003
    Messages:
    24
    Likes:
    0
    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.
     
  7. Skyknight

    Skyknight New Member

    Joined:
    May 1, 2003
    Messages:
    97
    Likes:
    0
    Location:
    Spain
    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?"

    Thanks for your reply :D
     
  8. moki

    moki New Member

    Joined:
    May 28, 2003
    Messages:
    20
    Likes:
    0
    Location:
    Durban, South Africa
    Have you posted your question on the Piclist? Lots of help there!
     
  9. TheAnimus

    TheAnimus New Member

    Joined:
    Jun 22, 2003
    Messages:
    116
    Likes:
    1
    Location:
    England
    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 (text):

    DECFSZ    0x20 ; some file reg
         GOTO    ENDINT
    MOVLW     d'15'
    MOVWF     0x20 ;
    ; your 0.98second interval here

    ENDINT:
    BCF    INTCON, T0IF
    RETFIE
     
    Hope that helps!
     
  10. TheAnimus

    TheAnimus New Member

    Joined:
    Jun 22, 2003
    Messages:
    116
    Likes:
    1
    Location:
    England
    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!
     

Share This Page