Page 1 of 1

help..TMR2 to make 1Mhz interrupt per second

Posted: Thu Dec 11, 2014 4:29 pm
by hertz89
hi
i am using flowcode 5 free version and 16f627a with 20 MHz crystal.....i want use TMR2 to make 1Mhz interrupt per second...i couldn't make it....it give me about 45000 interrupt per second...why?

Re: help..TMR2 to make 1Mhz interrupt per second

Posted: Thu Dec 11, 2014 5:35 pm
by Benj
Hello,

If you set the prescaler and postscaler to 1:1 and the rollover to 5 then the maths says you should get a interrupt frequency of 1MHz.

However with only 5 instructions between each interrupt it would be my guess that you cannot do anything useful in 5 instructions.

Also there may be at least a couple of instructions overhead in firing the interrupt so my guess is a 20MHz PIC cannot generate a 1MHz interrupt.

An AVR might have more chance as you don't have the inherent divide by 4 on the clock speed as you do with 8-bit PICs.

Do you mind me asking what you intend to use the 1 MHz interrupt for? If it's for driving output pins then you might struggle as I don't think the I/O will run that fast even on an AVR, I could be wrong.

Re: help..TMR2 to make 1Mhz interrupt per second

Posted: Thu Dec 11, 2014 8:50 pm
by hertz89
hi Benj
i want Measure pulse period..any suggestion?

Re: help..TMR2 to make 1Mhz interrupt per second

Posted: Thu Dec 11, 2014 9:15 pm
by kersing
As you are not sharing a tip or trick I have moved this message to the appropriate forum. Please do not use the 'Tips and Tricks' forum for requests for help.

Re: help..TMR2 to make 1Mhz interrupt per second

Posted: Fri Dec 12, 2014 1:20 pm
by Benj
Hello,

What's the min / max frequency of the pulse you want to monitor and what resolution do you need?

Re: help..TMR2 to make 1Mhz interrupt per second

Posted: Fri Dec 12, 2014 1:33 pm
by hertz89
the pulse length 500ms...i want highest resolution..1us or ns