int main(void)
{
   /* perform the needed initialization here */
    InicializaPuertosTeclasYLeds();

	DatoDAC=0;
	Vmax=930;
	T=100;
	t=0;

	Chip_SCU_DAC_Analog_Config(); //select DAC function
	Chip_DAC_Init(LPC_DAC); //initialize DAC
	Chip_DAC_SetBias(LPC_DAC, DAC_MAX_UPDATE_RATE_400kHz);
	Chip_DAC_SetDMATimeOut(LPC_DAC, 0xffff);
	Chip_DAC_ConfigDAConverterControl(LPC_DAC, DAC_CNT_ENA | DAC_DMA_ENA);


	
    Chip_RIT_Init(LPC_RITIMER);
    Chip_RIT_SetTimerInterval(LPC_RITIMER,1);



    NVIC_EnableIRQ(RITIMER_IRQn);

       while(1) {

         }
         return 0;


}
Пример #2
0
/** \brief Main function
 *
 * This is the main entry point of the software.
 *
 * \returns 0
 *
 * \remarks This function never returns. Return value is only to avoid compiler
 *          warnings or errors.
 */
void inicializatimer(void)
{
	Chip_RIT_Init(LPC_RITIMER);

//	Chip_RIT_SetTimerInterval(LPC_RITIMER, 1);

}
Пример #3
0
void RITInitInterrupt(void)
{
	Chip_RIT_Init(LPC_RITIMER);
	if( timeIntervalRTIms != 0 )
		Chip_RIT_SetTimerInterval(LPC_RITIMER,timeIntervalRTIms);
	else
		Chip_RIT_SetTimerIntervaluS(LPC_RITIMER,timeIntervalRTIus);
//	NVIC_ClearPendingIRQ(RITIMER_IRQn);
	NVIC_EnableIRQ(RITIMER_IRQn);
}
Пример #4
0
void InitTimer(uint8_t timer){
	switch(timer){
	case RIT_TIMER:
		Chip_RIT_Init(LPC_RITIMER);
		SetDelay(RIT_TIMER,100);
		break;
	default:
		break;
	}
}
Пример #5
0
void InicializarTimerRIT(void){
	/* inicializa el Temporizador, con un intervalo en milisegundos */
	 Chip_RIT_Init(LPC_RITIMER);

	 /*Setear el intevalo de interrupción*/
	 Chip_RIT_SetTimerInterval(LPC_RITIMER,INTERVALO_TIMER);

	 /*Habilita la interrupción*/
	 NVIC_EnableIRQ(IRQ_RIT);

}
Пример #6
0
void configRit (uint16_t timeInterval_us, void (*isr)(void))
{
	ritConfig.time = timeInterval_us;
	ritConfig.hook = isr;

	/* Initialize RITimer */
	Chip_RIT_Init(LPC_RITIMER);

	/* Configure RIT for a 1s interrupt tick rate */
	Chip_RIT_SetTimerInterval_(LPC_RITIMER, ritConfig.time);

	NVIC_EnableIRQ(RITIMER_IRQn);
}
void StartOs_Arch_SysTick(void)
{
   /* Set lowest priority for PendSV */
   NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);

   /* Activate Repetitive Interrupt Timer (RIT) for periodic IRQs */
   Chip_RIT_Init(LPC_RITIMER);
   Chip_RIT_SetTimerInterval(LPC_RITIMER, 1); /* 1ms Period */
   Chip_RIT_Enable(LPC_RITIMER);

   /* Enable IRQ for RIT */
   NVIC_EnableIRQ(RITIMER_IRQn);

   /* Set lowest priority for RIT */
   NVIC_SetPriority(RITIMER_IRQn, (1<<__NVIC_PRIO_BITS) - 1);
}
Пример #8
0
/**
 * @brief	Main entry point
 * @return	Nothing
 */
int main(void)
{
    /* Generic Initialization */
    SystemCoreClockUpdate();
    Board_Init();

    /* Initialize RITimer */
    Chip_RIT_Init(LPC_RITIMER);

    /* Configure RIT for a periodic interrupt tick rate */
    Chip_RIT_SetTimerIntervalHz(LPC_RITIMER, TIME_INTERVAL);
    Chip_RIT_Enable(LPC_RITIMER);

    NVIC_EnableIRQ(RITIMER_IRQn);

    /* LED is toggled in interrupt handler */
    while (1) {
        /* Sleep between interrupts */
        __WFI();
    }
}
Пример #9
0
/**
 * @brief	Main entry point
 * @return	Nothing
 */
int main(void) {
	SystemCoreClockUpdate();
	Board_Init();
	setupClock();
	SystemCoreClockUpdate();

	On = true;
	enableOut = false;
	controlFlag = false;

	Board_LED_Set(0, On);
	DEBUGOUT("Starting\n");
	/* Initialize RITimer */
	Chip_RIT_Init(LPC_RITIMER);

	LPC_IOCON->PINSEL[4] |= 0x00000555; //Change this after you know which pwm outputs are needed.
	LPC_IOCON->PINMODE[3] |= (3 << 6);
	LPC_IOCON->PINMODE[3] |= (3 << 12);

	LPC_IOCON->PINSEL[1] |= (1 << 14);
	LPC_IOCON->PINSEL[1] |= (1 << 16);
	LPC_IOCON->PINSEL[1] |= (1 << 18);
	LPC_IOCON->PINSEL[1] |= (1 << 20);
	LPC_IOCON->PINMODE[1] |= (2 << 14);
	LPC_IOCON->PINMODE[1] |= (2 << 16);
	LPC_IOCON->PINMODE[1] |= (2 << 18);
	LPC_IOCON->PINMODE[1] |= (2 << 20);

	LPC_SYSCTL->PCLKSEL[0] |= (1 << 12); //PCLK_PWM1 = CCLK
	LPC_IOCON->PINMODE[4] |= (3 << 26);
	LPC_SYSCTL->PCONP |= (1 << 17); //Enable clock
	LPC_SYSCTL->PCLKSEL[1] |= (1 << 30); //PCLKMPWM = CCLK
	LPC_SYSCTL->PCLKSEL[0] |= (1 << 24);

	Chip_PWM_Init(LPC_PWM1);
	LPC_PWM1->PR = 0;
	Chip_PWM_SetMatch(LPC_PWM1, 0, 3000);
	Chip_PWM_SetMatch(LPC_PWM1, 1, 1500);
	Chip_PWM_SetMatch(LPC_PWM1, 2, 1500);
	Chip_PWM_SetMatch(LPC_PWM1, 3, 1500);

	Chip_PWM_ResetOnMatchEnable(LPC_PWM1, 0);
	Chip_PWM_SetCountClockSrc(LPC_PWM1, PWM_CAPSRC_RISING_PCLK, 0);
	Chip_PWM_SetControlMode(LPC_PWM1, 0, PWM_SINGLE_EDGE_CONTROL_MODE, PWM_OUT_ENABLED);
	Chip_PWM_SetControlMode(LPC_PWM1, 1, PWM_SINGLE_EDGE_CONTROL_MODE, PWM_OUT_ENABLED);
	Chip_PWM_SetControlMode(LPC_PWM1, 2, PWM_SINGLE_EDGE_CONTROL_MODE, PWM_OUT_ENABLED);

	Chip_PWM_LatchEnable(LPC_PWM1, 0, PWM_OUT_ENABLED);
	Chip_PWM_LatchEnable(LPC_PWM1, 1, PWM_OUT_ENABLED);
	Chip_PWM_LatchEnable(LPC_PWM1, 2, PWM_OUT_ENABLED);
	Chip_PWM_LatchEnable(LPC_PWM1, 3, PWM_OUT_ENABLED);

	Chip_PWM_Enable(LPC_PWM1);
	Chip_PWM_Reset(LPC_PWM1);

	Chip_GPIO_Init(LPC_GPIO);

	LPC_MCPWM->CON_SET |= (1 <<3);
	DCACSetFreq(1074);
	LPC_MCPWM->DT = 12;
	LPC_MCPWM->INTEN_SET |= 1;
	LPC_MCPWM->INTF_SET |= 1;
	LPC_MCPWM->CON_SET |= 1;
	freq = 1074;
	NVIC_EnableIRQ(RITIMER_IRQn);

	Chip_ADC_Init(LPC_ADC, &ADCSetup);
	Chip_ADC_SetBurstCmd(LPC_ADC, DISABLE);

	/* Configure RIT for a 1s interrupt tick rate */
	Chip_RIT_SetTimerInterval(LPC_RITIMER, TIME_INTERVAL);


	/* LED is toggled in interrupt handler */
	vout = 0;
	voutOldest = 0;
	voutOld = 0;
	while (1) {
		if(controlFlag) {
			bool emergency = !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency = !emergency;
			if(emergency) {
				enableOut = false;
				vout = 0;
			} else {
			#ifdef enableLoad
				enableOut = Chip_GPIO_GetPinState(LPC_GPIO,0,28);
			#else
				enableOut = true;
			#endif
			}
			Board_LED_Set(0, enableOut);
			DCDCControl();
			DCACControl();
			Vmeasure += readADC(VIN_PIN);
			Imeasure += readADC(CURRENT_PIN);
			times++;
			if(times >= delayFactor && enableOut) {
				DEBUGOUT("%d %d %d %d\n",readADC(VIN_PIN), readADC(VOUT_PIN), readADC(CURRENT_PIN), vout);
				times = 0;
				cycles++;
				if(cycles < ncycles) {
					#ifdef enableMPPT
						MPPT(Vmeasure/delayFactor, Imeasure/delayFactor);
					#endif
					Vmeasure = 0;
					Imeasure = 0;
				} else {
					cycles = 0;
				}
			}
			if(enablePrev != enableOut) {
				DEBUGOUT("TOGGLING %d\n",enableOut);
			}
			enablePrev = enableOut;
			controlFlag = false;
			if(emergency) return 0;
		}
	}
}
Пример #10
0
void InicializarTimer( void )
{
	Chip_RIT_Init( LPC_RITIMER );
	NVIC_EnableIRQ( 11 );
}
Пример #11
0
void InicializarTimer(uint32_t tiempo_ms, uint32_t myIRQ){
	NVIC_EnableIRQ(myIRQ);
	Chip_RIT_Init(LPC_RITIMER);
	Chip_RIT_SetTimerInterval(LPC_RITIMER, tiempo_ms);

}
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void) {
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	uint32_t prompt = 0;

	SystemCoreClockUpdate();
	/* Initialize board and chip */
	Board_Init();
	Board_ADC_Init();

	/* Initialize PWM Units */
	handle0 = Chip_PWM_Init(0, 18, 100);
	handle1 = Chip_PWM_Init(0, 13, 100);

	/* enable clocks and pinmux */
	Chip_USB_Init();

	/* initialize USBD ROM API pointer. */
	g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	/*	WORKAROUND for artf44835 ROM driver BUG:
	 Code clearing STALL bits in endpoint reset routine corrupts memory area
	 next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
	 EP2_IN are used we need to specify 3 here. But as a workaround for this
	 issue specify 4. So that extra EPs control structure acts as padding buffer
	 to avoid data corruption. Corruption of padding memory doesn’t affect the
	 stack/program behaviour.
	 */
	usb_param.max_num_ep = 3 + 1;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	 descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/*	WORKAROUND for artf32219 ROM driver BUG:
		 The mem_base parameter part of USB_param structure returned
		 by Init() routine is not accurate causing memory allocation issues for
		 further components.
		 */
		usb_param.mem_base = USB_STACK_MEM_BASE
				+ (USB_STACK_MEM_SIZE - usb_param.mem_size);

		/*
		 Initialize ADC
		 */
		Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup);
		Chip_ADC_EnableChannel(_LPC_ADC_ID, ADC_CH0, ENABLE);
		Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, ADC_CH0, ENABLE);
		NVIC_SetPriority(_LPC_ADC_IRQ, 1);
		NVIC_EnableIRQ(_LPC_ADC_IRQ);

		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_SetPriority(USB0_IRQn, 1);
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}

	}

	DEBUGSTR("USB CDC class based virtual Comm port example!\r\n");

	/* Start BURST Mode (Continuously Convert and Interrupt) */
	Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
	Chip_RIT_Init(LPC_RITIMER);
	Chip_RIT_SetTimerInterval(LPC_RITIMER, CONTROL_INTERVAL);

	NVIC_EnableIRQ(RIT_IRQn);

	int read_mode = WAITING_HEADER;

	while (1) {

		/* Check if host has connected and opened the VCOM port */

		if ((vcom_connected() != 0) && (prompt == 0)) {
			//vcom_write("Hello World!!\r\n", 15);
			prompt = 1;
		}

		if (prompt) {

			unsigned char c;
			if (vcom_bread(&c, 1) != 0) {
				switch (read_mode) {
				case WAITING_HEADER:
					if (c == PACKET_HEADER) {
						g_buffCounter = 0;
						read_mode = WAITING_FOOTER;
					}
					break;
				case WAITING_FOOTER:
					if (c == PACKET_FOOTER) {
						onReceivePacket();
						read_mode = WAITING_HEADER;
					} else {
						g_rxBuff[g_buffCounter] = c;
						g_buffCounter++;
					}
					break;
				default:
					break;
				}
			}
		}
		/* Sleep until next IRQ happens */
		//__WFI();

	}
}
Пример #13
0
/* DeInitialize the RIT */
void Chip_RIT_DeInit(LPC_RITIMER_T *pRITimer)
{
	Chip_RIT_Init(pRITimer);
	Chip_Clock_Disable(CLK_MX_RITIMER);
}
Пример #14
0
void InicializarTimer(int tiempo){
	Chip_RIT_Init(LPC_RITIMER);
	Chip_RIT_ClearInt(LPC_RITIMER);
	NVIC_EnableIRQ(RITIMER_IRQn); //habilito interr
	Chip_RIT_SetTimerInterval(LPC_RITIMER, tiempo); //seteo tiempo
}
Пример #15
0
int main(void) {
#ifdef NEED_EVENT
	uint32_t DVSEventPointer;
	uint32_t DVSEventTimeLow;
	uint16_t DVSEvent;
	uint32_t timeStampMemory = 0, timeStampDelta = 0;
#endif

	int16_t angle = 0;
	uint32_t cnt =0;

	ExtraPinsInit();
	disablePeripherals();
	Chip_RIT_Init(LPC_RITIMER);
	RTC_TIME_T build = { .time = { BUILD_SEC_INT, BUILD_MIN_INT, BUILD_HOUR_INT, BUILD_DAY_INT, 0, 1, BUILD_MONTH_INT,
	BUILD_YEAR_INT } };
	buildTime = build;
	//This should be one of the first initializations routines to run.
	sensorsInit();
#ifdef NEED_EVENT
	DVS128ChipInit();
#endif
	DacInit();
	UARTInit(LPC_UART, BAUD_RATE_DEFAULT); /* baud rate setting */
	initMotors();
	PWMInit();
#if USE_IMU_DATA
	timerDelayMs(100);
	MPU9105Init();
#endif

#if USE_SDCARD
	SDCardInit();
#endif
#if USE_PUSHBOT
	MiniRobInit();
#endif

#ifdef TEST_RUN
	test();
	//This will not return
#endif

	LED1SetOn();
	// Start M0APP slave processor
	cr_start_m0(&__core_m0app_START__);
	LED1SetOff();

	LED0SetOn();
	LED0SetBlinking(ENABLE);
	UARTShowVersion();
	for (;;) {
		if (ledBlinking && toggleLed0) {
			LED0Toggle();
			toggleLed0 = 0;
		}
		// *****************************************************************************
		//    UARTIterate();
		// *****************************************************************************
		while (bytesReceived(&uart)) {  // incoming char available?
			UART0ParseNewChar(popByteFromReceptionBuffer(&uart));
		}

		// *****************************************************************************
		//    Deal with audio data
		// *****************************************************************************
		/*
		 * do the fft cross correlation and figure out the angle
		 * manipulate the proceeding direction of the pushbot
		 */
		// if buffer reaches a length of 1024
	/*	if(process_flag != -1){  // -1 for not ready, 0 for buffer0, 1 for buffer1
		//	SysTick->CTRL &= ~0x1;
			//xprintf("%d\n", process_flag);
			angle = itd();
			//SysTick->CTRL |= 0x1;
			if(++cnt>150){
				xprintf("angle = %d\n", angle);
				cnt = 0;
			}
		}*/


		// start doing math

#if USE_IMU_DATA
		updateIMUData();
#endif
#if USE_PUSHBOT
		refreshMiniRobSensors();
		if (motor0.updateRequired) {
			motor0.updateRequired = 0;
			updateMotorController(MOTOR0);
		}
		if (motor1.updateRequired) {
			motor1.updateRequired = 0;
			updateMotorController(MOTOR1);
		}
#endif
		/*
		// disable the data streaming through serial
		if (sensorRefreshRequested) {
			sensorRefreshRequested = 0;
			for (int i = 0; i < sensorsEnabledCounter; ++i) {
				if (enabledSensors[i]->triggered) {
					enabledSensors[i]->refresh();
					enabledSensors[i]->triggered = 0;
				}
			}
		}
		*/

#ifdef NEED_EVENT
		// *****************************************************************************
		//    processEventsIterate();
		// *****************************************************************************
		if (events.eventBufferWritePointer == events.eventBufferReadPointer) {		// more events in buffer to process?
			continue;
		}
		if (eDVSProcessingMode < EDVS_PROCESS_EVENTS) { //Not processing events
			if (freeSpaceForTranmission(&uart) < (TX_BUFFER_SIZE - 32) || !(eDVSProcessingMode & EDVS_STREAM_EVENTS)) {
#if LOW_POWER_MODE
				uart.txSleepingFlag = 1;
				__WFE();
#endif
				continue; //Wait until the buffer is empty.
			}
		}
		/*We are either processing events or streaming them.
		 * If streaming the buffer must be empty at this point
		 */

		events.ringBufferLock = true;
		events.eventBufferReadPointer = ((events.eventBufferReadPointer + 1) & DVS_EVENTBUFFER_MASK); // increase read pointer
		DVSEventPointer = events.eventBufferReadPointer;  // cache the value to be faster
		DVSEvent = events.eventBufferA[DVSEventPointer];		 // fetch event from buffer
		DVSEventTimeLow = events.eventBufferTimeLow[DVSEventPointer];	// fetch event from buffer
		events.ringBufferLock = false;
		if (eDVSProcessingMode & EDVS_STREAM_EVENTS) {
			if (freeSpaceForTranmission(&uart) > 6) {	// wait for TX to finish sending!
				pushByteToTransmission(&uart, (DVSEvent >> 8) | 0x80);      // 1st byte to send (Y-address)
				pushByteToTransmission(&uart, DVSEvent & 0xFF);                  // 2nd byte to send (X-address)
				if (eDVSDataFormat == EDVS_DATA_FORMAT_BIN_TSVB) {
					// Calculate delta...
					timeStampDelta = DVSEventTimeLow - timeStampMemory;
					timeStampMemory = DVSEventTimeLow;              // Save the current TS in delta
					// check how many bytes we need to send
					if (timeStampDelta < 0x7F) {
						// Only 7 TS bits need to be sent
						pushByteToTransmission(&uart, (timeStampDelta & 0x7F) | 0x80); // 3rd byte to send (7bit Delta TS, MSBit set to 1)
					} else if (timeStampDelta < 0x3FFF) {
						// Only 14 TS bits need to be sent
						pushByteToTransmission(&uart, (timeStampDelta >> 7) & 0x7F); // 3rd byte to send (upper 7bit Delta TS, MSBit set to 0)
						pushByteToTransmission(&uart, (timeStampDelta & 0x7F) | 0x80); // 4th byte to send (lower 7bit Delta TS, MSBit set to 1)
					} else if (timeStampDelta < 0x1FFFFF) {
						// Only 21 TS bits need to be sent
						pushByteToTransmission(&uart, (timeStampDelta >> 14) & 0x7F); // 3rd byte to send (upper 7bit Delta TS, MSBit set to 0)
						pushByteToTransmission(&uart, (timeStampDelta >> 7) & 0x7F); // 4th byte to send (middle 7bit Delta TS, MSBit set to 0)
						pushByteToTransmission(&uart, (timeStampDelta & 0x7F) | 0x80); // 5th byte to send (lower 7bit Delta TS, MSBit set to 1)
					} else {
Пример #16
0
void InicializarTimer(void)
{
   /* perform the needed initialization here */
	Chip_RIT_Init(LPC_RITIMER);
};