Manchester encoding and decoding system design for STM32

Publisher:caoda143Latest update time:2012-07-27 Source: 电子设计工程 Keywords:Manchester Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Introduction
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.

a.jpg



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.

b.jpg [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.

c.jpg


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.

d.jpg


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.

e.jpg



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.

f.jpg

[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.

g.jpg


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.

h.jpg



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.

Keywords:Manchester Reference address:Manchester encoding and decoding system design for STM32

Previous article:STM32F103VB SD card in-application programming design
Next article:Solar-LED Street Light Solution Based on STM32 MCU

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号