1. Capture/Compare/ PWM Module
The RC2 /CCPI pin of the PICI6C64 microcontroller has the functions of capture/compare/ PWM output , corresponding to the internal capture/compare/PWM module, referred to as the CCPI module. This module has a 16-bit register (CCPR1) which can be set by software as a capture register, compare register or PWM output register. The mode is selected by the CCP1 control register (CCP1CON) in the graphics card.
(I) Capture function
When the RC2/CCP 1 pin is used as a capture function, it should be set to input state. When a pulse event occurs on the CCP1 pin, CCPR1 captures and records the value of TMR1 (counter 1) at this time, and generates a capture interrupt request.
Example 1. BSF TRISC,2; CCP1 pin is set as input
MOVLW,XXXX0101; Select CCP1 as the capture mode,
Each rising edge is valid
MOVWF CCP1CON ; Set CCPP1 control register
The capture function can be used to calculate external pulse width ( frequency ), etc.
0000: CCP1 mode function is disabled (reset).
0100: Capture mode, CCP1 pin captures every falling edge.
0101: Capture mode, every rising edge of CCP1 pin is captured.
0110: Capture mode, CCP1 pin captures every 4 rising edges.
0111: Capture mode, CCP1 pin captures every 16 rising edges.
1000: Compare mode, CCP1 pin is set to 1 when it matches.
1001: Compare mode, CCP1 pin is cleared to 0 when it matches.
1010: Comparison mode, when the match occurs, the CCCP1 pin remains unchanged and an interrupt request is generated.
1011: Compare mode: trigger a special event to occur.
11XX: PWM output mode
(ii) Comparison function RC2/CCP1 pin should be set to output state at this time. In comparison mode, CCPR1 register is constantly compared with TMR1 register. When the values of the two registers are equal (match), the following situations may occur on RC2/CCP1 pin.
(1) Pull to high level
(2) Pull to low level
(3) Remain unchanged.
At the same time, a compare interrupt request is also generated.
Example 2. BCF TRISC,2; CCP1 pin is set as output
MOVLW XXXX1000; select CCP1 as compare mode
When a match occurs, the CCP1 pin is set high.
MOVWF CCP1CON; Set the OCPI control register comparison function, which is often used to time drive certain components.
(III) PWM function
At this time, the RC2/ CC P1 pin should be set to output state. In PWM mode, the user sets the 8-bit duty cycle into the lower 8-bit byte CCPR1L of CCPR1, and the upper 8-bit CCPR1H is used as the PWM register. The PWM generation process is shown in the figure:
PWM cycle = [(PR2) + 1] × 4Tosc × (TMR2 pre- division value)
PWM Dwty Cycle = DC1 × Tosc × (TMR2 pre-division value
DC1 = 10-bit value composed of CCPR1L and CCPR1CON (5:4), so the PWM output resolution can reach up to 10 bits. The relationship between PWM frequency and resolution (under 20 MHz oscillation , see Table 1.
Table 1 PWM frequency and resolution relationship table
2. Synchronous Serial Port (SSP) ??
The PIC16C64 microcontroller has a synchronous serial port, referred to as SSP, which can be used to communicate with other peripheral devices or microcontrollers. Peripheral devices can be EEPROM, shift registers, display drivers, A/D converters, etc. The SSP module can be selected by the user in two working modes
(1)Serial peripheral interface (SPI)
(2)I2C interface
(I) Serial External Interface (SPI) mode The SPI mode allows 8-bit data to be transmitted and received synchronously, using 3 pins to complete its communication function:
(1)Serial Data Out (SDO)
(2) Serial Data Input ( SDI )
(3)Serial Clock ( SCK )
PICI6C64 has an SSP control register SSP CON, which users can set with software to select the working mode they need. Another SSP status register SSPSTAT records the various working states of the SSP.
By setting the SSPCON(5:0) bits, the SPI can operate in the following modes.
(1) Master control mode (SCK as clock output)
(2) Slave mode (SCK as clock input)
(3) Clock polarity (SCK rising/falling edge transmits data) Figure 3 shows a typical example of two microprocessors connected.
The master controller (microprocessor 1) starts transmitting data through the SCK signal. Data is transmitted through the shift register on each clock edge and latched on the next edge. The two processors communicate serially with the same clock polarity, and the two processors can send and receive data at the same time.
(II) I2C method
SSP can complete all slave functions in I2C mode and provide hardware support for master software implementation. Two pins are used for data transmission: RC3/SCK/SCL (clock) and RC4/SD1/SDA (data). The I2C serial communication of PICI6C64 microcontroller supports 7-bit and 10-bit addressing, and can complete standard and fast data transmission.
The user can set SSPCON (3: O) to make the I2C operation work in the following modes:
(1) I2C slave mode (7-bit address).
(2) I2C slave mode (10-bit address).
(3) I2C slave mode (7-bit address) and supports master mode,
(4) I2C slave mode (10-bit address) and supports master mode.
(5) I2C master mode, not used in slave mode.
The SSPSTAT register indicates the status of data transmission, including the detection of the STABT and STOP bits, distinguishing between address and data, determining whether the next byte is a 10-bit address, and the direction of data transfer.
Previous article:PIC10F200 LED running light program
Next article:IAI wireless module test board based on PIC microcontroller
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- 【LuatOS-ESP32】Download tool——Luatoose installation and use
- [ST60 short-distance evaluation] Part 1: First release on the Internet! Detailed evaluation!
- How reliable is Dupont wire???
- Q and D values of capacitors
- TI CC3200 WIFI Training Development Kit——by light-s
- HDMI to MIPI universal driver horizontal screen 1080P HD PC Raspberry Pi projector set-top box PS4 camera sub-screen side-transparent monitor TF card
- FPGA-based RGB to YUV422 digital video conversion.pdf
- "Let's practice together in 2021" + the busy year of 2020
- TMS320C66x study notes universal parallel port interrupt service program example
- How many years can a laptop battery last?