Timer T3 (8 bits) controls the LED via interrupts

Publisher:山宝宝Latest update time:2018-05-13 Source: eefocusKeywords:Timer Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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)
    {};
}


Keywords:Timer Reference address:Timer T3 (8 bits) controls the LED via interrupts

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

"Hit the point" LED lightning protection design strategy
LED lighting has gradually replaced traditional lighting to become the dominant lighting market. Due to the second revolution in the lighting field, LED lighting technologies such as improvements in lighting efficiency (higher lumens per watt), secondary optical components (better lenses/reflectors), and stronger he
[Embedded]
Based on Infineon LED thyristor dimming solution
There are three main dimming methods at present, namely: analog dimming, PWM dimming and thyristor dimming. When using thyristor dimming to dim LED replacement lamps, the existing dimmer circuit can remain unchanged, so this dimming method is generally favored, and AC-DC control chips suitable for thyristor dimming ha
[Power Management]
Based on Infineon LED thyristor dimming solution
Application of AM335x platform in full-color LED display wall asynchronous control card
1 Introduction to full-color LED display wall control card Full-color LED display control cards can be divided into two categories according to the control method: synchronous control card and asynchronous control card. 1.1 Synchronous control card The full-color LED synchronous display wall is mainly composed of
[Microcontroller]
Application of AM335x platform in full-color LED display wall asynchronous control card
What is the lifetime discount rate for LED products?
Energy saving, environmental protection and long life are the three major advantages of LED products. In terms of energy saving and environmental protection, the editor does not have too many doubts. At present, LED products have gradually conquered the market by relying on the "low energy consumption" selling point
[Power Management]
Analysis of mini2440 LED driver
//Define the name of the LED device, here is leds. After this module is loaded, it will automatically create a device file with this name in the /dev directory. #define DEVICE_NAME "leds" //There are 4 LEDs (light-emitting diodes) on the mini2440 development board; //These 4 LEDs are connected to the PINs (pins) of t
[Microcontroller]
Analysis of mini2440 LED driver
Determinants of LED display quality
 As a professional industry research institution in the field of LED, Gaogong LED Industry Research Institute recently released an analysis report stating that the total output value of the domestic LED industry is expected to increase from 154 billion yuan in 2011 to 205.9 billion yuan in 2012. In recent years, LED d
[Power Management]
Risks of LED lamps in abnormal use
As the country's strength increases, more and more preferential policies are being granted to rural areas, and the support for rural development is increasing. Therefore, the rural lighting market has huge potential to be tapped. Under the premise of the rapid development of LED technology, the cost of various compone
[Power Management]
Portable device LED display lighting design
introduction LED drivers have quickly become an increasingly important application area for power conversion technology. In addition to the requirements for higher efficiency and lower quiescent current, LED drivers have many more sophisticated requirements, such as LED matching, dimming, white light balanc
[Power Management]
Portable device LED display lighting design
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号