# Input capture

**URL:** <https://forums.digi.com/t/input-capture/10610>\
**Category:** Rabbit\
**Created:** [May 6, 2011, 1:32pm UTC](https://forums.digi.com/t/input-capture/10610 "2011-05-06T13:32:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 6, 2011, 1:32pm UTC](https://forums.digi.com/t/input-capture/10610/1 "2011-05-06T13:32:44Z")

</div>

hello all,

I have a RCM3900 and I attack with input capture. I helped one of the sample (IC\_Test.c) but I missed one little thing. it is written:

WrPortI (ICS1R, NULL, 0xCC) / / //PG1 is pulse capture pin for channel 1

I know that ICS1R is Input Capture Source 1 Register. But I do not understand why 0xCC means PG1.  
In addition, this program uses the switch S3. How did you it connected to PG1

Thank you.

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 6, 2011, 2:36pm UTC](https://forums.digi.com/t/input-capture/10610/2 "2011-05-06T14:36:21Z")

</div>

Hi ,  
WrPortI (ICS1R, NULL, 0xCC) means setting the register ICS1R,To use parallel port G for start and stop conditions.

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 6, 2011, 1:38pm UTC](https://forums.digi.com/t/input-capture/10610/3 "2011-05-06T13:38:21Z")

</div>

More:  
capture\_status RdPortI = (ICCSR);  
if (capture\_status & 0x10)

We read and put away the state of the input capture. Then I do not understand why it is compared to 0x10?

Thank you

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [May 6, 2011, 2:26pm UTC](https://forums.digi.com/t/input-capture/10610/4 "2011-05-06T14:26:38Z")

</div>

You need to read the R3000 users manual more carefully and see what the settings for these registers mean.

Looking at the circuit diagram for the RCM3900 prototype board shows S3 is connected to G1.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 9, 2011, 9:18am UTC](https://forums.digi.com/t/input-capture/10610/5 "2011-05-09T09:18:45Z")

</div>

Yes I understood this. But I do not see why we use the 0xCC because R3000 user manual 0xCC is the port E …

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 9, 2011, 3:16pm UTC](https://forums.digi.com/t/input-capture/10610/6 "2011-05-09T15:16:25Z")

</div>

Hi,  
OxCC means (MSB)11001100(LSB),  
here 6,7 bits for Parallel Port G used for Start condition input,  
2,3 bits for Parallel Port G used for Stop condition input.

I think you can understand.

For the registers details see the R3000 processor manual.

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 7:30am UTC](https://forums.digi.com/t/input-capture/10610/7 "2011-05-10T07:30:34Z")

</div>

Hy,

Thank you for your quick and accurate response.

Friendly,

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 8:00am UTC](https://forums.digi.com/t/input-capture/10610/8 "2011-05-10T08:00:09Z")

</div>

Just one last question, I should replace 0xCC whereby if I want to use the switch S2?

Thank you!

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 10, 2011, 12:05pm UTC](https://forums.digi.com/t/input-capture/10610/9 "2011-05-10T12:05:15Z")

</div>

Hi,

In RCM3900, the PG1 using the switch S2.  
In Rabbit 3000 processor , the input capture channel can accept input from one of the following parallel port pins:  
PC1, PC3, PC5, PC7, PD1, PD3, PD5, PD7, PF1, PF3, PF5, PF7, PG1, PG3, PG5, PG7.

On the RCM3900 board S2 connected at PG1.

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 12:31pm UTC](https://forums.digi.com/t/input-capture/10610/10 "2011-05-10T12:31:48Z")

</div>

I also thought that S2 was connected to PG1 but when I test the program IC\_TEST.c when I press S2 nothing happens … Must I press S3 !!!  
So I think S3 is connected to PG1

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 10, 2011, 12:35pm UTC](https://forums.digi.com/t/input-capture/10610/11 "2011-05-10T12:35:08Z")

</div>

Could you please send the IC\_TEST.c file.

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 12:37pm UTC](https://forums.digi.com/t/input-capture/10610/12 "2011-05-10T12:37:01Z")

</div>

So this is IC\_test.C:

#class auto

void main()  
{  
char capture\_status;  
unsigned long pulse\_width;

```
WrPortI(ICS1R, NULL, 0xCC); //PG1 is pulse capture pin for channel 1

//use freq_divider for input capture prescaler
//(freq_divider-1) runs at 19200*16Hz, multiply by 4 for better range
WrPortI(TAT8R, NULL, freq_divider*4 - 1); //(TA8 prescaler)
WrPortI(ICCSR, NULL, 0x0c); //zero out counters
WrPortI(ICCR, NULL, 0x00); //no interrupts

//run counter start to stop
//start is falling edge, stop is rising edge
//latch counter on stop
WrPortI(ICT1R, NULL, 0x59);

pulse_width = 0;

while(1)
{
	//listen for capture states
	capture_status = RdPortI(ICCSR);
	if(capture_status &amp; 0x10)
	{
		//channel 1 stop occured
		//read capture value, LSB first
		pulse_width += RdPortI(ICL1R);
		pulse_width += RdPortI(ICM1R)*256;

		//76.8 = 19200*16*1000/4 (see TA8 setting above)
		printf("channel 1 pulse: %.1fms

```

", (float)pulse\_width/38.4);  
pulse\_width = 0;  
WrPortI(ICCSR, NULL, 0x04); //zero out counter  
}  
else if(capture\_status & 0x04)  
{  
printf("Input capture counter rolled over.  
");  
pulse\_width += 0x10000;  
}  
}

}

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 12:38pm UTC](https://forums.digi.com/t/input-capture/10610/13 "2011-05-10T12:38:21Z")

</div>

I want to say that I have not changed … he was such in my file SAMPLE /

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 10, 2011, 12:40pm UTC](https://forums.digi.com/t/input-capture/10610/14 "2011-05-10T12:40:19Z")

</div>

Starting of the program what they mentioned? comments  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ic\_test.c  
Z-World, 2002

```
This program is used with RCM3000 series controllers
with prototyping boards.

Description
===========
This program demonstrates a simple application of input
capture peripheral. It measures the duration of a low pulse
on switch S2 (PG1) and displays to STDIO. Port G bit 1 is
channel 1 pulse capture pin.

Note: Interrupts are not used in the demo.

Instructions
============
1. Compile and run this program.
2. Press and release switch S2 on the proto-board.
3. Observe the amount of time you hold S2 down in STDIO.

```

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 12:42pm UTC](https://forums.digi.com/t/input-capture/10610/15 "2011-05-10T12:42:44Z")

</div>

RCM3000…

I’m so sorry 🙂  
Thanks

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 10, 2011, 12:49pm UTC](https://forums.digi.com/t/input-capture/10610/16 "2011-05-10T12:49:40Z")

</div>

The RCM3900 having the processor R3000 only, I have tested this program on the board 3209, on that board it was connected S2 at PG1 only. Just i want to confirm that in your program what they mentioned as comments. …

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 12:58pm UTC](https://forums.digi.com/t/input-capture/10610/17 "2011-05-10T12:58:37Z")

</div>

Yes thank you I changed the comments. But I also saw the drawings of RCM 3900 that was connected to S2 PG0.  
Where do I change 0xCC PG0 to whether the capture input???

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 10, 2011, 1:10pm UTC](https://forums.digi.com/t/input-capture/10610/18 "2011-05-10T13:10:31Z")

</div>

Hello, Do not change the comments. I want to know that what they mentioned in the comments. I want to confirm that whether they mentioned wrong information in the document. Have you seen the R3900 user manual?

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 10, 2011, 1:18pm UTC](https://forums.digi.com/t/input-capture/10610/19 "2011-05-10T13:18:06Z")

</div>

Nan no false information in the comments …  
Oh I just saw that PG0 can not be an input capture.  
Before you told me 0xCC defined initial conditions (bits 6 and 7) and stop conditions (2 and 3). Can you explain a little more running because I thought it was based on years S3 S3 is a switch, it can not be connected to the cock and 7,6,3,2 PG0 same time …

Sorry for not understanding

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 10, 2011, 1:24pm UTC](https://forums.digi.com/t/input-capture/10610/20 "2011-05-10T13:24:45Z")

</div>

Hello, if you do not mind , could you please send the comments in the starting of the program what they mentioned? after that we can discuss about this issue.

Thank you

[Next page](https://forums.digi.com/t/input-capture/10610.md?page=2)
