Input capture

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.

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

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

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.


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

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.


Thank you for your quick and accurate response.


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

Thank you!


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.

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

Could you please send the IC_TEST.c file.

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;

	//listen for capture states
	capture_status = RdPortI(ICCSR);
	if(capture_status & 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;


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

Starting of the program what they mentioned? comments
Z-World, 2002

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

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.

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.



I’m so sorry :slight_smile:

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

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

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?

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

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