help..TMR2 to make 1Mhz interrupt per second

Moderator: Benj

Post Reply
hertz89
Posts: 19
Joined: Sat Mar 22, 2014 6:30 pm
Been thanked: 3 times
Contact:

help..TMR2 to make 1Mhz interrupt per second

Post 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?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

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

Post 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.

hertz89
Posts: 19
Joined: Sat Mar 22, 2014 6:30 pm
Been thanked: 3 times
Contact:

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

Post by hertz89 »

hi Benj
i want Measure pulse period..any suggestion?

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

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

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

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

Post by Benj »

Hello,

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

hertz89
Posts: 19
Joined: Sat Mar 22, 2014 6:30 pm
Been thanked: 3 times
Contact:

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

Post by hertz89 »

the pulse length 500ms...i want highest resolution..1us or ns

Post Reply