Haberler:

Eposta uyarılarını yanıtlamayınız ( ! ) https://bit.ly/2J7yi0d

Ana Menü

lpc2368 timer ?

Başlatan armsistem, 26 Temmuz 2012, 21:20:42

armsistem

Arkadaşlar merhaba ; 1 µs ve 5 µs program içerisinde delay kullanmam gerek aşağıda örnek bir örnek 60 Mhz için 10 ms kesme oluşturulduğu söyleniyor benim programım aşağıdaki gibi olduğunu varsayarsak nasıl kullanabilriz.

led yak
delay 5µs
led söndür
delay 1µs
....


main.c
/*****************************************************************************
 *   tmrtest.c:  main C entry file for NXP LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.09.01  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC23xx.H"                        /* LPC23xx/24xx definitions */
#include "type.h"
#include "target.h"
#include "irq.h"
#include "timer.h"

extern DWORD timer_counter;

/*****************************************************************************
**   Main Function  main()
*****************************************************************************/
int main (void)
{	    		
    DWORD counter = 0;

	/************ The main Function is an endless loop ************/
    /* The timer routine is tested on the Keil MCB214x board */
    FIO2DIR = 0x000000FF;		/* P1.16..23 defined as Outputs */
    FIO2CLR = 0x000000FF;		/* turn off all the LEDs */
    
    init_timer( TIME_INTERVAL );
    enable_timer( 0 );

    while (1) 
    {					/* Loop forever */
		if ( timer_counter >= (0x20 * counter) )
		{
			FIO2SET = 1 << counter;
			counter++;
			if ( counter > 8 )
			{
		    	counter = 0;	
		    	timer_counter = 0;
		    	FIO2CLR = 0x000000FF;
			}
	    }
    }
    return 0;
}

/*****************************************************************************
**                            End Of File
******************************************************************************/



Timer.c

/*****************************************************************************
 *   timer.c:  Timer C file for NXP LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.09.01  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC23xx.h"		/* LPC23xx/24xx Peripheral Registers	*/
#include "type.h"
#include "irq.h"
#include "timer.h"

volatile DWORD timer_counter = 0;

/******************************************************************************
** Function name:		Timer0Handler
**
** Descriptions:		Timer/Counter 0 interrupt handler
**				executes each 10ms @ 60 MHz CPU Clock
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void Timer0Handler (void) __irq 
{  
    T0IR = 1;			/* clear interrupt flag */
    IENABLE;			/* handles nested interrupt */

    timer_counter++;

    IDISABLE;
    VICVectAddr = 0;		/* Acknowledge Interrupt */
}

/******************************************************************************
** Function name:		enable_timer
**
** Descriptions:		Enable timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void enable_timer( BYTE timer_num )
{
    if ( timer_num == 0 )
    {
		T0TCR = 1;
    }
    else
    {
		T1TCR = 1;
    }
    return;
}

/******************************************************************************
** Function name:		disable_timer
**
** Descriptions:		Disable timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void disable_timer( BYTE timer_num )
{
    if ( timer_num == 0 )
    {
		T0TCR = 0;
    }
    else
    {
		T1TCR = 0;
    }
    return;
}

/******************************************************************************
** Function name:		reset_timer
**
** Descriptions:		Reset timer
**
** parameters:			timer number: 0 or 1
** Returned value:		None
** 
******************************************************************************/
void reset_timer( BYTE timer_num )
{
    DWORD regVal;

    if ( timer_num == 0 )
    {
		regVal = T0TCR;
		regVal |= 0x02;
		T0TCR = regVal;
    }
    else
    {
		regVal = T1TCR;
		regVal |= 0x02;
		T1TCR = regVal;
    }
    return;
}

/******************************************************************************
** Function name:		init_timer
**
** Descriptions:		Initialize timer, set timer interval, reset timer,
**						install timer interrupt handler
**
** parameters:			None
** Returned value:		true or false, if the interrupt handler can't be
**						installed, return false.
** 
******************************************************************************/
DWORD init_timer ( DWORD TimerInterval ) 
{
    timer_counter = 0;
    T0MR0 = TimerInterval;
    T0MCR = 3;				/* Interrupt and Reset on MR0 */
    if ( install_irq( TIMER0_INT, (void *)Timer0Handler, HIGHEST_PRIORITY ) == FALSE )
    {
		return (FALSE);
    }
    else
    {
		return (TRUE);
    }
}

/******************************************************************************
**                            End Of File
******************************************************************************/

armsistem

Arkadaşlar merhaba , timer ile ilgili aşağıdaki kodu buldum daha deneme şansım olmadı üstadlar bir inceleyebilir mi ?

- Turn on the LED for 0.5 sec.(500 ms mi yapar ?)
- Turn off the LED for 0.5 sec.(500 ms mi yapar ?)
- Totally 1.0 sec. (Toplam 1 saniye.)

#include "LPC23xx.h"


void delay(void)
{
    /* My PCLK of Timer0 is 18Mhz */
    T0PR  = 9999;          // Prescale Register = 9999
    T0MR0 =  900;          // Match Register    =  900
    T0MCR = 0x00000004;    // Stop on MR0: the TC and PC will be stopped
                           // and TCR[0] will be set to 0 if MR0 matches the TC.
    T0TCR = 0x02;          // Counter Reset
    T0TCR = 0x01;          // Counter Enable
    while(T0TC != T0MR0);
}


int main(void)
{
    FIO3DIR |= (1<<26);    // 1 for Output

    while(1)
    {
        FIO3CLR = (1<<26);
        delay();
        FIO3SET = (1<<26);
        delay();
    }

}

armsistem

#2
hocam büyüksün ....

Benim verdiğim örnekte sizinkine yakındı .

armsistem

Arm gitgide hoşuma gidiyor belki sizin için çok basit olabilir ama ezbere yapmadan kavraya kavraya öğrenmek çok iyi.

armsistem

#4
Gerbay Hocam , tekrar teşekkürler.
#include <LPC21XX.h>   			/***32 BIT ARM7 LPC2103***/

/****GECIKME FONKSIYONU****/
void activate_PLL(void)
{
PLLCFG=0x24;
PLLCON=0x01;			   // 60 mhz
PLLFEED=0xaa;
PLLFEED=0x55;
while(!(PLLSTAT%00000400))
			PLLCON=0x03;
PLLFEED=0xaa;
PLLFEED=0x55;
VPBDIV=0x00000001;
}


void initTmr()
{
    T0PR  = 60;
    T0TCR = 2; 			// reset
    T0TCR = 1;			// enable
}

void busyWait(unsigned value)
{
  volatile unsigned i = value;
  T0TC = 0;
  while (T0TC < i);
}

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

/*****GIRIS VE CIKIS TANIMLARI*****/   

int main (void) 
 {
   
 IODIR0 =   0x000000ff;
 IOSET0 =   0x00000000;
 IOCLR0 =   0x00000000;
    IOSET0 = 0x00000010;      // red led off  
  initTmr();
 while(1)
{  
 busyWait(1);
  IOSET0 = 0x00000001;      // red led off  
busyWait(1);
  IOCLR0 = 0x00000001;      // red led on
   busyWait(1);
  IOSET0 = 0x00000002;      // red led off  
busyWait(1);
  IOCLR0 = 0x00000002;      // red led on
  }	
}



Proteus osilaskop resmini koyamadım