wrote (via Tim Hamel): > I need to learn about prescalers, couse I have to control the time > of jumping to a certain subroutine(my program will drive dc motors > with PWM). Birsen: What follows is a slightly-edited version of a message I posted here about four years ago. I hope it helps. Timer-0 has four components: The clock input (either from the TMR0 pin or from the internal instruction clock), the TMR0 prescaler, the TMR0 register, and the TMR0 interrupt flags (GIE, T0IE, and T0IF). CLOCK INPUT: You'll probably use the internal instruction clock as your TMR0 input; I'll assume that your PIC is running at 4 MHz. Since there's an internal divide-by-4 between the oscillator frequency and the instruction clock, this means that instruction clocks occur at a 1 MHz rate. PRESCALER: The TMR0 prescaler is set (via 4 bits in the OPTION register) to divide-by-1, -2, -4, -8, -16, -32, -64, -128, or -256. The TMR0 input clock (1 MHz in your case) is passed to the prescaler, whose divided-down output is then fed to the TMR0 register. For example, if the TMR0 prescaler is set to divide-by-4 and the PIC is running at 4 MHz, the prescaler will send a 250 KHz clock to the TMR0 register. TMR0 REGISTER: The TMR0 register can be preloaded with any 8-bit value that you like. Each clock pulse from the prescaler increments the contents of the TMR0 register. When the value in the TMR0 register rolls over from 0xFF to 0x00, the T0IF flag is set (the TMR0 register continues to be incremented on every pulse from the prescaler, though). INTERRUPT FLAGS: If the GIE and T0IE flags are set when the T0IF flag is set, an interrupt is generated (the GIE bit is automatically cleared (to temporarily prevent further interrupts while your interrupt routine is executing), and the PIC jumps to the "interrupt vector" at location 0x04. Your interrupt-service routine at that location should check the T0IF flag to determine the source of the interrupt, then must clear the T0IF flag to prevent the PIC from immediately jumping back to the interrupt routine when interrupts are re-enabled. At this point in the interrupt routine, you can re-load the RTCC with any appropriate value. When you're finished handling the interrupt, your code should execute a RETFIE instruction, which will automatically set the GIE bit to re-enable interrupts and return to your main program. -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - San Diego, California === http://www.geocities.com/SiliconValley/2499