Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LG by
MTimer.c
- Committer:
 - Kovalev_D
 - Date:
 - 2016-03-28
 - Revision:
 - 95:dd51e577e114
 - Parent:
 - 93:b3803774f110
 - Child:
 - 100:e197a8d2cf43
 - Child:
 - 103:e96f08947def
 
File content as of revision 95:dd51e577e114:
#include "MTimer.h"
#include "LPC17xx.h"
#include "MTimer.h"
#include "vibro.h"
#include "QEI.h"
#include "Global.h"
#include "SPI.h"
#include "InputOutput.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////TIMER1////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/////////////////////инициализация таймера 1 /////////////////////////
//////////////////////////////////////////////////////////////////////
//unsigned int CountV=0;
//unsigned int CountVf=0 ;
unsigned int CountV31=0;
unsigned int CountV255=0 ;
unsigned int CountV64  = 0;
unsigned int Init_TIM1 (unsigned int TimerInterval )
{
    LPC_TIM1->MR0 = TimerInterval;
    LPC_TIM1->MCR = 3;				/* Interrupt and Reset on MR1 */
    NVIC_EnableIRQ(TIMER1_IRQn);
}
/////////////////////////////////////////////////////
/////////////////////EVENT///////////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
///////////////////// 1Hz ///////////////////////////
/////////////////////////////////////////////////////
void Event_1Hz(void)// событие раз в 1 Гц
{   int i,t;
    if (Event1Hz)	{
        Event1Hz--;
        Discharg ();
        BackLight ();
      // sprintf(Time,"\r\n");
      /* for ( i = 0; i < 32; i++ )
       {
       	sprintf (Time," <%05d> ", Buff_32Point[i]);
       	WriteCon(Time);
       }*/
       
     // WriteCon("\n\r");
      /* sprintf((Time),"%d",  Spi.DAC_B);
       WriteCon(Time);
       WriteCon("\n\r");*/
       if( Rate_Flag)CMD_Rate();
       
    }
}
/////////////////////////////////////////////////////
///////////////////// 1kHz //////////////////////////
/////////////////////////////////////////////////////
void Event_1KHz(void)// событие раз в 1 кГц
{
    if (Event1K) {
        Event1K --;
        Time1K++;
        if (Time1K == 1000) {
            Time1K = 0;
            Event1Hz ++;
            Time1Hz++;
        }
    }
}
/////////////////////////////////////////////////////
///////////////////// 100kHz //////////////////////////
/////////////////////////////////////////////////////
void Event_100KHz(void)// событие раз в 100 кГц
{
    if (Event100K)	{
        Event100K --;
        Time100K++;
        PinCheng();	// чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами.
        if (OutBufCon1Count)  {
            OutBufCon1Count--;   // обратный отсчет для управления ногой и формирование задержки на выдачу
        }
        if (Time100K == 100) {
            Time100K = 0;
            Event1K ++;
        }
    }
}
/////////////////////////////////////////////////////
//////////////////vibro EVENT////////////////////////
/////////////////////////////////////////////////////
void Event_Vibro(void)// событие от вибр
{
    if (EventVibro)	{
        EventVibro --;
    }
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/////////////////////////включение таймера 1//////////////////////////
//////////////////////////////////////////////////////////////////////
void enable_timer1( void )
{
    LPC_TIM1->TCR = 1;
    return;
}
//////////////////////////////////////////////////////////////////////
/////////////////////////прерывание таймера 1//////////////////////////
//////////////////////////////////////////////////////////////////////
__irq void TIMER1_IRQHandler (void)
{
    ResetCS(ADC);					  	 //prepare ADC for sampling
    SetDAC(DAC);
    CountV255++;
    CountV255 &= 0xff;
    CountV31 =CountV255 & 0x1f;
    CountV64 = CountV255 & 0x3f;
    SetCS(ADC);					    		//start ADC sampling
    ResetDAC(DAC);
    D_QEI();								//чтение данных по счетчику
    cheng();								// расчет вибропривода
//			CuruAngle = CuruAngle + Buff_32Point [CountVf] - 0xffff;
    CuruAngle = CuruAngle + Buff_32Point [CountV255] - 0xffff;
    SPI_Exchange(); 				//Чтение ADS_SPI
    LPC_TIM1->IR = 1;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////TIMER2//////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/////////////////////инициализация таймера 2 /////////////////////////
//////////////////////////////////////////////////////////////////////
unsigned int Init_TIM2 (void)
{
    LPC_TIM2->MR0 = 250;
    LPC_TIM2->MCR = 3;				/* Interrupt and Reset on MR0 */
    NVIC_EnableIRQ(TIMER2_IRQn);
    return 1;
}
//////////////////////////////////////////////////////////////////////
/////////////////////////включение таймера 2//////////////////////////
//////////////////////////////////////////////////////////////////////
void enable_timer2(void)
{
    LPC_TIM2->TCR = 1;
    LPC_TIM2->TCR = 0x01;
}
///////////////////////////////////////////////////////////////////////
/////////////////////////прерывание таймера 2//////////////////////////
///////////////////////////////////////////////////////////////////////
__irq void TIMER2_IRQHandler (void)
{
    LPC_TIM2->IR = 1;
    Global_Time++;
    Time_UART++;
    Time_vibro++;
    Time_1kHz++;
    VibroOut();
    Event100K --;
}
            
    