caramoan tour package

caramoan tour package

Author Topic: how to make an exact 1 second delay using TMR0?  (Read 762 times)

Offline chimes27

  • CR2032 Battery
  • **
  • Posts: 32
  • Pogi/Ganda Points: 2
how to make an exact 1 second delay using TMR0?
« on: September 16, 2010, 12:27:54 PM »
i am currently using pic16f84a and a 4mhz external oscillator...i have a code for making a delay using tmr0 but it is'nt accurate.
i am also using 1:2 prescaler

here is the code:

-------------------------------------------------------------
list p=16f84a
#include <p16f84a.inc>

bsf status, rp0
clrf trisb
movlw 0f0h
movwf trisa
movlw b'10111000' ; prescaler 1:2
movwf option_reg
bcf status,rp0

main
..
..
..
..
call delay
..
..
..

delay
movlw 0a1h
movwf b
movlw 07h
movwf c
movlw 96 ; decimal
movwf TMR0

test
    btfss TMR0,7 ; test if TMR0 has reached 256 cycles (128 beats in prescaler)
    goto test      ;increment TMR0
    bcf TMR0,7   ;clear bit 7 only so that the other bits will not be affected
    decfsz b,1
    goto test
    decfsz c,1
    goto test
return
-----------------------------------------------

-the code is'nt accurate because 2 sets of two cycles will be disregarded; the call and return function

help please..

Philippine Electronics Forum

how to make an exact 1 second delay using TMR0?
« on: September 16, 2010, 12:27:54 PM »

Offline RiDdLeR???

  • Hydroelectric
  • ***
  • Posts: 3032
  • Pogi/Ganda Points: 208
Re: how to make an exact 1 second delay using TMR0?
« Reply #1 on: September 16, 2010, 01:12:51 PM »
simply adjust or compensate by incrementing the timer by 2

Philippine Electronics Forum

Re: how to make an exact 1 second delay using TMR0?
« Reply #1 on: September 16, 2010, 01:12:51 PM »

Offline AirWire

  • Size AA Battery
  • ****
  • Posts: 113
  • Pogi/Ganda Points: 4
  • Gender: Male
Re: how to make an exact 1 second delay using TMR0?
« Reply #2 on: September 22, 2010, 01:58:29 AM »
Better to use 32.768 Khz oscillator, not 4 MHz. 32.768 KHz, is equal to 2^15. Mas madaling gumawa ng algorithm compared sa 4 MHz. Besides, kung gagamitan mo ng battery yung circuit, mas matagal ang buhay ng battery mo. :)

Philippine Electronics Forum

Re: how to make an exact 1 second delay using TMR0?
« Reply #2 on: September 22, 2010, 01:58:29 AM »

Offline insomartin

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4825
  • Pogi/Ganda Points: 320
  • Gender: Male
  • Nalulunod lang...
Re: how to make an exact 1 second delay using TMR0?
« Reply #3 on: September 22, 2010, 04:32:27 AM »
^ ok din yung wall clock interrupt..
pero kakain nang isang pin. then again.
it's a nice 1hz interrupt source.
then pwede mo pa i assign yung timer0 mo sa ibang job.

Philippine Electronics Forum

Re: how to make an exact 1 second delay using TMR0?
« Reply #3 on: September 22, 2010, 04:32:27 AM »

Offline chimes27

  • CR2032 Battery
  • **
  • Posts: 32
  • Pogi/Ganda Points: 2
Re: how to make an exact 1 second delay using TMR0?
« Reply #4 on: September 24, 2010, 11:02:02 AM »
ok...ty po...:)

Philippine Electronics Forum

Re: how to make an exact 1 second delay using TMR0?
« Reply #4 on: September 24, 2010, 11:02:02 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com