Index pulse (Z) loss: Check if the Z-phase of the encoder is a narrow pulse. The minimum width of the index pulse in the QEI module needs to be greater than two system clock cycles.
3.3 Input Capture and Output Comparison
The input capture module can measure frequency, period, and pulse width, but it should be noted that its timer sources are only Timer2 and Timer3. If multiple capture channels are used simultaneously, ensure that their shared timebases do not conflict. The output comparison module can be used to generate variable width pulses or simple PWM (resolution of 16 bits). The common problem on site is that the matching interrupt does not trigger - the corresponding interrupt enable bits (ICxIE, OCxIE) and global interrupts (INTCON1bits. GIE) should be checked.
Chapter 4 Troubleshooting of Digital Communication Interface Malfunctions
4.1 UART serial port
The UART of dsPIC30F supports full duplex, 8/9-bit data, checksum, hardware flow control (CTS/RTS), and IrDA. The most common on-site problem encountered is "inability to communicate" or "garbled code".
Diagnostic steps:
Pin configuration: UART function pins (UTX, URX) must have the corresponding TRIS bit set as input/output, and typically require disabling the analog function (ADPCFG).
Baud rate calculation: UxBRG value=(Fcy/(16 × Baud)) -1. If 40MIPS (Fcy=40MHz) is used, 9600 baud should be obtained, BRG≈259。 Calculation errors will result in timing errors in both directions.
Parity matching: The parity settings of the master and slave stations must be consistent. 8-bit data+odd parity is the most common combination.
Hardware flow control impact: If CTS/RTS is enabled but the corresponding pin is not connected, UART will hang. Flow control can be disabled during debugging.
Buffer overflow: An OERR bit of 1 indicates a receive overflow, which requires software to reset and reinitialize the receiver.
4.2 SPI and I ² C bus
The SPI module supports all four modes and has frame synchronization (FSYNC) for audio codecs. On site SPI issues are often caused by mode mismatch (clock polarity/phase) or incorrect control of device chip selection. Logic analyzer is a powerful tool for troubleshooting: check the timing diagram of SCK, SDO, SDI in the setting mode.
The I ² C module supports multi master, 7-bit/10 bit addressing, and hardware implementation of arbitration and clock synchronization. Common faults:
Bus hang up (SDA consistently low): A device has not released the bus. You can try to force the generation of 9 clock pulses for recovery.
Arbitration loss: In a multi master environment, if two masters simultaneously send different data, the loss arbitrator will interrupt the transmission. Check the bus competition conditions.
100k/400k speed switching: I2CBRG must be configured correctly, and the rising edge time must meet the specifications (adjusted by external pull-up resistor resistance).
4.3 CAN bus module
Integrated CAN 2.0B controller, supporting standard frames and extended frames, up to 1Mbps. Common issues include:
Bit timing configuration error: SJW, TQ, and sampling point positions in BRCON1/2 do not match, resulting in an increase in error frames. Collect erroneous waveforms using a CAN analyzer.
Improper setting of receiving filter masking: If 6 filters (2 for high priority buffer and 4 for low priority) are not initialized correctly, the expected message will be discarded.
Priority of sending buffer: Three sending buffers can be set with priority, but if all buffers are full and have the same priority, low priority messages may never be sent out. Use the send abort function to clear specific buffers.

Chapter 5 Development Tools and On site Firmware Maintenance
5.1 MPLAB IDE and Debugging Toolchain
Microchip offers free MPLAB IDE (such as version 6.00 or later), integrated editor, project manager, MPLAB SIM software simulator, MPLAB ICE 4000 online simulator, MPLAB ICD 2 debugger, and PRO MATE II programmer.
MPLAB SIM: Suitable for algorithm validation and can finely control time. But it cannot truly reflect the I/O timing and electrical characteristics.
MPLAB ICD 2: A low-cost online debugger that occupies two I/O pins (PGC/PGD) and a portion of program memory and RAM. Note: ICD2 may not be able to maintain connectivity in some low-power modes (SLEEP).
MPLAB ICE 4000: A fully functional simulator that supports complex triggering, tracing, and code coverage analysis. It is essential to solve extremely difficult timing problems.
5.2 Programming and Code Protection
DsPIC30F supports online serial programming (ICSP) through 3 pins (PGC, PGD, MCLR). During the mass production stage, it can be programmed using PRO MATE II or a third-party general-purpose programmer. Code protection configuration bits (GCP, GSS, etc.) can prevent FLASH and EEPROM from being read externally. However, it should be noted that once code protection is enabled, the chip will not be able to read existing firmware through the programmer (but it can be completely erased and re burned). When replacing faulty components on site, it should be ensured that the newly burned firmware version is consistent with the original.