The design uses the high-performance single-chip microcomputer C8051F020 as the control chip to monitor the status of 40 buttons, 3 coding switches and 4 potentiometers on the oscilloscope panel. The working principles of the keyboard, coding switch and potentiometer, as well as the hardware circuit and software programming implementation of the connection with the single-chip microcomputer are introduced respectively. The key part adopts the keyboard program design method of one key with multiple meanings, and a key code matching subroutine flow chart is given. The
monitoring program is responsible for the allocation and scheduling of all hardware and software resources in the system. It provides a user interface and enables users to obtain a friendly working environment. It is an important part of the system design.
1 Overview of C8051F020 single-chip microcomputer
With the rapid development of electronic technology, more and more people are joining the army of electronic development. In the process of learning electronic technology and R&D projects, it is inevitable to use some instruments, such as multimeters, oscilloscopes, etc. However, for some non-professional enthusiasts, owning a digital oscilloscope is a "luxury". This design of C8051F020 single-chip microcomputer, because of its low cost, simple production, high measurement accuracy and other advantages, just meet the needs of this part of people.
The C8051F020 microcontroller is a highly integrated system-on-chip. It integrates two multi-channel ADC subsystems (each subsystem includes a programmable gain amplifier and an analog multiplexer), two voltage output DACs, two voltage comparators, voltage references, SMBus/I2C bus interfaces, UART, SPI bus interfaces, five general-purpose 16-bit timers, a programmable counter/timer array (PCA) with five capture/compare modules, an internal oscillator, eight 8-bit general-purpose digital I/0 ports and 64 KB FLASH program memory, as well as an 8051-compatible high-speed microcontroller core. The
C8051F020 microcontroller is a microcontroller in which all analog and digital peripherals can be enabled/disabled and configured by user firmware. The Flash memory also has the ability to be reprogrammed in the system, which can be used for non-volatile data storage and allows the 8051 firmware to be updated on site. The on-chip JTAG debugging circuit allows non-intrusive (without occupying on-chip resources), full-speed, in-system debugging using the product MCU installed in the final application system. The debugging system supports observing and modifying memory and registers, and supports breakpoints, watchpoints, single-step, and run and stop commands. When using JTAG debugging, all analog and digital peripherals can operate with full functionality.
A mixed-signal system-level microcontroller from Cygnal. The chip contains the CPU core of CIP-51, and its instruction system is fully compatible with MCS-51. The C8051F020 microcontroller contains 64kB on-chip Flash program memory, 4352B of RAM, 8 I/O ports with a total of 64 I/O lines, a 12-bit A/D converter and an 8-bit A/D converter, as well as a dual 12-bit D/A converter, 2 comparators, 5 16-bit general-purpose timers, a programmable counter/timer array of 5 capture/compare modules, a watchdog timer, a VDD monitor, and a temperature sensor. The C8051F020 microcontroller supports dual clocks, and its operating voltage range is 2.7 to 3.6V (the withstand voltage of the port I/O, RST and JTAG pins is 5V). Compared with the previous 51 series microcontrollers, the C8051F020 has added many functions, and its reliability and speed have also been greatly improved.
2 Working principle of one-key polyphonic keyboard
A complete intelligent instrument often has many functions, and there are many set ranges and parameters. If one key is used for one function, it is bound to have a large keyboard, and the panel will be enlarged accordingly, which is not beautiful and the cost will increase. Therefore, in this type of instrument, the keyboard is designed to have one key polyphonic, and one key has multiple functions.
In the case of one-key polyphony, a command is not composed of a single key press, but a key sequence. In other words, the interpretation of the meaning of a key depends not only on the current key press, but also on what keys were pressed before. Therefore, for the one-key polyphonic monitoring program, it is necessary to first determine whether a key sequence (not a single key press) has constituted a legal command. If it has constituted a legal command, the command is executed, otherwise wait for a new key input. The one-key polysemy keyboard management program mainly solves the two problems of keyboard key sequence recognition and how to find the corresponding operation program according to the keyboard key sequence. The
above problems can be solved by the method of "one map and three tables". That is, establish a key map, rely on the analysis program state table, analysis program entry table and action routine subroutine table to complete. The analysis program state table is divided into 4 columns, namely the current state PSTi, key code, next state, and action routine subroutine number.
3 Working principle of encoding switch
The encoding switch has 3 pins and 5 pins, 2 of which are press functions, and the other 3 pins control the left and right functions of the encoding switch. Connected to pins 1 and 2 are two metal static pieces of different lengths, and connected to pin 3 is a metal moving piece with 12 or 24 teeth in one circle. When the pulse potentiometer rotates, there are 4 states: pin 3 is connected to pin 1, pin 3 is connected to pin 2 and pin 1, pin 3 is connected to pin 2, and pin 3 is disconnected from pin 2 and pin 1.
In actual use, pin 3 is generally grounded as a data input terminal. Pins 1 and 2 are connected to the I/O port of the microcontroller as data output terminals. Three encoding switches are used in this design, one of which connects pin 1 to P4.0 of the microcontroller and pin 2 to P4.1 of the microcontroller. When the pulse potentiometer rotates left or right, P4.0 and P4.1 will periodically generate the waveform shown in Figure 1. If a 12-point pulse potentiometer rotates one circle, it will generate 12 sets of such waveforms, and a 24-point pulse potentiometer will generate 24 sets of such waveforms. A set of waveforms (or one cycle) contains 4 working states. Therefore, as long as the waveforms of P4.O and P4.1 are detected, it is possible to identify whether the pulse potentiometer is rotating, and whether it is rotating left or right.
4 C8051F020 MCU ADC0
The ADC0 subsystem of C8051F020 includes: a 9-channel configurable analog multiplexer (AMUX0), a programmable gain amplifier (PGA0) and a 100 ksps 12-bit resolution successive approximation register ADC. The ADC integrates a track-and-hold circuit and a programmable window detector. AMUX0, PGA0, data conversion mode and window detector can be configured by software through special function registers. The ADC subsystem is only allowed to work when the ADOEN bit in the ADC0 control register (ADCOCN) is set to 1. When the ADOEN bit is 0, the ADC subsystem is in low-power shutdown mode.
Each pair of ADC0 ports can be programmed to be single-ended input or differential input. The port pairing for differential input is (0, 1), (2, 3), (4, 5), (6, 7), which is determined by the lower 4 bits of the channel selection register AMUXOSL and the lower 4 bits of the channel configuration register AMUXOCF. In AMXOCF, bits 3 to 0 correspond to two pin channels each. Bit value = 0 indicates an independent single-ended input (the reset value is single-ended input); bit value = 1 indicates a differential input pair. The
ADC rate in the C8051F series microcontrollers is programmable, but at least 16 system clocks are required. Generally, a tracking/holding capture time of 3 system clocks (>1.5μs) is automatically added before conversion. The method to set the ADC rate in F020 is to configure bits 7 to 3 of the ADCOCF register, and its reset value is 11111 (bits 7 to 3 = SYSCLK/CLK (SAR) - 1).
Generally, the ADC must be in tracking mode before starting. If bit 6 of the control register ADCOCN is "0", it is always in tracking mode (at this time, starting the four starting modes can be 3 system clocks faster than the tracking start); if it is "1", there are 4 tracking start modes to choose from, that is, assign values to bits 3 to 2 in ADCOCN: 00 is tracking when writing 1 to ADBUSY (software command), 01 is timer 3 overflow tracking, 10 is CNVSTR rising edge tracking (external signal), and 11 is timer 2 overflow tracking.
5 System hardware circuit design
The keyboard part uses a 6×6 matrix keyboard, P7.O~P7.5 are row lines, and P3.0~P3.5 are column lines. The intersection of P3.0 and P7.O is a key, and the P7 port is connected to a 10 kΩ pull-up resistor to 3.3 V. The 1 and 2 pins of the three encoding switches are directly connected to the I/0 pins of the microcontroller. Here, P4.O~P4.5 are selected, the 3 pin is grounded, and the 4 and 5 pins are used as keys. Take the coding switch connected to P4.O and P4.1 as an example, the circuit diagram is shown in Figure 2. The analog-to-digital conversion part uses an internal voltage reference, so just connect the VREF pin to the VREF0 pin. A potentiometer is used to adjust the analog input, single-ended input, the potentiometer resistance is 10 kΩ, the reference voltage is typically 2.43 V, and the power supply voltage is 3.3 V. In order to maximize the reference voltage, a resistor with a resistance of about 3.58 kΩ is required to be connected in series with the potentiometer to the analog port. The hardware circuit is shown in Figure 3. The 4th and 5th pins of the potentiometer are also used as buttons.
6 System Software Design
6.1 One-key polysemy keyboard programming
In keyboard analysis, a working status register is used to save the current state of the keyboard. When the keyboard scans a key, the address of the analysis program state table is found from the analysis program entry table according to the value of the current state, and the analysis program state table is entered from the address to find the matching value, and the next state is sent to the current state unit, and the action number is taken out. The action subroutine entry address is calculated according to the action number, and then the corresponding subroutine is executed. Figure 4 is a flowchart of the key code matching subroutine.
6. 2 Coding switch programming
As can be seen from Figure 1, pins 1 and 2 are both high at the same time. If pin 2 reaches a high level before pin 1, it means left rotation, and if pin 1 reaches a high level before pin 2, it means right rotation. When programming, you can judge the status of pins 1 and 2 based on this feature. Take pin 1 connected to P4.0 and pin 2 connected to P4.1 as an example:
Previous article:Application of filter MAX274 in power parameter measurement
Next article:Comparison of measurement characteristics between vector network analyzer and traditional sampling oscilloscope
- Popular Resources
- Popular amplifiers
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- In what situations are non-contact temperature sensors widely used?
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- What is the chip with 4BMN silk screen? It has 5 pins.
- Can I ask the experts, can a sine wave be converted into a square wave only by using an adder?
- Next-generation DOCSIS 4.0 products, CATV amplifiers based on gallium nitride (GaN) technology
- ④. Drive five-wire four-phase stepper motor
- Bluetooth Protocol
- I encountered a problem when testing the CAN communication isolation chip a few days ago. I hope you can give me some advice.
- Reminiscing about the past! A brief discussion on the century-long history of radio development
- 【ESP32-C3-DevKitM-1】WIFI+SNTP time acquisition of ESP32-C3
- [Qinheng RISC-V core CH582] UART1 send packet loss test
- Learn embedded linux c programming from practice