Design of accurate delay technology based on PIC12XX

Publisher:AningmengLatest update time:2019-12-31 Source: elecfansKeywords:PIC12XX Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:PIC12XX Reference address:Design of accurate delay technology based on PIC12XX

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

New Codasip Studio Mac version brings more differentiated design potential for RISC-V processors
Munich, Germany, June 2022 – Codasip, a leader in customizable RISC-V processor silicon intellectual property (IP), today announced that its Codasip Studio platform now supports Apple’s macOS Monterey, the current major version of macOS. Codasip Studio is a processor design automation platform used to customize
[Embedded]
New Codasip Studio Mac version brings more differentiated design potential for RISC-V processors
Esperanto and Intel form strategic partnership on IFS and RISC-V
Esperanto Technologies, a leading developer of high-performance, low-power artificial intelligence (AI) reasoning accelerators based on the RISC-V instruction set, recently announced a strategic partnership with Intel to advance its massively parallel RISC-V AI acceleration solutions. As part of the partnership, Esper
[Embedded]
RISC-V mobile phone prototype may be born next year
This article is compiled from https://tuxphones.com/sipeed-rv64-first-risc-v-rv64-phone-linux-2022-2023/ RISC-V ISA is usually divided into two architectures, RV32 and RV64, covering 32-bit and 64-bit registers respectively. Although the RV64 standard is not yet fully compatible with RV32, the two are clo
[Embedded]
RISC-V mobile phone prototype may be born next year
The first RISC-V China Summit will be held soon to bring together the latest technologies and academic achievements
Shanghai, China, May 27, 2021 – The first RISC-V World Conference China will be held on June 21 at ShanghaiTech University. The summit is expected to have more than 1,000 offline attendees and more than 10,000 online attendees, with more than 100 vendors giving speeches or exhibiting. It will be the largest RISC-V-the
[Embedded]
The first RISC-V China Summit will be held soon to bring together the latest technologies and academic achievements
Precise delay technology based on PIC12XX
1 PIC12XX structure Microchip's single-chip microcomputer was the first to adopt a high-performance, cost-effective embedded controller with a RISC (reduced instruction set computer) structure. The PIC microcontroller has the characteristics of high speed, low operating voltage, low power consump
[Microcontroller]
Precise delay technology based on PIC12XX
Engineer: These domestically produced RISC-V MCUs are very powerful!
Initiating topic discussions is an old tradition of the EEWorld forum. This time, we invited senior engineers to talk about MCU chips using the RISC-V core. As a rising star, RISC-V has been hotly sought after in recent years, and has produced countless high-quality products with continuous breakthroughs
[Embedded]
RISC-V basic instruction set architecture and privileged architecture specifications approved
On July 10, the RISC-V Foundation announced the approval of the RISC-V base instruction set architecture and privileged architecture specifications, which is a milestone in the development of the RISC-V ecosystem. The RISC-V base instruction set architecture is used for the interface between software and hardware. S
[Mobile phone portable]
Ni Guangnan: RISC-V is the most popular architecture in China’s CPU field. It is not subject to monopoly restrictions and the supply chain is safe and secure.
On March 2, the first Xuantie RISC-V Ecological Conference organized by Alibaba Pingtouge was held in Shanghai. Representatives from hundreds of companies and institutions around the world, including Intel, Google, Canonical, Imagination, Haier, Alipay, NetEase Youdao, and Skyworth Kukai, gathered together to become t
[Embedded]
Ni Guangnan: RISC-V is the most popular architecture in China’s CPU field. It is not subject to monopoly restrictions and the supply chain is safe and secure.
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号