Connect with us

Question about the PIC16F676 ?

Discussion in 'Electronic Basics' started by sine, Aug 28, 2003.

Scroll to continue with content
  1. sine

    sine Guest

    1. If I need to calculate a time for a delay, is it simply
    number_of_instructions_in_loop * T where T is 1/F
    or 1/4,000,000 in the case of the internal 4MHz clock ?

    2. The second part of the question is if the accuracy of the
    delay will be sufficient to implement a normal 24h clock ?

    3. Should I use the built in timer ?

    If anyone can answer some/all of these points I would be
    very happy.

    Tia.
     
  2. Byron A Jeff

    Byron A Jeff Guest

    Not exactly. First off the instruction rate is 1/4 the processor clock.
    Second jump/skip instructions take 2 instruction clock.
    Nope. I've build a sunrise/sunset light controller and even my supposedly
    accurate 32768 HZ watch crystal drifts by several minutes a month.
    Absolutely! it will make you life easier because you then don't have to keep
    such a watchful eye on instruction cycles. It also allows your program to
    go do something else while time is ticking away. For example my controller
    scans its pot/switch interface, and updates the PED display showing the time
    in the intervals between ticks.
    If you want an accurate clock and it is plugged into the wall you should do 2
    things:

    1) Count the number of cycles on the power line. While line frequency may vary
    ever so slightly during the course of day, there will be exactly 86400*(50/60)
    cycles over the course of a day.

    2) Battery backup. When you lose power you don't want to lose either the set
    time or the interval that elapses while the power is out. By having a battery
    backup you can retain the time and use the internal clock to maintain the time
    over the interval that you lose ticks.

    Hope this helps,

    BAJ
     
  3. Counting instructions is a pain on the PIC, since it doesn't have 16 or 32
    bit datawords. Thus, you are always dealing with carries, etc.

    One easy way to do this is to use the following macro:

    a set 0 ; used to generate labels for the PAUSE macro

    PAUSE MACRO t
    banksel GPIO
    bcf T1CON,TMR1ON ; turn off timer1
    movlw ((65536 - (t)) & 0xFF) ; set it up so there are t ticks left till
    rollover
    movwf TMR1L
    movlw (((65536 - (t)) >> 8) & 0xFF)
    movwf TMR1H
    bsf T1CON,TMR1ON ; turn it on
    bcf PIR1,TMR1IF ; clear the interrupt flag
    M_again#v(a):
    btfss PIR1,TMR1IF ; wait till timer rolls over
    goto M_again#v(a)
    a += 1
    ENDM

    Set up the T1CON to have a 0 prescaler, and it'll pause t uS (assuming the
    4MHz internal oscillator). If you use another prescaler, it'll pause for
    longer, obviously. If you are using the internal oscillator, make sure
    you've calibrated OSCCAL with the factory value.

    If you want to use interrupts, just get rid of the M_again loop, and wait
    for the TIMER1 interrupt.

    Regards
    Bob Monsen
     
  4. sine

    sine Guest

    Good discussion, thanks to all !!!
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-