Manchester coding is widely used in Ethernet, vehicle bus, and industrial bus because of its characteristics of no DC component during transmission and convenient clock extraction. The commonly used Manchester coding chips in engineering are HD-6408 and HD-6409, but this chip has some shortcomings. First, the chip has strict restrictions on the transmission rate and the number of effective bits in each frame of data. Secondly, the use of this chip requires additional hardware circuits, which increases the system cost. Using FPGA for Manchester coding is costly and has a long development cycle. This paper proposes a coding system solution based on STM32F103RET6, which utilizes the powerful timer function of STM32F103RET6 and adopts a flexible coding method. The transmission rate and data frame format can be completely defined according to needs. The built-in DMA function of STM32F103RET6 makes data coding no longer require frequent timer interrupts, improves the coding rate, and saves CPU resources. The implementation method of this design is simple, stable, flexible, and has a wide range of applications.
1 Manchester code
Manchester code is an automatic synchronization coding method, that is, the clock synchronization signal is hidden in the data waveform. In Manchester code, there is a jump in the middle of each bit, and the jump in the middle of the bit serves as both a clock signal and a data signal. Each code element is represented by two level signals with different phases. Compared with non-return-to-zero binary codes represented by high and low levels, it is easier to extract synchronization clock information in the case of continuous "0" or continuous "1". In addition, Manchester code has no DC component during transmission, which can reduce the power consumption of the system and has strong anti-interference ability. Figure 1 shows the most commonly used Manchester coding method. When the transmitted signal is "1", Manchester code jumps from high level to low level; if the transmitted information is "0", Manchester jumps from low level to high level. Maintaining a low level without jumps within a data cycle indicates idle.
2 Introduction to the timer and DMA of STM32F103RET6
The controller uses ST's STM32 microprocessor. The STM32 series microprocessor is based on the ARM Cortex-M3 core and uses an efficient Harvard structure three-stage pipeline to achieve 1.25DMIPS/MHz. Here we use the enhanced STM32F103RET6. It has the following features: 72 MHz system clock frequency, 512 KB flash program memory, 64 KBSRAM, 8 timers, 3 12-bit analog-to-digital converters, 1 digital-to-analog converter, 1 CAN interface, 7-channel DMA controller, and SPI, USART, I2C, I2S, USB interfaces, etc. The controller has rich peripherals and strong anti-interference ability, and is very suitable for industrial field control.
STM32F103RET6 has 8 timers, each of which consists of a 16-bit auto-load counter with programmable pre-scaling. The counting frequency is up to 72 MHz. It is suitable for a variety of occasions including the pulse length of the input signal (input capture) or the generation of output waveforms (output comparison or PWM).
STM32F103RET6 supports DMA operation. DMA is a high-speed data transmission channel between the external and the memory or between the memory and the memory. Through DMA, data can be moved quickly without the participation of the CPU, which saves CPU resources to do other things. This design uses the counter to trigger DMA to exchange data between the memory and the timer, which improves the efficiency and stability of the encoding compared to the interrupt query method.
The maximum counting frequency of the timer is 72 MHz, and the DMA transmission rate is 6 Mb/s, so the Manchester encoding rate can easily reach 1 Mb/s, meeting the needs of high-speed encoding.
3 System Implementation Scheme
The block diagram of the Manchester voltage and current encoding system based on STM32F103RET6 is shown in Figure 2. The system design mainly uses the timer and DMA function of the STM32F103RET6 chip to implement Manchester voltage encoding and decoding. The current encoding and decoding requires the help of peripheral voltage and current conversion circuits.
[page]
3.1 Voltage Coding
Set the timer to output comparison flip function, apply for a buffer area, convert the data to be encoded into flip matching value through the encoding algorithm and put it into this buffer area, as shown in Figure 3, ABC DEF... count value, the encoding algorithm is written according to the encoding protocol in the specific application. After starting the timer, the counter starts counting. When the count value matches the value of the timer comparison register, the level of the output pin is flipped and triggers DMA to update the comparison register from the buffer area; each time it is updated, the memory address pointed to by DMA increases by 1, pointing to the data to be updated to the comparison register next time, in this way, the timer outputs the corresponding encoding waveform according to the data in the buffer area. The encoding rate can be adjusted by modifying the timer prescaler and the RCC clock controller divider.
3.2 Voltage decoding
Set the timer to input capture function. When the rising or falling edge of the Manchester code arrives, the timer will capture the current count value and transfer it to the buffer via the DMA channel; the main program will call the decoding algorithm to process and decode the data in the buffer. Decoding is the reverse process of encoding, and its decoding algorithm should also be written according to the encoding protocol in the specific application.
3.3 Current encoding
Voltage encoding is realized through the voltage/current conversion circuit shown in Figure 4, which converts the Manchester voltage code output by the timer into the Manchester current code.
3.4 Current decoding
The Manchester current code signal to be measured is converted into a voltage code through current/voltage, shaped to make the edge steeper, and then handed over to the MCU for decoding. The current/voltage conversion circuit is shown in Figure 5.
4 Software Design
The software flow is shown in Figure 6. System initialization includes clock initialization, timer initialization, DMA initialization, etc. If the data to be encoded continuously at one time is relatively large, the DMA buffer should be set to double buffer, and two buffers should be opened for each DMA channel used. When DMA uses one of the buffers, the MCU calls the encoding or decoding algorithm to read and write the other buffer; when the DMA data is transferred, a DMA transfer end interrupt occurs, and the interrupt service program switches to another buffer, and the encoding algorithm or decoding algorithm flag is set. When the main program queries the flag position, the MCU calls the encoding or decoding algorithm to process the buffer previously pointed to by DMA (fill data or fetch data). Of course, if the data to be encoded or decoded at one time is not much, we only need one buffer.
[page]
Because the CPU processes data faster than the encoding rate, the CPU can spare time to do other things. The length of time depends on the size of the buffer and the encoding rate. When the encoding or decoding flag is queried in the main program, the encoding or decoding algorithm is executed to process the data, which improves the CPU's work efficiency. In applications where real-time requirements are not high, a dedicated CPU is no longer needed to process encoding or decoding.5 Scheme Verification
This scheme has been verified in the automotive acceleration sensor simulation system. Here, the Manchester encoding protocol of a certain acceleration sensor is taken as an example. Its data frame format is a frame of 19 bits, including: 2 start bits, 2 category bits, 10 data bits, and 5 CRC validation bits.
5.1 Coding Scheme Verification
The Manchester voltage encoding waveform is measured at point T1 of the circuit shown in Figure 4, and the current encoding waveform is indirectly measured by measuring the voltage drop between T2 and T3.
A frame of data 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 is continuously encoded, the delay between frames is 6μs, the encoding rate is 400kb/s, and the encoding waveform is shown in Figure 7.
5.2 Decoding scheme verification
By capturing and decoding the Manchester current code output by a real sensor, its ID information is obtained. The decoded data is shown in Figure 8. The ID is correct and the decoding is successful.
Conclusion
This design can easily realize Manchester voltage and current encoding and decoding. The implementation method is flexible and reliable, and is suitable for various types of Manchester encoding and decoding application fields. At present, this design has been successfully applied in the automotive acceleration sensor simulation system.
Previous article:STM32F103VB SD card in-application programming design
Next article:Solar-LED Street Light Solution Based on STM32 MCU
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- The application channels for multiple development boards have been reopened. Come and apply if you are interested!
- Learn about RTOS in ten minutes!
- Power communication - carrier communication
- PowerPC
- High salary recruitment of 5G filter design engineers located in Suzhou Industrial Park
- Bluetooth Low Energy Issues
- TI's TPS92610-Q1 is a single-channel LED driver
- Good video material sharing on UWB in detail
- Please tell me how to use low power resistors when connecting LEDs in series and parallel
- Award-winning live broadcast | Interpretation of TI's latest low-cost C2000 features, quickly get started with precision power supply and motor control!