Share this

DC motor drive circuit and power supply module design

2026-04-06 04:50:05 · · #1

microcontroller module

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with an on-chip 8KB ISP Flash read-only program memory that can be erased and rewritten 1000 times. The device is manufactured using high-density, non-volatile memory technology and is compatible with the standard MCS-51 instruction set and 80C51 pinout. The chip integrates a general-purpose 8-bit central processing unit and an ISP Flash memory unit, providing a cost-effective solution for many embedded control applications.

The AT89S52 has 40 pins, 8KB of on-chip Flash program memory, 256B of RAM, 32 external bidirectional input/output ports, 5 interrupt priorities, 2 levels of interrupt nesting, 2 16-bit programmable timer/counters, 2 full-duplex serial communication ports, a watchdog timer (WDT) circuit, and an on-chip clock oscillator.

During development, a development board is used to facilitate program debugging and overall system testing. After the system debugging is completed, the microcontroller is removed from the development board and installed in the microcontroller socket of the robot system board. Since the tasks that the robot needs to complete in the design are relatively simple, only the crystal oscillator and reset circuit are retained in the microcontroller system of the robot system board, and redundant circuits such as the JTAG programming port are eliminated.

3.2 Sensor Module

The working principle of a photoelectric sensor is that the sensor's infrared emitting tube emits infrared light, and the receiving tube counts based on the intensity of the reflected infrared light. Therefore, the surface of the component or object being detected must have alternating black and white areas to absorb and reflect infrared light, so that the receiving tube can be in the effective cutoff and saturation regions to achieve the counting purpose. The sensor's detection and adjustment circuit is shown in Figure 2. R3 in the figure is used to adjust the threshold voltage of the comparator. Observation with an oscilloscope shows that the output waveform is quite regular and can be directly used for microcontroller query. Moreover, it has been verified that the battery voltage drop supplying power to this circuit is small. The infrared photoelectric sensor is connected to the P0.5, P0.6, and P0.7 ports of the AT89S52 microcontroller through the P8, P9, and P10 interfaces on the motherboard. Where P0.5 = 0 indicates an obstacle in front; P0.6 = 0 indicates an obstacle to the left; and P0.7 = 0 indicates an obstacle to the right.

DC motor drive circuit and power supply module

The DC motors are connected to the motherboard's driver module via the P5 interface. This paper uses the L298 as the motor driver chip. Pins 5, 7, 10, and 12 of the L298 are connected to the microcontroller. By programming the microcontroller, functions such as forward and reverse rotation of the two DC motors can be achieved. Since the microcontroller's voltage is around 4.8V, a VFM boost converter chip is used to provide approximately 5V to the microcontroller and peripheral circuits.

Software development environment and search algorithm

This paper uses Keil U Version 2 as the system development environment and employs a mix of C and assembly languages ​​in the program design. Regarding the software algorithm, considering that the time and space efficiency of the depth-first search algorithm is directly proportional to the complexity of the maze terrain—that is, the more complex the maze, the longer it takes to find the exit—this paper adopts a maze pathfinding strategy called the left-hand (or right-hand) rule. This involves continuously searching along the left (or right) wall in the maze to find the exit.

Compared to depth-first search, the left-hand (or right-hand) algorithm's space usage is independent of the maze's complexity, and the robot's path selection depends only on the current node, eliminating the need for backtracking. Furthermore, it requires less precise hardware manufacturing precision, as it doesn't require accurate control of the robot's movement distance and direction, simplifying drive design. To facilitate algorithm implementation, this paper sets the following constraints:

1. In the algorithm, no matter how complex the maze terrain is, it consists of seven basic terrain types: straight lines, dead ends, T-shaped, cross-shaped, corner-shaped, and the endpoint.

2. Intersections are classified into two-way intersections and three-way intersections (generally, four-way intersections are rare) based on the number of forks. The forks leading to the intersections are named from right to left as the first fork, second fork, and third fork (only present in cross-shaped intersections). Two-way intersections have three different forms: first, a fork appears on the right side of the path (the right fork is called the first fork, and the path ahead is called the second fork); second, a fork appears on the left side of the path (the path ahead is called the first fork, and the path to the left is called the second fork); third, a T-junction (the right fork is called the first fork, and the path to the left is called the second fork). For these three cases, the corresponding algorithm program consists of a main program, a straight-line subroutine, a left rotor program, a right rotor program, and a correction subroutine. The main program serves as a guide and decision-maker, determining when the robot should do what. Other robot functions are implemented by calling specific subroutines.

The maze search algorithm used in this paper is shown in Figure 3. After the motor and sensor power is turned on, the microcontroller, under the control of the program, determines the forward and reverse rotation of the motor based on the values ​​detected by the sensors. When P0.7=1, it means there is no obstacle on the left, and according to the "right-hand" traversal algorithm, the robot will call the right rotor program; when P0.7=0 and P0.5=0, the robot will call the left rotor program; otherwise, the robot moves forward in a straight line. This process of detection and adjustment is repeated until the robot escapes the maze.

Architecturally, the CLB is very similar to the programmable logic structure of an FPGA. Each BLE that makes up a CLB consists of a 4-input LUT (Lookup-Table) and a D flip-flop. The CLB's input interface provides 16-input select latches, each of which can select one of up to 40 different signals as inputs. These signals can be signals input through external pins, output signals of internal peripherals, and signals from software-operated registers. Programmable edge detectors are embedded at the CLB inputs. These edge detectors are triggered by the rising edge by default, but can be programmed to be triggered by the falling edge or completely bypassed.

Additionally, the CLB supports eight outputs that can be routed to external pins, internal registers, or inputs from internal peripherals. The CLB also includes a 3-bit hardware counter to aid in building state machines. The CLB's usefulness is further enhanced when the MCU needs to perform simple multitasking in parallel or requires minimal hardware-level real-time processing. Developers can use the CLB to implement state machines or "high-speed" peripherals, such as software-driven signal multiplexers, counters, quadrature decoders, stepper motor controllers, or high-speed PWM (pulse width modulators).

A brand new development experience

In fact, integrating programmable logic functions into MCUs is not a new challenge for Microchip. More than 10 years ago, Microchip introduced a programmable logic peripheral called a Configurable Logic Unit (CLC) into its MCUs, and the value of this design concept has been proven by the market. With the increasing demand for more complex programmable logic in practical applications, the PIC16F13145 series evolved into the CLB, a larger and more complex programmable logic block, completing an important iterative upgrade and enabling this series of MCUs to be used in application areas that were previously dominated by independent programmable logic devices.

The unique positioning of the PIC16F13145 series MCUs can bring many benefits to developers.

First, the CLB integrated into the MCU implements logic functions in hardware, which significantly outperforms the "general-purpose MCU + software" approach. This helps optimize the speed and response time of the embedded control system, improving overall system performance. Furthermore, since no additional external logic devices are needed during system design, it also reduces BOM costs, achieving two goals at once.

Secondly, as a peripheral independent of the CPU core, the CLB in the PIC16F13145 can run while the CPU is in sleep mode to respond to and process tasks from both external and internal sources, minimizing the MCU's power consumption. The CLB can also be used in conjunction with other peripherals (such as timers, ADCs, PWM modules, etc.) to further optimize system power consumption performance.

Furthermore, CLB also helps the PIC16F13145 series MCUs achieve greater scalability. In practical applications, design adjustments are inevitable as requirements change. The programmable logic capabilities of the PIC16F13145 series MCUs allow developers to quickly iterate designs through flexible hardware programming without having to completely modify the entire design from scratch, simplifying the entire design process.

Therefore, thanks to the higher performance, lower power consumption, and stronger scalability brought by the CLB module, coupled with other rich on-chip resources (including a fast 10-bit ADC with built-in computing functions, an 8-bit DAC, a fast comparator, 8-bit and 16-bit timers, and communication modules such as I2C and SPl), the PIC16F13145 series MCUs undoubtedly provide embedded developers with a powerful and flexible development tool.

A complete development ecosystem

Of course, an embedded hardware platform, along with supporting software development tools and related technical resources, is needed to provide a complete development experience. Specifically, for the innovative hardware architecture of the PIC16F13145 series MCU, a robust development ecosystem is essential to minimize the barriers for developers to get started and "try it out."

The good news is that Microchip has already addressed this. Development of the PIC16F13145 series MCUs can be supported by the MPLAB Code Configurator (MCC), a free software plugin for Microchip's MPLAB X IDE. MCC provides developers with a user-friendly GUI-based development interface for configuring devices and on-chip peripherals (including CLBs). Custom logic configurations required for CLBs can be schematically created using MCC, significantly reducing development time. Furthermore, users can use the Hardware Description Language (Verilog) as their development language, increasing development flexibility. Schematics for custom logic configurations can also be created online (logic.microchip.com).

Meanwhile, the PIC16F13145 Curiosity Nano Evaluation Kit provides full support for designing using the PIC16F13145 series MCUs. It requires no external tools, programming, or debugging, is simple to use, and helps developers achieve a seamless embedded development experience, shortening time to market.

Today, the highly competitive MCU market urgently needs differentiated and innovative products. Microchip's PIC16F13145 series MCUs creatively combine programmable logic peripheral functions with an 8-bit MCU architecture. While inheriting the inherent advantages of MCUs, they also deliver better performance, low power consumption, and scalability, providing embedded developers with a whole new space for imagination and development experience in real-time control, digital sensor nodes, and niche markets such as industry and automotive.


Read next

CATDOLL 128CM Himari Silicone Doll

Height: 128 Silicone Weight: 21kg Shoulder Width: 30cm Bust/Waist/Hip: 57/52/63cm Oral Depth: N/A Vaginal Depth: 3-15cm...

Articles 2026-02-22