Summary based on mini2440 timer module

Publisher:静默思考Latest update time:2022-10-09 Source: csdnKeywords:mini2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. From the document, we can know that mini2440 has a total of 5 timers. As shown in the following figure:

Among them, the four registers of timer 0, 1, 2, and 3 have output pins, which are combined with the buzzer. Timer 4 has no output pin, so timer 4 is used exclusively for timing.


Timers 0 and 1 share an 8-bit frequency divider, and timers 2, 3, and 4 share an 8-bit frequency divider.

T = times * cycle = 1/fre(pwm) where: cycle = 1/f = 1/(50M/(prescaler+1)/(divider value).


About the configuration method of timer 4:


1. From the schematic diagram above, we can know that we need to input a PCLK first (the size is 50M, which has been set in the startup code).


Then it passes through an 8-bit divider, the value can be between (0 and 255). Then it passes through a clock divider (the value can be 2, 4, 8, 16)

So first we should configure the divider and divider value (the corresponding registers are TCFG0, TCFG1).


2. We need to configure

Setting times


3. Configuration:

First, we need to set the manual update bit and auto reload bit (TCON)


Then, we need to set up the timer interrupt. For the interrupt method, see the document of the interrupt summary.


Next, we need to set the start bit and clear the manual update bit.


In this way, we have completed setting a timer.


How to set timer 0:


1. First, we need to set the corresponding output pins (as can be seen from the schematic diagram).


2. Secondly, we need to set the divider value and divider value. (TCFG0, TCFG1).


3. Again, we need to configure the initial value and comparison value of the number of times, where the comparison value determines the reversal moment of the level.

4. Then, we need to set the manual update bit and auto reload bit (TCON)


Next, we need to configure the timer interrupt. For the interrupt method, see the relevant documentation for interrupt configuration.


Finally, we start our timer. We need to set the start bit and clear the manual update bit.


In this way, timer 0 is configured.


The timer related code is as follows:


/************************************************

  NAME    : PWM.C

  DESC   :

  Revision: 2015.8.18 ver 0.0

 ************************************************/

 

 #include "pwm.h"

 #include "led.h"

 #include "music.h"

 #include "uart.h"

 

 volatile  unsigned int div=0;

 volatile  unsigned int div10ms=0;

 volatile  unsigned int t=0;

 volatile  unsigned int t1=0;

 extern void Delay_MS( unsigned int time);

 volatile int count = 0;

 // Tone frequency table

unsigned  Syllable_freq[30]={

      262,294,330,349,392,440,494,50000000,0,0,

      523,587,659,698,784,880,988,0,0,0,

      1046,1175,1318,1397,1568,1760,1976,0,0,0

      };



void delayns(volatile int ns) //delay 200ms

{

 t=(int)ns*200;

 while(1)

 {

  if(t==0)

  {

  break;

  

  }

 }

 

}


void delayns1(volatile int ns) //delay 1s

{

 t1=(int)ns*1000;

 while(1)

 {

  if(t==0)

  {

  break;

  

  }

 }

 

}

/***********************************************

Function  name  :   timer4_irq

Description: Timer 4 interrupt service function

Input parameter :   none

Return          :   none   

Others      :   none                                      

*************************************************/

static void __irq timer4_irq(void)

{

 rSRCPND |= BIT_TIMER4;

    rINTPND |= BIT_TIMER4;

 t--;

 t1--;

 div++;

 switch(div%2)

 {

  case 0:

   timer10ms();

   break;

  case 1:

   break;

  default:

   break;

 }

}

/***********************************************

Function  name  :   time4_init

Description: Timer 4 initialization

Input parameter :   none

Return          :   none   

Others      :   none                                      

*************************************************/

void time4_init(unsigned int msec) //pass in 1

{

 volatile unsigned temp;

 temp=rTCFG0;

 temp&=~(0xf<<8);

 temp|=0xff<<8;

 rTCFG0=temp;

 

 temp=rTCFG1;

 temp&=~(0xf<<20|0xf<<16);

 temp|=0x2<<16;

 rTCFG1=temp; //Use 1/8 frequency

 

 msec=(msec==0)?1:msec; //Legal boundary value judgment

 

 

 rTCNTB4 = (50000*msec)>>11; //Set the timing count buffer value

 

 temp=rTCON;

 temp&=~(0x7<<20); //initialization

 temp|=1<<22|1<<21; // can automatically reload and redefine the value of TCNTB4

 rTCON=temp;

 

 

 

 rSRCPND|=BIT_TIMER4;

 rINTPND|=BIT_TIMER4;

 rINTMOD &=~BIT_TIMER4;

 rINTMSK &=~BIT_TIMER4;

 

 pISR_TIMER4 = (unsigned int)timer4_irq;

 

    temp = rTCON;

   temp &=~(0x7<<20);

   temp|=1<<22|1<<20;

   rTCON=temp;

 

 

}

/***********************************************

Function  name  :   timer10ms

Description: Timer processing function

Input parameter :   none

Return          :   none   

Others      :   none                                      

*************************************************/

void timer10ms()

{

  (div10ms<=4)?(div10ms++):(div10ms=0); //0 1 2 3 4

  switch(div10ms)

  {

   case 0:

    break;

   case 1:

    break;

    

   case 2:

    break;

   case 3:

    break;

   case 4:

    break;

     default:

      break;

  }

}


/***********************************************

Function  name  :   timer0_irq

Description: Timer 0 interrupt service function

Input parameter :   none

Return          :   none   

Others      :   none                                      

*************************************************/

static void  __irq timer0_irq(void)

{


 rSRCPND |= BIT_TIMER0;

    rINTPND |= BIT_TIMER0;

}

/***********************************************

Function  name  :   time0_stop

Description: Disable timer 0

Input parameter :   none

Return          :   none   

Others      :   none                                      

*************************************************/

void time0_stop()

{

 volatile int temp;

 //1. Stop register

 rTCON &= ~(0x1<<0);

 

 //2.configure GPB0 to output and low level disable the pull up function

 temp = rGPBCON;

 temp &=~(0x3<<0);

 temp |= (0x1<<0);

 rGPBCON =temp;

 

 rGPBDAT &=~(0x1<<0);

 rGPBUP |=(0x1<<0); 

}

/***********************************************

Function  name  :   time0_init

Description: Timer 0 initialization

Input parameter :   none

Return          :   none   

Others      :   timer0 init                                      

*************************************************/

void time0_init(unsigned int nes)

{


 volatile unsigned temp;

 

 temp=rGPBCON;

 temp&=~(0x3);

 temp|=0x2;

 rGPBCON=temp;

 

 

 temp=rGPBUP;

 temp&=0;

 rGPBUP=temp;

 

 

 temp=rTCFG0;

 temp&=~(0xf);

 temp|=0xff;

 rTCFG0=temp;

 

 

 temp=rTCFG1;

 temp&=~(0xf<<20|0xf);//initialization

 temp|=0x2;

 rTCFG1=temp; //Use 1/8 frequency

 

 

 

 rTCNTB0 = (50000000/nes)>>11;

 rTCMPB0 = (50000000/nes)>>13;

 

 temp=rTCON;

 temp&=~(1<<3|1<<2|1<<1|1);

 temp|=1<<3|1<<1;

 rTCON=temp;

 

 

 rSRCPND|=BIT_TIMER0; 

 rINTMOD &=~BIT_TIMER0;

 rINTMSK &=~BIT_TIMER0;

 rINTPND|=BIT_TIMER0;

 

 pISR_TIMER0 = (unsigned int)timer0_irq;

 

 temp=rTCON;

 temp&=~(0xf);

 temp|=1<<3|1;

 rTCON=temp;

}

/***********************************************

Function  name  :   play_music

Description: Music playback function

Input parameter :   none

Return          :   none   

Others      :   none                                      

*************************************************/ 

void play_music(void)

{

 unsigned char ch;

 ch=uart_getc();

 while(1)

 {

  switch(ch)

  {

   case 'q':

   {

    time0_stop();

    time0_init(262);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'w':

   {

    time0_stop();

    time0_init(294);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   

   case 'e':

   {

    time0_stop();

    time0_init(330);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'r':

   {

    time0_stop();

    time0_init(349);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 't':

   {

    time0_stop();

    time0_init(392);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'y':

   {

    time0_stop();

    time0_init(440);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'u':

   {

    time0_stop();

    time0_init(494);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'a':

   {

    time0_stop();

    time0_init(523);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 's':

   {

    time0_stop();

    time0_init(587);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'd':

   {

    time0_stop();

    time0_init(659);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'f':

   {

    time0_stop();

    time0_init(698);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'g':

   {

    time0_stop();

    time0_init(784);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'h':

   {

    time0_stop();

    time0_init(880);

    delays(1);

    time0_init(Syllable_freq[7]);

    break;

   }

   case 'j':

   {

    time0_stop();

    time0_init(988);

    delays(1);

    time0_init(Syllable_freq[7]);  // 1046,1175,1318,1397,1568,1760,1976

    break;

   }

   case 'z':

   {

    time0_stop();

    time0_init(1046);

    delays(1);

    time0_init(Syllable_freq[7]); 

    break;

   }

   case 'x':

   {

    time0_stop();

    time0_init(1175);

    delays(1);

    time0_init(Syllable_freq[7]); 

    break;

   }

   case 'c':

   {

    time0_stop();

    time0_init(1318);

    delays(1);

    time0_init(Syllable_freq[7]); 

    break;

   }

   case 'v':

   {

    time0_stop();

    time0_init(1397);

    delays(1);

    time0_init(Syllable_freq[7]); 

    break;

   }

   case 'b':

   {

    time0_stop();

    time0_init(1568);

    delays(1);

    time0_init(Syllable_freq[7]);  

    break;

   }

   case 'n':

   {

    time0_stop();

    time0_init(1760);

    delays(1);

    time0_init(Syllable_freq[7]); 

    break;

   }

   case 'm':

   {

    time0_stop();

    time0_init(1976);

    delays(1);

    time0_init(Syllable_freq[7]); 

    break;

   }

   default:

    break;

   

  }

  ch=uart_getc();

  

 }

 

}

Keywords:mini2440 Reference address:Summary based on mini2440 timer module

Previous article:Summary of mini2440LCD module
Next article:Analysis of the interrupt generation principle in the mini2440 startup code

Recommended ReadingLatest update time:2024-11-16 07:33

U-Boot-2011.03 transplant nandflash to mini2440
u-boot2011.03 supports s3c2440, and the registers are defined in s3c24x0_cpu.h in the arch/arm/includer/asm/ directory. The code contains the s3c2410 read and write nandflash functions, so it is modified based on s3c2410 U-Boot source code download address http://www.linuxidc.com/Linux/2011-07/38897.htm
[Microcontroller]
FFmpeg ported to mini2440
Fedora 8 arm-linux-gcc 3.4.1 Download ffmpeg_x264_src_20071007 source code Free download address: http://linux.linuxidc.com/ The username and password are both www.linuxidc.com The specific download directory is /pub/2011/09/25/FFmpeg ported to mini2440/ Cross-compile x264 #CC=arm-li
[Microcontroller]
MINI2440 updates NK and nboot from SD card (Part 1)
I bought a MINI2440 development board from Youshan. SuperVivi is not open source, and my own board does not have NOR Flash. Burning the system brought me a lot of trouble. I had no choice but to make a burning tool myself. The general idea is to start WINCE from the SD card first, then use the tool to format the Fla
[Microcontroller]
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号