Share this

Embedded CAN Smart Node Based on PIC Microcontroller and Its Communication with PC

2026-04-06 03:32:59 · · #1
Abstract: This paper introduces the hardware and software design of an embedded CAN intelligent node based on the PIC16F874 microcontroller. A PCL-841 CAN interface card is used to enable communication between the embedded CAN intelligent node and a PC, achieving real-time acquisition, reliable transmission, and real-time display of signals such as voltage, current, and temperature. The PC also controls the pulse width of the PWM wave output from the embedded CAN intelligent node. Keywords: PIC microcontroller, embedded PIC16F874, CAN intelligent node, communication, PWM wave, pulse width Introduction: The CAN bus is a serial data communication protocol. Its communication interface integrates the physical layer and data link layer functions of the CAN protocol, enabling data framing. A key feature of the CAN protocol is the elimination of traditional station address encoding, replacing it with communication data block encoding. This method theoretically allows for an unlimited number of nodes in the network and enables different nodes to receive the same data simultaneously. This paper introduces an embedded CAN intelligent node and uses a PC and the embedded CAN intelligent node to form a CAN communication system, achieving real-time acquisition of signals such as voltage, current, and temperature. Reliable transmission and real-time display enable PC-side control of the pulse width of the embedded CAN smart node's PWM wave output. Design of an Embedded CAN Smart Node Based on a PIC Microcontroller The embedded CAN smart node uses a PIC16F874 microcontroller as the embedded microcontroller, an MCP2510 as the CAN controller, and a PCA82C250 as the CAN transceiver, providing on-site/remote control capabilities. Depending on user needs, the embedded CAN smart node can complete real-time acquisition of various signals by connecting corresponding sensors. Reliable transmission and real-time display are provided, and the PWM wave output can be used to control corresponding loads. The embedded CAN smart node can achieve circuit protection, on-site configuration, automatic adjustment, fault diagnosis and alarm, and status detection functions through external circuitry, enabling the drive and intelligent control of electrical appliances such as motors, valves, and pumps. Hardware Design: The Microchip PIC16F874 microcontroller adopts a RISC instruction set, Harvard bus architecture, low power consumption, and high speed. It integrates an ADC, a serial peripheral interface (SPI), and Flash program memory, and features PWM output and LCD driving functions. The PIC16F874 can seamlessly connect to the CAN controller MCP2510 via the SPI interface. The PIC16F874 has abundant I/O resources, with five I/O ports (A, B, C, D, and E), each with some special functions in addition to its basic purpose. The hardware schematic of an embedded CAN smart node based on the PIC16F874 mainly includes the following four modules: CAN Communication Module: The CAN communication module of the embedded CAN smart node consists of the CAN controller MCP2510 and the CAN transceiver PCA82C250. The MCP2510 can perform all functions of the physical layer and data link layer of the CAN bus, supports the high-speed SPI interface (maximum data transmission rate can reach 5Mb/s), and supports CAN2.0A/CAN2.0B protocols. The CAN transceiver PCA82C250 is the interface between the CAN controller and the physical bus, providing differential transmission capability to the physical bus and differential reception capability to the CAN controller. It can also increase the communication distance and improve the anti-interference capability of the embedded CAN smart node. The PIC16F874 connects to the CAN controller MCP2510 via SPI. Its Serial Data Input (SDI) pin is connected to the MCP2510's SO pin, its Serial Data Output (SDO) pin is connected to the MCP2510's SI pin, and its Serial Clock (SCK) pin is connected to the MCP2510's SCK pin. The MCP2510's reset signal is provided by RA5 and RA2 on the microcontroller's A port. The MCP2510's interrupt signal is also provided by RB0 and RB5 on the microcontroller's B port. The SPI interface is set to active mode by configuring the PIC16F874's SPI interface status register and control register. The timing of communication between the PIC16F874 and MCP2510 is crucial. When sending data, the write command is sent first, followed by the register address, and finally the data. When the MCP2510 receives data from the bus, it generates an interrupt. The microcontroller responds to the interrupt, first sending a read command, then sending the register address. The data is automatically written into the buffer of the microcontroller's SPI interface. The embedded CAN smart node of the display module uses the OCMJ4X8 display module, which can display Chinese characters, ASCII codes, etc. All its settings and initialization can be completed automatically upon power-on. The data lines DB0~DB7 of the OCMJ4X8 display module are connected to the microcontroller's D port. The request (REQ) pin and the response (BUSY) pin are connected to RB4 of the microcontroller's B port and RE2 of the microcontroller's E port, respectively. Adjustable resistors are connected to the RT1 and RT2 pins of the display module to adjust the LCD brightness. The display module interface protocol is a request/response (REQ/BUSY) handshake. A high level BUSY indicates that the display module is busy; a low level BUSY indicates that the display module is idle and waiting to receive commands. The microcontroller first sends commands or data to the display module, then sends a request signal to request processing. The display module sets BUSY to high level, processes the commands or data, and sets BUSY to low level after processing. The analog signal acquisition module (RA0, RA1, and RA3 on port A of the PIC16F874 microcontroller) is used for analog input. The main function of the analog signal acquisition module of the embedded CAN smart node is to convert the current signal to be acquired into a voltage signal through a current transformer, and to convert the temperature signal to be acquired into a voltage signal through a temperature sensor AD590. The digital input/output module of the embedded CAN smart node provides 4 digital inputs and 7 digital outputs through I/O expansion. Digital inputs are used for circuit protection, fault alarms, status detection, etc. As long as the controlled object has the corresponding detection element, it can be connected to the corresponding interface. Digital outputs are used to drive relays; the need for contactor control of motors, valves, pumps, and other electrical actuators can be determined based on the load size. This part of the circuit can be modified according to user requirements. Software Design The software for the embedded CAN smart node is written in assembly language. It primarily initializes the PIC16F874 microcontroller (I/O ports, timers, etc.), SPI interface (serial port status register SSPSTAT, serial port control register SSPCON, etc.), display module, 8255 I/O expansion chip, and MCP2510 CAN controller (bit timing configuration register, CAN information receive filtering and masking control register, receive and transmit buffer control register, etc.), sets the transmit and receive identifier (ID), reads the A/D conversion value, sets the pulse width of the embedded CAN smart node's PWM wave output, processes, displays, and transmits the acquired data, and receives and processes and displays the data transmitted from the bus. The system initialization program requires initializing the PIC16F874 microcontroller, display module, 8255 I/O expansion chip, and MCP2510 CAN controller. Initializing the MCP2510 is crucial, mainly including setting the data transmission baud rate and writing the identifier and mask into the CAN information receive filtering and masking control register. When initializing the PIC16F874, special attention should be paid to the initialization of timer TMR2. Set up transmission. The PIC16F874 microcontroller's C port RC0, RC1, RC6, and RC7 pins are connected to a DIP switch. The program assigns transmission to each embedded CAN smart node by reading the status of these four pins. Initialize the receive identifier value. This method simplifies program writing when there are many smart nodes in the network. Read the A/D conversion value. The PIC16F874's A and E ports can be used as analog input ports, with a total of 8 input channels. The A/D conversion result is stored in the microcontroller's ADRES register. The program first sets bits 3-0 of the microcontroller's A/D control register ADCON1, selecting the input/output type for each channel and setting the reference voltage to 5V. Then, it sets bits 5-3 of the microcontroller's A/D control register ADCON0 to select the channel, sets bit 0 to enable the ADC, and sets bit 2 to start the ADC. Finally, it reads the A/D conversion value from the microcontroller's A/D conversion result register ADRES. The program sets the pulse width of the PWM wave output using the CCP1 pin of the PIC16F874. First, it sets bits 3-0 of the microcontroller's CCP1 module control register CCP1CON, defining the operating mode as PWM. Then, it uses data received from the PC to set the pulse width of the embedded CAN smart node's PWM wave output to set bits 5-4 of the microcontroller's CCP1 control register CCP1CON and the CCPR1L register, thus enabling the PC to control the pulse width of the embedded CAN smart node's PWM wave output. The data transmission program assigns an identifier code to each signal (voltage, current, temperature, pulse width of the embedded CAN smart node's PWM wave output) that needs to be transmitted to the PC. When transmitting data, a write command is first sent to the MCP2510, followed by the definition of the identifier code, frame format, and data length. The data to be transmitted is then written sequentially into the corresponding registers of the MCP2510. The data reception program reads the value of the interrupt flag register of the CAN controller MCP2510 to determine if there is data in the receive buffer. If there is data, a read command is sent to the MCP2510, sequentially defining the identifier code, frame format, and data length. The received data is read from the corresponding registers of the MCP2510. The data processing and display program processes the A/D conversion values ​​to obtain the actual signal values, which are then sent to the display module for display, mainly including the display of numerical values, Chinese characters, and English characters. Simultaneously, it displays the pulse width of the embedded CAN smart node's PWM wave output and the data received from the PC. Implementation of PC-side Functionality The hardware portion of the PC uses Advantech's PCL-841 dual-port CAN interface card. This card has two CAN communication ports, with a maximum data transmission rate of 1Mbps. The card employs a memory mapping mechanism, mapping the memory on the CAN interface card to main memory. Users can set the base address of the mapped memory as needed. The software portion of the PC is written in C language, primarily handling real-time reading, processing, and display of CAN information, sending data to the embedded CAN smart node, and setting the pulse width of the embedded CAN smart node's PWM wave output. Some issues to consider during design and debugging : In the design of the embedded CAN smart node, attention should be paid to handling reset and clock signals, including the timing of resets between different devices. When acquiring temperature signals, special attention should be paid to zeroing the AD590 temperature sensor. The AD590 is a constant current source; its characteristic is that the current increases/decreases by 1mA for every 1°C change in absolute temperature, and is 0mA at 0°C. To compensate for the AD590's voltage at 0℃, a negative power supply needs to be added so that its output is 0V at 0℃. Then, a suitable resistor is selected to convert the current into voltage, thus transforming the temperature signal acquisition into a 0-5V voltage signal acquisition. During debugging, the operating voltage of each chip should be checked first to ensure it is normal, the crystal oscillator is oscillating, and the reset signal is correct. The heating status of each chip should be checked frequently, and if the temperature is too high, the power should be immediately turned off for inspection. If necessary, an oscilloscope can be used to observe and analyze the signal waveform. On the PC side, since the PCL-841 dual-port CAN interface card occupies the PC's serial port resources, the serial port should be disabled in the BIOS settings. Special attention should also be paid to whether the memory resources occupied by the CAN interface card are occupied by other hardware. If they are already occupied, the starting address of the CAN interface card's memory mapping should be modified, and the jumpers on the CAN interface card should be changed; otherwise, the CAN interface card will not work properly. On the software side, when programming the embedded CAN smart node, special attention must be paid to the initialization of the CAN controller MCP2510. It is crucial to ensure that all smart nodes in a system have the same data transmission baud rate; otherwise, the embedded CAN smart node will be unable to communicate with the PC. It is also essential to correctly write the identifier and mask into the MCP2510's CAN message receive filter and mask control registers; otherwise, the embedded CAN smart node will be unable to correctly send and receive CAN information. During debugging, the progress of program execution should be assessed by checking the values ​​of various registers. On the PC side, when programming, the PCL-841 dual-port CAN interface card driver library CAN841S.LIB needs to be embedded into the project. The driver library encapsulates functions for directly controlling the CAN interface card. Controlling the CAN interface card must be performed according to the prescribed procedures; otherwise, the CAN interface card will not function properly or will be unable to correctly send and receive CAN information. During debugging, a combination of breakpoints and single-step execution should be used, paying attention to analyzing the return values ​​of functions to determine the cause of problems. Conclusion This project has preliminarily completed the design of a data acquisition and intelligent control system based on the CAN bus. After repeated experiments, the system has demonstrated accurate data acquisition and reliable transmission, passing professional tests conducted by relevant departments. Furthermore, the designed embedded CAN intelligent node can quickly and accurately receive data sent from the PC.
Read next

CATDOLL 128CM Katya

Height: 128cm Weight: 19kg Shoulder Width: 30cm Bust/Waist/Hip: 57/52/63cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22