[AVR]/AT90USB2012. 1. 29. 10:40

[AT90USB1287] Timer2 테스트

[AT90USB1287] Timer2 테스트

AT90USB1287의 타이머 관련 레지스터는 ATMega128과 약간 다른데 드라이버 코드를 수정할 필요가 있다.
//---------------------------------------------------------------------------------------
#define TIMER2_VALUE      (256-115)

volatile unsigned int m_TimerTick = 0;

//---------------------------------------------------------------------------------------
// Timer2
#define TIMER_STOP                         0
#define TIMER2_CLK_DIVCLK                   1
#define TIMER2_CLK_DIV8                     2
#define TIMER2_CLK_DIV32                    3
#define TIMER2_CLK_DIV64                    4
#define TIMER2_CLK_DIV128                   5
#define TIMER2_CLK_DIV512                6
#define TIMER2_CLK_DIV1024                7

#define TIMSK        TIMSK2
#define TIMER2_INT_ENABLE     BIT0
#define Timer2Set(Value)     (TCNT2 = Value)
#define TCCR2        TCCR2B

void Timer2Init(void)
{
    Sbi(TIMSK, TIMER2_INT_ENABLE);
 Sbi(TCCR2, TIMER2_CLK_DIV128);

 //set 1ms
 Timer2Set(TIMER2_VALUE);
}
//---------------------------------------------------------------------------------------



Timer2 인터럽트 핸들러
//---------------------------------------------------------------------------------------
// Timer2 Handler
SIGNAL(TIMER2_OVF_vect)
{
 m_TimerTick++;

 //Led2Toggle();

 //set 1ms
 Timer2Set(TIMER2_VALUE);
}
//---------------------------------------------------------------------------------------



AT90USB1287 Timer 테스트 예제 소스코드
//-----------------------------------------------------------------------------
int main(void)
{
 //시스템 초기화
 SystemInit();
 
 //LED포트 초기화
 Led1Init();
 Led1Off();

 Led2Init();
 Led2Off();

 //UART Init
 DebugInit(BAUD_57600);
 DebugPrint("[AT90USB1287-EX] Test Program - Timer\r\n");

//Timer2초기화
 Timer2Init();
 enable();

 while(1)
 {
  if(m_TimerTick>100)
  {
   
   Led2Toggle();
   m_TimerTick = 0;
  }
 }
}
//-----------------------------------------------------------------------------



Posted by nexp

댓글을 달아 주세요

[DSP]/PICCOLO2011. 4. 30. 20:30

[TMS320F28069 EVM] Timer Interrupt Test - 1초 만들기

[TMS320F28069] Timer Interrupt Test - 1초 만들기

TMS320F28069 Piccolo시리즈는 3개의 32비트 시스템 타이머가 있다.



시스템 타이머 초기화 함수
ConfigCpuTimer() 함수를 이용하면 쉽게 설정 가능하다. 설정할 인자는 각각 아래와 같다.

//-----------------------------------------------------------------------------
//Timer0 Init
void Timer0Init(void)
{
 //인터럽트 루핸들러 설정
 EALLOW;
 PieVectTable.TINT0 = &Timer0Isr;
 EDIS;

//CPU Timer초기화
 InitCpuTimers();

 // Configure CPU-Timer 0 to interrupt every second:
 // 80MHz CPU Freq, 1 second Period (in uSeconds)
 ConfigCpuTimer(&CpuTimer0, 80, 1000);
 StartCpuTimer0();
 
 // Enable CPU INT1 which is connected to CPU-Timer 0:
    IER |= M_INT1;

 // Enable TINT0 in the PIE: Group 1 interrupt 7
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
    
 // Enable global Interrupts and higher priority real-time debug events:
    ERTM;   // Enable Global realtime interrupt DBGM    
}
//-----------------------------------------------------------------------------

interrupt void Timer0Isr(void)
{
 Timer0Handler(); 

 // Acknowledge this interrupt to receive more interrupts from group 1
 PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}



TMS320F28069 EVM Timer 테스트 예제 소스
1초마다 LED깜박이는 예제 테스트
#include "system.h"
#include "timer.h"

void Timer0Handler(void);

volatile unsigned int gTimeTick_1ms = 0;

void Timer0Handler(void)
{
 gTimeTick_1ms++;
}

void main(void)
{
 //DSP System Initialize
 SystemInit();

 Led1Init();
 Led1On();

 //타이 인터럽트 초기화
 Timer0Init();
 enable();  //Enable Global realtime interrupt

 while(1)
 {
  if(gTimeTick_1ms>1000)
  {
   gTimeTick_1ms = 0;
   Led1Toggle();
  }
 }
}  
Posted by nexp

댓글을 달아 주세요

[ST_MICRO]/STM322008. 4. 29. 12:26

[ STM32 ] Timer 테스트 - 1초 만들기

[ STM32 ] Timer 테스트 - 1초 만들기
 
타이머 인터럽트로 1ms만든 후 1초를 만들어 보자
STM32는 16비트 타이머를 가지고 있고 ... 정리를 위해 코드를 작성

//----------------------------------------------------------------------------- 
// Timer2 Interrupt Handler

void Timer2IntrHandler(void)
{
 Led1Toggle();
 Timer2_Counter++;
// SetTimer2(value);
}
//-----------------------------------------------------------------------------
 
//-----------------------------------------------------------------------------
//Timer2 Init

void Timer2Init(void)
{
 NVIC_InitTypeDef NVIC_InitStructure;
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 /* TIM2 clock enable */
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 
 /* Enable the TIM2 gloabal Interrupt */
 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure); 
 
  /* ---------------------------------------------------------------
    TIM2 Configuration: Output Compare Timing Mode:
    TIM2CLK = 36 MHz, Prescaler = 4, TIM2 counter clock = 7.2 MHz
    CC1 update rate = TIM2 counter clock / CCR1_Val = 146.48 Hz
    CC2 update rate = TIM2 counter clock / CCR2_Val = 219.7 Hz
    CC3 update rate = TIM2 counter clock / CCR3_Val = 439.4 Hz
    CC4 update rate = TIM2 counter clock / CCR4_Val =  878.9 Hz
  --------------------------------------------------------------- */
 
 /* Time base configuration */
 TIM_TimeBaseStructure.TIM_Period = 7200;
 TIM_TimeBaseStructure.TIM_Prescaler = 0;
 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 
 /* Prescaler configuration */
 TIM_PrescalerConfig(TIM2, 4, TIM_PSCReloadMode_Immediate);
 
 /* TIM IT enable */
 TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
 
 /* TIM2 enable counter */
 TIM_Cmd(TIM2, ENABLE); 
}
//-----------------------------------------------------------------------------

간단히 만든 MCU 타이머 계산기로 계산 한 결과
    TIM2CLK = 36 MHz, Prescaler = 4, TIM2 counter clock = 7.2 MHz

 



main에서 1초마다 LED 점등..
 
 if(Timer2_Counter>1000)
 {
  Led2Toggle();
  Timer2_Counter = 0;
 }
 
STM32 1Hz Test

Posted by nexp

댓글을 달아 주세요