pic frequency interrupt
Trevoor has contacted me by PM to explain the error in his first message which originally said 2MHz not KHz.
As the other have said, the 16F84 is not a good choice for this application and the 16F628A is *almost* identical but has extra features. I have used 628A's as plug in upgrades for 84A devices and mailed them to customers to swap over they are so similar. The 628A is also cheaper and you may be able to utilize it's internal oscilator to reduce your component count as well.
You haven't said why you need 2KHz to drive a DC motor so I'm guessing you are controlling it's speed by PWM. The 628A has built in PWM, the 84A does not.
Having said that, if you really want to use the 84A, this is what you do:
Based on your clock frequency, work out the prescaler ratio and value to pre-load into TMR0 to give a 2KHz roll-over interrupt.
In your interrupt routine, re-load the value into TMR0 for the next roll-over (remember it counts up not down so load the number of remaining counts, not the number you actually want - also remember that as the time in interrupt TMR0 = 0)
Now clear your PWM output pin, this is your frame reference point.
At this point you are resetting you output pin at a 2KHz rate.
Now you need to use a counter in software to set the pin (switch it on). Ideally, you want a counter that reaches maximum value in 500uS so it gives as many possible different values. Set it at zero at the start of your frame period. When you reach the desired count, turn the pin on.
This is only one of many ways you can do it. For example you could reverse the on and off in the example above or you could drive your counter from the timer and provide the framing period in software. You can even do it without the timer at all.
Brian.