High frequency interrupt (16F15323)

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Lord Grezington
Flowcode V4 User
Posts: 229
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 18 times
Been thanked: 23 times
Contact:

High frequency interrupt (16F15323)

Postby Lord Grezington » Sat Jan 26, 2019 7:06 pm

Hey everyone

Looking at a new project, thinking about using a IOC pin to measure frequencies around 100Khz. Not really done thes high frequencies before, so the first things that come to mind are?

What clock frequency will I need? is it possible to do it with a 32Mhz interlal oscillator?
The program itself wont actually be performing many other tasks other than checking a couple other inputs and setting some PWM outputs.

Was thinking about using the IOC and a timer, but is tehre an easier way ? Thinking along the lines of something like Using Timer1 and measuring the transition on T0CK1 or something? How would I do this and is using hte IOC not easier? which one will be more accurate? (measuring square wave duty cycle on the input).

Another thing I may want to look at is how do I prioritise the various interuppts?

And finally, is it possible to use the IOC port twice? meaning can I set the IOC to look at 2 pins and run one macro, then set two other pins to run a different macro?

Thanks

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1089
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 334 times
Been thanked: 544 times
Contact:

Re: High frequency interrupt (16F15323)

Postby QMESAR » Sun Jan 27, 2019 7:59 am

HI
Looking at a new project, thinking about using a IOC pin to measure frequencies around 100Khz. Not really done thes high frequencies before, so the first things that come to mind are?

These things are normally done by using the Capture Compare module of the PIC as it allows you to read the Capture registers which is in effect a Timer value

P1.jpg
P1.jpg (104.82 KiB) Viewed 702 times



I would not use any Clock less that 32Mhz and my reason is your 100Khz signal has a time of 10uSec a PIC 16 running at 32Mhz has Tcy of 125nSec
so the time you have between catures is 10/125 = 80 cycles, not much to calculate the frequency and other stuff from the captured values.

Note that if you do not need to capture each transition of the signal you can set the Capture module to capture every 4 or 16th pulse allowing you to get more time between the captures for the other things you need in code

P2.jpg
P2.jpg (18.86 KiB) Viewed 702 times


But I am sure you can capture the signal and the chip has 2 CCP modules you can detect 2 signals at once .
Check out the datasheet section Capture and compare and you will see you can achieve what you need to do with this chip with just using the chip correctly.
These users thanked the author QMESAR for the post:
chipfryer27 (Mon Jan 28, 2019 12:31 am)
Rating: 5.56%