P2 Input Capture questions?
Capt. Quirk
Posts: 872
in Propeller 2
Chip's terminology is not the same as other suppliers, so that can make smart pins harder to follow.
I have not purchased a P2 yet, but after trying to read the data sheet,
I am not certain the P2 provides an easy way to perform Input Capture.
A simple tachometer that is capable of recording the time period of one
revolution and converts that to rpm is at the core of all my potential
P2 projects.
A simple example is my ignition test stand spinning at the low speed of
2307 rpm. The period is 26ms, and because it is set up with a hall sensor
25ms is high, and 1ms is low.
Normally I count from falling edge to falling edge (26ms @2307rpm).
So many of the P2 pin states talk about accumulating clock cycles within
a hi or low state, or events within a period.
Pin State %10_000 looks promising, but there is no mention of falling
edges.
Is there an easy way to perform input capture?
Can input capture be done with an interrupt?
On some micro-controllers DMA seems to be helpful. Is a Streamer
helpful for input capture on the P2?
Can the clock speed be reduced to 1mhz on the input capture pin?
Thanks
Bill M.
Comments
I suppose you could have two adjacent pins on the same signal, one monitoring high duration, and one monitoring low duration. Combine the counts to get the input capture. Kinda clunky, though.
High and low periods are added together then divided into a scaled system clock value.
Test output show high perio of 25mS and low period of 1mS.
Calculated RPM is ~2304.
Yes, if you wanted to set up an event, the HW pin abilities mean you would usually use the pin HW
Interesting question. I think the streamer is timed-only, and cannot trigger from a smart pin capture.
No. Time units are all in SysCLKS, but they capture 32b, so you just shift the unwanted bits away.
on P2 if we take 100MHz, one period of 26ms is 2600000
Possible period-capture modes would be :
%MMMMM:
a) %10011 = for X periods, count time
b) %10101 = for periods in X+ clocks, count time
c) %10111 = for periods in X+ clocks, count periods
a) mode measures over a defined number of whole periods, which can be X=1, or 10, or anything that gives a sensible read rate.
b) & c) mode gives an (appx) known read rate, and auto-scales, and auto-stretches too.
Usually you pair synchronized 2 pins one in each of b) and c) as you need to know how many whole periods were in that window.
(see the reciprocal counter examples).
This gives you a very wide dynamic range.
mode %10101 = P_COUNTER_TICKS
should work to measure the periode ticks with smartpins.
Here is a Spin2 example that works for me. You can read the current periode ticks anytime from the smartpin.
if you set the mode for P39 with: P_PERIODS_TICKS + P_FILT1_AB, then the input gets filtered with a 600ns filter time, that is: glitches on the posedges will not be counted for 600ns. The input filters can also be configured, but there are 4 default filter settings.
Andy
Tweaked ref to 25.007mS high period and got this result
Circuitsoft for your input!
Hopefully in the near future, I can respond with intelligent
questions.
Bill M.