AbstractThis article introduces the main functions of the embedded Beidou time server, the implementation principles of B code, and focuses on the processes of B code encoding and decoding within the device.KeywordsB code、encoding、decoding、code element、TOD+1PPS、BCD code、timer、interrupt、I/OFunction Description of Beidou Time ServerThe Beidou satellite receiving terminal receives RNSS radio information transmitted by Beidou navigation satellites and calculates the user’s current position, speed, and time information through internal PVT resolution. The time information from Beidou has excellent characteristics, including complete information such as year, month, day, hour, minute, and second, with an output second pulse accuracy of less than 20ns, making it a very good time reference source. The standard time synchronization interface output by the Beidou terminal device is a serial port plus a second pulse, namely TOD+1PPS, where TOD (Time Of Data) contains year, month, day, hour, minute, and second information, and 1PPS is a pulse at the whole second, which has precise synchronization effects, generally implemented in TTL level pulse form or 485 differential pulse form.IRIG-B code (abbreviated as B code) is an international standard time code used in target measurement, industrial control, computing, communication, meteorology, and other timing and testing equipment. Therefore, adding B code functionality to the Beidou receiving terminal can introduce Beidou time into the aforementioned industries, achieving synchronization using the high-precision characteristics of Beidou time.Principle of B CodeThe IRIG-B code frame period is 1 second, containing 100 code elements, encoded according to the time information of seconds, minutes, hours, days, and years starting from the second reference point. Each code element lasts 10ms, with pulse width encoding: 2ms represents binary 0, separator flag, or unencoded bit; 5ms represents binary 1; and 8ms represents the whole 100ms reference flag. The second reference edge is indicated by the rising edge of the second pulse of two consecutive 8ms wide reference flag pulses. Starting from the initial flag, seconds (units), separator flag, seconds (tens), reference flag, minutes (units), separator flag, minutes (tens), reference flag, hours (units), separator flag, hours (tens), reference flag, days (units) starting from the first day of the year, separator flag, days (tens), reference flag, days (hundreds), 7 control codes, and the number of seconds since midnight (as a pure binary integer), followed by an end flag. According to TEEE Std 1344-1995, the year is added in bits P50-P58 of the IRIG-B code, with year, month, day, hour, minute, and second in BCD code format. The following figure shows a standard example of B code encoded time:
B Code Encoding Implementation MethodThe embedded Beidou time server uses the STM32 Cortex-M4 chip as the main control MCU, and B code encoding is implemented through software programming within the MCU. Once the encoding logic is determined, a GPIO pin of the Cortex-M4 chip is toggled to output TTL level B code encoding logic. If it is necessary to convert TTL level to differential level signals, an external hardware differential driver chip can be added. During the software implementation process, the main program retrieves the precise year, month, day, hour, minute, and second time information output from the Beidou terminal device’s PVT resolution, synchronizing the time information at the 1PPS second edge, and aligning the starting edge of the B code output with 1PPS, then converting the complete time information into B code format and storing it in the data structure for B code encoding, waiting for the arrival of the 1PPS second edge.
typedef struct{u32 allSec; // Total seconds in a dayu8 Year[2]; // Year 21u8 totalDay[3]; // Day 0-365u8 Hour[2]; // Hour 0-24u8 Minute[2]; // Minute 0-59u8 Second[2]; // Second 0-59}ENC_DATA;
Upon the arrival of the 1PPS second edge, the previously retrieved time information is incremented by 1, and a 1-millisecond timer is started. In the 1-millisecond interrupt program, the global variable bcode_1ms starts counting from zero, incrementing once every millisecond. Based on the accumulated count of bcode_1ms compared to the corresponding B code element width, the I/O pin of the MCU is toggled to output the level state, completing one round of B code encoding. During the previous round of B code encoding, the next round’s encoding time information is simultaneously retrieved in the main program, repeating the above process to ensure continuity of time.
B Code Decoding Implementation MethodThe Beidou time server can also obtain time information through the input of B code, converting B code information into TOD+1PPS format time information for use by other standard Beidou devices.The B code information to be decoded is input through an I/O pin of the Cortex-M4 chip within the Beidou time server. In the embedded software programming of the Cortex-M4 chip, the input state of this I/O pin is configured to interrupt reception status, and the interrupt input program is triggered using both rising and falling edges (EXTI_Trigger_Rising_Falling). In the interrupt input program, the rising edge starts a 1-millisecond timer, beginning the accumulation count of the global variable high_1ms (high_1ms++), while the falling edge terminates the accumulation count of high_1ms and starts the accumulation count of the global variable low_1ms (low_1ms++). The rising edge also terminates the accumulation count of low_1ms. Based on the accumulated count values of these two milliseconds, the current code element state is determined: whether it is 0, 1, or a separator flag, etc. For the 1-second B code time information, since there are 100 code elements, a data buffer of 200 bytes (DutyBuf[200]) is used to cyclically store the high-level duration count of the code elements. In the embedded main program, the second start flag is first retrieved, and then each value in DutyBuf[200] is read in a loop, translating and packaging the stored high-level millisecond counts to form real-time complete year, month, day, hour, minute, and second time information. This time information can be output as TOD via the serial port, and based on the starting edge of the B code, a standard 1PPS second pulse can be output for synchronization.It is important to note that during the B code decoding process, appropriate debouncing measures should be taken for the MCU’s I/O pin input to prevent errors. Debouncing methods can include using interrupt input combined with polling to read the port status.
ConclusionThe B code output function of the Beidou time server supplements the time information output forms of Beidou devices, providing possibilities for various industries to utilize the high-precision time reference of Beidou, fully leveraging China’s Beidou navigation satellite resources. The B code decoding function allows the Beidou time server to obtain sufficiently accurate time information from other external devices in cases where Beidou navigation signals are obstructed, ensuring the continuity and reliability of time information within the Beidou time server.References2) IRIG-B Code Format and Principles3) STM32F4XX Reference Manual1) “2022 China Satellite Application Industry Panorama”4) “General Data Interface Requirements for Beidou III Civilian Terminals”5) “CASIC Multi-Mode Satellite Navigation Receiver Protocol Specification”Author: Dong Xiyan, Aerospace Hengxing Space Application Technology Co., Ltd.EET Electronic Engineering Magazine Original
END▼Previous Hot Articles Review▼Intel 4 Process Analysis: Can It Be Considered 4nm? Huawei Hubble Invests in Another Automotive Chip Company Microcontroller Pointer: This Learning Method Is Too Simple! Comprehensive Notes on Switching Power Supply Design! RS485 Communication Interface Design SchemeUpload Material Activity

Upload materials and pass the review to participate in the upload material activity.
Activity Rules:
1. Enter the download center and click “Upload My Document” to upload!
Award Settings:
1) Uploading over 2000 materials: Reward of 666 yuan JD card + 1000 e-coins
2) Uploading over 1000 materials: Reward of 300 yuan JD card + 800 e-coins
3) Uploading over 500 materials: Reward of 200 yuan JD card + 400 e-coins
4) Uploading over 250 materials: Reward of 100 yuan JD card + 200 e-coins
5) Uploading over 100 materials: Reward of 30 yuan JD card + 100 e-coins

Scan to Upload

Share
Collect
Like
View