PDA

View Full Version : Timer0 and TMR0



Tomas
- 15th March 2004, 10:08
Dear All,

I'm trying to use interrupt in my program. I'm using PIC16F877, running at 4MHz. When interrupted i want to take a digital sample which is connected to one of PORTD's pin and store the signal using I2CWrite.
To get the interrupt i'm using TMR0 with prescaler confogured as shown below.

TMR0 will count to a quarter of PIC's speed which is 1M and its 1:256 roll-over rate will be (1/256 * 1M), 3906Hz. Then i divided this rate with the ratio i set in the prescaler. So for prescaler value 1:64 i can get (3906Hz/64) 0.016384Hz = 16.384ms.

Things i'm not sure are:
1. Does this mean the PIC is interrupted every 16.384ms?
2. If so i should be able to read a digital signal and store it (which takes only 10ms, I2CWrite) before the PIC is interrupted again.
3. If i divide 3906 by 32 (1:32) i will get 8.2ms. What does this time indicate?

My problem is the program jumps to the interrupt handler "very quickly" so i can not store the signal.
Using prescaler is not a good idea? Somebody told me to turn off the watchdog timer but i'm not sure how to disable the watchdog timer, how do i do that?

Please give me some more information regarding using interrupt with and without prescaler.

OPTION_REG = $55 '%01010101 the last three bitss
'sets TMR0 1:64
INTCON = $A0 'Enable TMR0 interrupt
. . .

Goto Start ' Skip subroutines

on interrupt goto IntIntialise_1

disable 'Disable interrupts during
'interrupt handling

IntIntialise_1:
LOW PORTC.1
ch6Digital = PORTD.1 'Read the digital signal
data1 = ch6Digital
EE_addr = $A2 'For just testing perpose
gosub sendToEEPROM_10 'Store it every 10ms

INTCON.0 = 0
INTCON.2 = 0 ' Reset timer interrupt flag
Resume
enable

The subroutine sendToEEPROM_10 is I2CWrite follwed by I2CRead, writing to 24LC256.


Best Regards,

Tom