The T3 timer (8-bit) of CC2530 requires understanding of T3CTL, T3CCTL0, T3CC0, T3CCTL1, and T3CC registers. Timer 3/4 is an 8-bit timer with timer/counter/PWM functions.
Timer 2, also known as MAC timer, is specially designed to support the event tracking protocol in IEEE 802.15.4 MAC. The timer has an 8-bit overflow counter that can be used to record the number of cycles that have occurred; a 16-bit capture register to record the exact time when a frame start delimiter is received/sent or the exact time when the transmission is completed; and a 16-bit output compare register to generate various command selection signals (start receiving, start sending, etc.) to the wireless module at a specific time. If you want to know more about Timer 2, you can refer to the relevant information.
Have you found that as long as the registers are configured correctly, there will be no problem with the rest.
The function of T3CTL (0XCB) is the control and status of timer 3
Bit[7:5]: Timer clock frequency division multiple selection:
000: No frequency division 001: 2 frequency division 010: 4 frequency division
011: 8 frequency division 100: 16 frequency division 101: 32 frequency division
110: 64 frequency division 111: 128 frequency division
Bit4: T3 start and end control bit
Bit3: Overflow interrupt mask 0: Disable overflow interrupt 1: Enable overflow interrupt
Bit2: Clear count value high level valid
Bit[1:0] T3 mode selection
00: Automatic reload 0x00-0xFF
01: DOWN (count from T3CC0 to 0X00 once)
10: Modulo counting (count from 0X00 to T3CC0 repeatedly)
11: UP/DOWN (count from 0X00 to T3CC0 and then to 0X00 repeatedly)
T3CCTL0 (0xCC) is the T3 channel 0 capture/compare control register
Bit6: Channel 0 interrupt mask 0: Interrupt disable 1: Interrupt enable
Bit[5: 3] T3 channel 0 comparison output mode selection
Bit2: T3 channel 0 mode selection: 0: Capture 1: Compare
Bit[1:0] T3 channel 0 capture mode selection
00 No capture 01 Rising edge capture 10 Falling edge capture 11 Edge capture
T3CC0 (0xCD) is the capture/compare value of timer 3 channel 0.
When T3CCTL0.MODE = 1 (compare mode), writing this register will cause T3CC0.VAL[7:0] to update to the input value to be delayed until T3CNT.CNT[7:0] = 0x00.
T3CCTL1 (0xCE) is T3 channel 1 capture/compare control register
Bit6: Channel 1 interrupt mask 0: Interrupt disable 1: Interrupt enable
Bit[5: 3] T3 channel 1 comparison output mode selection
Bit2: T3 channel 1 mode selection: 0: Capture 1: Compare
Bit[1:0] T3 Channel 1 capture mode selection 00 No capture 01 Rising edge capture
10 Falling edge capture 11 Edge capture
T3CC1(0xCF) Timer 3 Channel 1 Capture/Compare Value
Timer capture/compare value channel 1. When T3CCTL1.MODE = 1 (compare mode), writing this register will cause T3CC1.VAL[7:0] to update the written value and delay until T3CNT.CNT[7:0] = 0x00.
Configure T3 as follows. Since timer T3 is 8 bits, the configuration is slightly different.
T3CTL |= 0x08; //Open overflow interrupt
T3IE = 1; //Open general interrupt and T3 interrupt
T3CTL |= 0xE0; //128 frequency division, 128/16000000*N=0.5S, N=62500
T3CTL &= ~0x03; //Auto reload 00->0xff 62500/255=245 (times)
T3CTL |= 0x10; //Start
EA = 1; //Open general interrupt
/****************************************************************************
* Description: Timer T3 controls LED flashing through interruption
**************************************************************************/
#include
typedef unsigned char uchar;
typedef unsigned int uint;
#define LED1 P1_0 // P1.0 port controls LED1
uint count; //Used for timer counting
/****************************************************************************
* Name: InitLed()
* Function: Set the corresponding IO port of the LED lamp
* Input parameters: None
* Output parameters: None
***************************************************************************/
void InitLed(void)
{
P1DIR |= 0x01; //P1.0 is defined as output
LED1 = 1; //Make the LED1 lamp off by default when powered on
}
/****************************************************************************
* Name: InitT3()
* Function: Timer initialization. When the system is not configured with a working clock, the default frequency is 2 division, i.e. 16MHz
* Input parameter: None
* Output parameter: None
****************************************************************************/
void InitT3()
{
T3CTL |= 0x08 ; //Open overflow interrupt
T3IE = 1; //Open total interrupt and T3 interrupt
T3CTL |= 0xE0; //128 division, 128/16000000*N=0.5S, N=62500
T3CTL &= ~0x03; //Automatically reload 00->0xff 62500/255=245(times)
T3CTL |= 0x10; //Start
EA = 1; //Open total interrupt
}
//Timer T3 interrupt processing function
#pragma vector = T3_VECTOR
__interrupt void T3_ISR(void)
{
IRCON = 0x00; //Clear interrupt flag, can also be done automatically by hardwareif
(count++ > 244) //After 245 interrupts, LED is inverted and flashes once (about 0.5 seconds)
{ //Measured by oscilloscope to ensure accuracycount
= 0; //Count clearLED1
= ~LED1; //Change the state of LED1
}
}
/********************************************************************************
* Program entry function
********************************************************************/
void main(void)
{
InitLed(); //Set the corresponding IO port of LED lightInitT3
(); //Set the corresponding register of T3while
(1)
{};
}
Previous article:Timer T1 controls LED1 to flash periodically through query mode
Next article:STM8L uses ADC internal reference voltage channel to measure VDD voltage
Recommended ReadingLatest update time:2024-11-16 13:07
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
- How do you estimate the number of vias on the capacitors in the power supply section of a PCB? Do you need to drill a lot of vias if the capacitors don't carry a lot of current?
- The blueNRG-1 chip will burn out automatically when running the program (solved)
- Application of DSP repetitive control technology in inverter power supply system
- The ov7725 camera has serious distortion. What's going on?
- 【CH579M-R1】+Help: How to receive complete serial port data
- Regarding the calculation of the values of TA0CCR1 and TA0CCR2 configured by the PWM library function
- What does the Y axis of the graph displayed by the baud meter mean? For example, if it starts at 5DB and ends at -100DB, how do you understand it? Attenuation signal...
- Ask SAMD21 question
- LORA SX1308
- Newbie question: When using the PCB antenna library, one of the antenna pins is not connected. I want to know how to solve it.