Inputs: None (captures from hardware pins)
Outputs: Dynamic based on configuration
| Output Port | Condition | Description |
|---|---|---|
IC1_Up, IC1_Down | Mode 3 | Pulse width measurements (rising and falling edge times) |
IC1_Up, IC1_Period | Mode 5 | High pulse width and signal period |
IC1_Down, IC1_Period | Mode 10 | Low pulse width and signal period |
The block supports 1 output datatype representation:
| Output Type | Range | Description |
|---|---|---|
| uint16 | 0 to ICxmax | Raw timer counts at capture event |
Integer values transferred directly from ICxBUF capture registers—no runtime computation. Users handle conversion to physical time units.
The block creates workspace variables for scaling calculations:
| Variable | Description |
|---|---|
IC1max, IC2max, … | Maximum timer count per IC channel (based on associated timer) |
ICxmax | Vector of all channel max values (e.g., [65535 65535]) |
Scaling formula: Time_seconds = Timer_Ticks × (Max_Period_s / ICxmax)
Where Max_Period_s is the configured timer period in seconds.
Example: With IC1max = 65535 and timer max period = 0.25s:
Time_Resolution = 0.25 / 65535; % ≈ 3.8 µs per tick
Pulse_Width_s = IC1_Up × Time_Resolution;
Raw counts preserve full resolution—users apply application-specific scaling (frequency, RPM, duty cycle) in their model.
Hardware Considerations: PIC32 devices have hardware FPU—float scaling is efficient. dsPIC30F/33F/33E/33C lack FPU—use fixed-point arithmetic in time-critical loops. dsPIC33A has hardware FPU.
| Parameter | Description | Example |
|---|---|---|
| Channel | IC channel numbers to use | [1 2 3] for IC1, IC2, IC3 |
| Mode Value | Description | Captures |
|---|---|---|
| 1 (0x001) | Edge detect, every edge | Every rising or falling edge |
| 2 (0x002) | Edge detect, every 4th edge | Every 4th rising or falling edge |
| 3 (0x003) | Edge detect, every 16th edge | Every 16th rising or falling edge |
| 4 (0x004) | Capture rising edge only | Timer value on rising edge |
| 5 (0x005) | Capture falling edge only | Timer value on falling edge |
| 6 (0x006) | Capture every 4th rising edge | Every 4th rising edge |
| 7 (0x007) | Capture every 16th rising edge | Every 16th rising edge |
| Parameter | Description | Options |
|---|---|---|
| Channel_UP_Down_Periode | Measurement type per channel | 3: Pulse width (up & down), 5: Pulse up + period, 10: Pulse down + period |
| ChangeDetect | Output only when value changes | ON/OFF per channel |
| Timer_Ref | Associated timer for each channel | Timer index or -2 for system timer |
| Parameter | Description |
|---|---|
| PIN_IC1 … PIN_IC16 | Remappable pin selection for each IC channel (dsPIC33E/C/A, PIC32) |
| Family | IC Channels | Edge Detection | Timer Association |
|---|---|---|---|
| dsPIC33F/33E | IC1-IC8 | Rising, Falling, Both | Timer2/Timer3 |
| dsPIC33C/33A | IC1-IC16 (device dependent) | Rising, Falling, Both | Timer1-Timer5 |
| PIC24F | IC1-IC9 | Rising, Falling, Both | Timer2/Timer3 |
| PIC32MK | IC1-IC9 | Rising, Falling, Both | Timer2/Timer3 |
ICxCON1 register:
ICSIDL = 0 (continue in idle mode)
ICTMR = timer selection (0=Timer3, 1=Timer2, others device-specific)
ICI = interrupt prescaler
ICM = capture mode (0x1-0x7)
ICxBUF - Capture buffer (read-only, contains timer value)
ICxCON2 (33C/33A) - Additional control bits, trigger synchronization
IC interrupts trigger on each capture event:
% Pulse width measurement (mode 3)
RisingEdge_Time = IC_RisingCapture / Timer_Frequency;
FallingEdge_Time = IC_FallingCapture / Timer_Frequency;
PulseWidth = FallingEdge_Time - RisingEdge_Time;
% Period measurement (mode 5)
Period = (IC_CurrentCapture - IC_PreviousCapture) / Timer_Frequency;
% Measure encoder pulses on IC1 and IC2
Channel: [1 2]
Capture Mode: [4 4] % Rising edge only on both
Channel_UP_Down_Periode: [3 3] % Pulse measurement
Timer_Ref: [2 2] % Both use Timer2
Change Detect: [ON ON] % Output only on changes
Result: Captures encoder A/B channel transitions for position/speed calculation.
% Measure signal frequency on IC1
Channel: 1
Capture Mode: 4 % Rising edge
Channel_UP_Down_Periode: 5 % Pulse + period
Timer_Ref: 3 % Timer3 with maximum range
Result: Outputs pulse width and period. Frequency = 1 / (Period_ticks / Timer_Freq)
% Measure PWM duty cycle
Channel: 1
Capture Mode: 1 % Every edge (rising and falling)
Channel_UP_Down_Periode: 5 % Up time + period
Result: DutyCycle = (PulseWidth / Period) * 100%
% Timestamp external events
Channel: [1 2 3] % Three event sources
Capture Mode: [4 4 4] % Rising edge trigger
Timer_Ref: [-2 -2 -2] % Use high-resolution system timer
Result: Precise event timestamps for synchronization or logging.
| Timer Config | Max Period @ 60MHz Fcy |
|---|---|
| 16-bit, 1:1 prescaler | 1.09 ms |
| 16-bit, 1:256 prescaler | 280 ms |
| 32-bit mode | 71.6 seconds |
Check:
Check:
Solutions: