We know that the characteristic of Gray code counting is that adjacent code words have only one bit different, so when designing Gray code counting, we just need to find this bit and invert it. The idea of finding this bit: First convert the Gray code into binary code. The Gray code position corresponding to the first ''0'' bit from LSB to MSB in this binary code is the required position. If all ''1'' bits are ''1'', the MSB position is the required position.
Below is a VHDL program taking cyclic Gray code as an example.
Library Ieee;
Use Ieee.Std_logic_1164.All;
Entity Demo Is Port(
Clock :In Std_logic;
Q: Out Std_logic_vector(3 Downto 0)); --The length of the vector depends on the user, this is just an example.
End Demo;
Architecture MyFavor Of Demo Is
Function NxG(Argv: Std_logic_vector) Return Std_logic_vector Is --This function completes the Gray code input and returns the Gray code of the next number.
Alias GV :Std_logic_vector(1 To Argv''Length) Is Argv;
Variable BV,GC :Std_logic_vector(1 To Argv''Length);
Begin
BV(1) := GV(1);
For I In 2 To Argv''Length Loop
BV(I) := GV(I) Xor BV(I - 1);
End Loop;
GC := GV;
For I In Argv''Length Downto 1 Loop
If BV(I) = ''0'' Or I = 1 Then
GC(I) := Not GC(I);
Exit;
End If;
End Loop;
Return GC;
End NxG;
Signal GC :Std_logic_vector(3 Downto 0);
Begin
Process(Clock) Begin
If Rising_edge(Clock) Then
GC <= NxG(GC);
End If;
End Process;
Q <= GC;
End MyFavor;
Previous article:Technology and application of single chip microcomputer controlling GSM mobile phone
Next article:Gray code to binary conversion method
- Popular Resources
- Popular amplifiers
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
- 【Me and Yatli】+ Upcoming review
- NE555 timer problem
- Road lighting system solutions based on the Internet of Things
- [Jihai M3 core APM32E103VET6S MINI development board] 05. ADC high-speed sampling and DAC analog peripheral functions
- From 30 days to three months, how does Shenzhou XII solve the energy problem? ? ?
- Find an electronics engineer near Foshan
- Agitek Engineer - How to determine if an oscilloscope has a false wave
- My question is, does IoT need a server? Is Alibaba Cloud better or Tencent Cloud? Can anyone recommend one?
- [RVB2601 Creative Application Development] Network Weather Clock
- [HPM-DIY] Pseudo 3D game doom ported to HPM6750