1 PIC12XX structure
Microchip's single-chip microcomputer was the first to adopt a high-performance and cost-effective embedded controller with RISC (Reduced Instruction Set Computer) structure.
The PIC microcontroller has the characteristics of high speed, low operating voltage, low power consumption, large input and output direct drive capability, online serial programming, low price and small size of the chip. To this end, Microchip has developed a variety of models of products at different levels, including high-end, mid-range and low-end. The PIC12XX is a mid-range PIC microcontroller based on an EEPROM 8-bit microcontroller, with a high-performance RISC CPU, special microcontroller functions, low power consumption functions, and enhanced Timer 1 peripheral functions, providing reliable protection for the precise delay technology of the microcontroller. Its internal structure is shown in Figure 1.
1.1 External structural features
Its pins have high current sink/source capability and can directly drive LEDs. The analog comparator module has an analog comparator, an on-chip programmable comparator voltage reference (CVREF) module, programmable input multiplexing from the device input pins, and externally accessible comparator outputs. Timer 0 is an 8-bit timer/counter with an 8-bit programmable prescaler; enhanced Timer 1 is a 16-bit timer/counter with a prescaler, external strobe input mode, and in-circuit serial programming is possible through two pins.
1.2 Internal structure characteristics
The high-performance RISC-CPU has only 35 instructions. Except for the jump instruction, all instructions are single-cycle. Its clock frequency is DC-20 MHz and the instruction cycle is 0-200 ns. It has a strong interrupt function, an 8-level deep hardware stack, and uses direct, indirect and relative addressing modes. It can choose internal and external oscillators. The internal oscillator is a 4 MHz high-precision oscillator, and its accuracy has been calibrated to ±1% when it leaves the factory. It can wake up the CPU from sleep mode and enter power-saving sleep mode, with low-power power-on reset (POR), power-on delay timer (PWRT) and oscillator start-up timer (OST), undervoltage detection (BOD) and watchdog timer with independent oscillator; the MCLR input pin can be reused, and the pin level change can trigger an interrupt. It has an independent programmable weak pull-up function, programmable code protection, and high-durability flash/EEPROM storage unit. The flash memory can be written up to 10 times, the EEPROM can be written up to 10 times, and the data retention period of the flash memory/data EEPROM is >40 years.
1.3 Timer 1 working characteristics
The Timer 1 module is a 16-bit timer/counter consisting of two readable and writable 8-bit registers (TMR1H and TMR1L). The TMR1 register pair (TMR1H, TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. If the Timer 1 interrupt is enabled, a Timer 1 interrupt will be generated when it overflows. The interrupt can be enabled/disabled by setting/clearing the TMR1IE bit. Timer 1 has three operating modes: synchronous timer mode, synchronous counter mode, and asynchronous counter mode. Its mode is determined by the clock selection bit TMR1CS (T1CON) and the synchronization control bit T1SYNC, as shown in Figure 3.
In timer mode, Timer 1 increments on every instruction cycle. In counter mode, Timer 1 increments on every rising edge of the external clock on the T1CKI pin. Timer 1 can be turned on and off by the TMR1ON (T1CON) control bit. Timer 1 also has an internal "reset input" that can be generated by a CCP module. Timer 1 can be connected to an external crystal oscillator. When the oscillator of Timer 1 is enabled (T1OSCEN position 1), the T1OSI and T1OSO pins are set as input pins. In other words, their corresponding TRIS values are ignored.
2 Precision Delay Technology
2.1 Theoretical Analysis
The frequency of the built-in crystal oscillator of PIC12XX microcontroller is 4 MHz, and its accuracy is ±1%. The clock cycle is 0.25 us, and the single instruction running time is 1 us. The error is 1%us, which leads to a large cumulative error. Therefore, the internal crystal oscillator cannot be used directly for accurate delay. For this reason, a high-precision external clock signal is required. Since Timer 1 is 16 bits and the number of full counts is 2 times, the frequency of 32768Hz, i.e. 215Hz, with an accuracy of 5×10-6, is used as the clock. The full count of Timer 1 is 2 s. If the crystal oscillator is used as the clock, the maximum error in half a year will not exceed 1 min. Figure 4 is the schematic diagram of the external crystal oscillator signal generation circuit.
Since the PIC12XX instructions are executed according to the internal crystal oscillator, in order to improve the delay accuracy of the single chip, an external crystal oscillator signal is used as the clock signal, and the Timer 1 of the microcontroller is used for interrupt delay, so that high-precision arbitrary time delay can be achieved.
2.2 Delay Method
After theoretical analysis, the basic circuit shown in Figure 5 is used for accurate delay. Since a 32786 Hz clock is used and Timer 1 is 16 bits, interrupt delay is used. When the initial value of Timer 1 is set to 0000H, the interrupt delay time is 2 s; when the initial value of Timer 1 is set to 8000H, the interrupt delay time is 1 s. For long delays greater than or equal to 2 s, Timer1 is set to 0000H; for long delays greater than 1 s, Timer1 is set to 8000H; for short delays less than 1 s, Timer 1 is set to the budget initial value, and all short delays are completed in one interrupt, which can greatly improve the accuracy of the delay.
2.3 Delay critical subroutine
Since the precise delay uses an external crystal oscillator, the initialization procedure of Timer 1 connected to the external crystal oscillator adopts the following simplified procedure:
CLRF T1 CON ;Stop Timer1, Internal Clock Source
;T1 oscillator disabled, prescaler = 1:1
CLRF TMR1H ;Clear Timer1 High byte register
CLRF TMR1L ;Clear Timer1 Low byte register
CLRF INTCON ;Disable interrupts
BSF STATUS,RP0 ;Bank1
CLRF PIE1;Disable peripheral interrupts
BCF STATUS, RP0; BankO
CLRF PIR1; Clear peripheral interrupts Flags
MOVLW 0x32 ;External Clock source with 1:8 prescaler
MOVWF T1CON ;Clock source is synchronized to device
;Timerl is stopped and T1 OSC is disabled
BSF T1CON, TMR1ON; Timer starts to increment
;The Timerl interrupt is disabled, do poling on the overflow bit
T1_OVFL_W AI T
BTFSS PIR1, TMR1 IF
GOTO T1_OVFL_WAIT
;Timer has overflowed
BCF PIR1, TMR1IF
According to the delay method analysis, the interrupt initialization value adopts the following procedure:
load_initial_s
bcf T1CON,TMR1ON
CLRF TMR1H; Clear Low byte, ensures no rolover into
TMR1H,Value to load into TMR1H
MOVLW 0X80 ;Value to load into TMR1H, Write High byte
MOVWF TMR1H ;
MOVLW 0X00 ;Value to load into TMR1L, Write Low byte
ADDWF TMR1L; one second intrupt one time run 262162 Tcy, ie 0.262162s. soset tmr1
BSF T1CON,TMR1ON
load_initial_ms
bcf T1CON,TMR1ON
CLRF TMR1L; Clear Low byte, Ensures no rolover into
TMR1H,Value to load into TMR1H
MOVLW 0Xxx; the value is preparative worked out
MOVWF TMR1H;
MOVLW 0Xxx ;the value is preparative worked out
MOVWF TMR1L;
BSF T1CON,TMR1ON
After the program is initialized, by presetting the initial value and adding other program structures, the precise delay of PIC can be achieved.
3 Conclusion
In view of the functional characteristics and advantages of PIC12XX microcontrollers, the use of external crystal oscillator and Timer 1 interrupt technology can achieve more accurate arbitrary delay. In addition. Microchip's PIC series microcontrollers are practical, low-priced, easy to learn, power-saving, high-speed and small in size. They also have functions such as low-power sleep, power-off reset lock, power-on reset circuit, watchdog circuit, etc., and have fewer peripheral devices, small space, low cost, and very reliable confidentiality technology, which can maximize the protection of the interests of developers. Therefore, it has extremely broad application prospects in many fields such as industrial control, instrumentation, computers, and home appliances.
Previous article:Design of three-phase half-controlled rectifier circuit using PIC microcontroller chip
Next article:Target Detection and Tracking System Based on Embedded PIC32 Microcontroller
Recommended ReadingLatest update time:2024-11-16 18:04
- 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
- The official ST Chinese forum is now online. Let’s go and have a look.
- Qorvo Launches High-Performance BAW Filters to Support Band 41 5G Base Station Deployment
- It’s dangerous to make phone calls at a gas station, so is it safe to pay by scanning a QR code with your mobile phone?
- MSP430 MCU's own hardware SPI communication
- Microstrip transmission line impedance matching engineering example
- What methods can be used to generate a ±0.2V rectangular wave?
- FPGA_Digital Electronic System Design and Development Example Navigation.pdf
- How should users install magnetic flap level gauges?
- Do you understand Geely Group's new logo?
- I'm wondering if anyone has used a similar switch?