|
|
View previous topic :: View next topic |
Author |
Message |
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
PIC24 input capture question |
Posted: Mon Mar 18, 2024 9:25 am |
|
|
Device: PIC24EP512GP806
Compiler: 5.116
Hi guys,
Question here on something I've never tried before.... I am testing-out a new device that has an analog signal that gets output as a varying pulse width up to 4kHz.
I've never used the input capture module and pardon my ignorance but what is the difference between that module vs using a simple external CN interrupt on that signal, combined with a 32-bit count-up variable in a timer so that upon every other CN interrupt transition, I read the count value of that variable, substract from the previous read value and calculate the frequency?
My MCU uses the following for its clocking:
#define XTAL_FREQ 29491200 // 29.4912MHz
#define SYS_CLOCK 129024000 // 129.024MHz
Is this too slow such that using a capture module would be overkill? Would be more effective to use the capture module vs my method with a CN interrupt and a timer counter?
What are the drawbacks / advantages of using one vs the other?
Thanks,
Ben |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Mon Mar 18, 2024 10:05 am |
|
|
The point about the input capture module, is it captures the count value
between two 'events' (usually either two rising edges for frequency or
a rising and falling edge for period), and stores this into a buffer. The
buffer is normally 4 deep, and you can elect to interrupt when 1, 2, 3
or 4 values have been stored. You can also elect to capture on every
event, or every 4 or 16 events. The time you capture is from a timer,
and this has prescalers, so you can work from the CPU frequency or
a much lower division of this. Normally it is only a 16bit value.
Advantage is the ability to capture without any processor overhead, and
capturing multiple values. Downside (for you), is it is normally only
16bit. The key big thing is that the capture is accurate. Using an edge
and interrupt, you will get latency getting into the interrupt, and if
other interrupts trigger this latency may vary. Result inaccuracy.
At 4KHz, the latency might not be a problem. With the peripheral, you
don't even have to interrupt. You can just read the buffer and get the last
count value at any time. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Mon Mar 18, 2024 10:42 am |
|
|
Thanks for the response.
Well if I look at it this way, if each sample is measured with the count of a 16-bit value, that's 65535 which yields a granularity of 0.061Hz per step so that should be enough for 4kHz.
I will look at ex_capture.c shortly. I guess this is the best example?
Ben |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|