TI CC2530 Basic Experiment (Timer 3 interrupt mode-free running)

Source: Internet
Author: User

In this experiment, the CC2530 Timer 3 (8-bit) Query method is used to control the LED1 to 1S periodic flashing, this experiment uses 2 registers T3CTL (Timer 3 control register) about Timer 3, IEN1 (interrupt enable 1 register).

For CC2530 Gpio Basics, General Gpio operation about registers, IAR Embedded Workbench IDE software use: TI CC2530 Basic Experiment (ordinary GPIO operation-Light LED)

schematic diagram :


Register Analysis :



Program :

#include <iocc2530.h>/*********************************************** * Program Description: T3 interrupt mode control LED1 with 1S of periodic flashing ********* /#define LED1 p1_0unsigned char count = 0;//used to record the number of timer overflows/*********************** * Function Description: Initialize LED1 * Note: The system does not configure the working clock using the internal RC oscillator, i.e. 16MHz *********************************  /void led1init (void) {P1sel &= ~0x01;   function: normal I/O p1dir |= 0x01;        Direction: Output LED1 = 1; Make it out of State}/*********************************** * Function Description: Timer 3 initialize **********************************/void T3init (void)              {EA = 1;       Regardless of 3,721, first turn on the total interrupt/* Enable Timer 3 Interrupt */IEN1 |= 0x08;  or t3ie = 1;      /* Enable overflow interrupt, default is enable overflow interrupt */T3ctl |= 0x08;      To view the T3CTL register, you need to enable overflow interrupt/* Set divider, free run mode */T3ctl |= 0xE0;     128 frequency T3ctl &= ~0x03;      Free Run mode/* Set Timer 3, turn on timer 3*/t3ctl |= 0x10; To view the T3CTL register, you need to start the timer}/*********************************** * Function Description: Timer 3 Interrupt handler function **********************************/# pragma vector = T3_vector__interrupt void T3_isr (void) {//ircon = 0;//clear interrupt, it seems that the hardware helps us to clear the IRCON corresponding interrupt flag bit if (++count > 254) {count = 0; LED1 =!  LED1;  }}void Main () {led1init ();  T3init (); for (;;);}

Where does the Timer 3 interrupt service program 254 come from?

The system defaults to 2 when the operating frequency is not configured, i.e. 16M=32M/2. 1/(16m/128) *n = 0.5s (once every 0.5 seconds, one off, so it looks like a 1S periodic flicker), to get N = 65200, that is, each overflow increment of (0X00~0XFF), all the total number of overflow = 65200/256 = 254.

Note: Each creation of a new project will have to configure the IAR (to do the basic experiment), TI CC2530 Basic Experiment (ordinary GPIO operation-led light) also has IAR related configuration steps


Summarize:

1, when the system does not configure the operating frequency, that is, 16M operating frequency, the timer increments each time to 1/(16000000/128) = 8us. When using free-running mode, the time required for each overflow is: 2ms

2, Timer 3 uses the interrupt mode, the initialization needs to do things: 1) Turn on the total interrupt EA = 1; 2) Enable Timer 3 interrupt 3) Enable overflow interrupt (default enable) 4) set divider, run mode 5) last start Timer 3

TI CC2530 Basic Experiment (Timer 3 interrupt mode-free running)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.