コード例 #1
0
ファイル: rit_interrupt.c プロジェクト: readermank/kico_si5
/*********************************************************************//**
 * @brief		c_entry: Main RIT program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void) {

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();
	 _DBG(menu);

	RIT_Init(LPC_RIT);
	/* Configure time_interval for RIT
	 * In this case: time_interval = 1000 ms = 1s
	 * So, RIT will generate interrupt each 1s
	 */
	RIT_TimerConfig(LPC_RIT,TIME_INTERVAL);

	_DBG("The time interval is: ");
	_DBD32(TIME_INTERVAL); _DBG_(" millisecond..");

#ifdef MCB_LPC_1768 /* Using LED2.2 for testing */
	//turn on LED2.2
	FIO_SetDir(2,(1<<2),1);
	FIO_SetValue(2,(1<<2));
#elif defined(IAR_LPC_1768) /* Using LED1 (P1.25 for testing */
	FIO_SetDir(1,(1<<25),1);
	FIO_ClearValue(1,(1<<25));
#endif
	NVIC_EnableIRQ(RIT_IRQn);

	while(1);
	return 1;
}
コード例 #2
0
/*********************************************************************//**
 * @brief       c_entry: Main ADC program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry(void)
{
    volatile uint32_t adc_value, tmp;
    uint8_t  quit;

    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();

    // print welcome screen
    print_menu();

    /* Initialize ADC ----------------------------------------------------*/
    /*
     * Init ADC pin that currently is being used on the board
     */
    PINSEL_ConfigPin (BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO);
    PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE);

    /* Configuration for ADC :
     *  ADC conversion rate = 400Khz
     */
    ADC_Init(LPC_ADC, 400000);

    ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, DISABLE);
    ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE);

    while(1)
    {
        // Start conversion
        ADC_StartCmd(LPC_ADC, ADC_START_NOW);

        //Wait conversion complete
        while (!(ADC_ChannelGetStatus(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ADC_DATA_DONE)));

        adc_value = ADC_ChannelGetData(LPC_ADC, BRD_ADC_PREPARED_CHANNEL);

        //Display the result of conversion on the UART

        _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL);

        _DBG(" is: "); _DBD32(adc_value); _DBG_("");

        //delay
        for(tmp = 0; tmp < 1000000; tmp++);
        if(_DG_NONBLOCK(&quit) &&
            (quit == 'Q' || quit == 'q'))
            break;
    }
    _DBG_("Demo termination!!!");

    ADC_DeInit(LPC_ADC);

}
コード例 #3
0
/*********************************************************************//**
 * @brief	Main I2S program body
 **********************************************************************/
int c_entry (void) {                       /* Main Program  */
	RIT_CMP_VAL  value;
	PINSEL_CFG_Type PinCfg;

	// DeInit NVIC and SCBNVIC
	NVIC_DeInit();
	NVIC_SCBDeInit();

	/* Configure the NVIC Preemption Priority Bits:
	 * two (2) bits of preemption priority, six (6) bits of sub-priority.
	 * Since the Number of Bits used for Priority Levels is five (5), so the
	 * actual bit number of sub-priority is three (3)
	 */
	NVIC_SetPriorityGrouping(0x05);

	//  Set Vector table offset value
#if (__RAM_MODE__==1)
	NVIC_SetVTOR(0x10000000);
#else
	NVIC_SetVTOR(0x00000000);
#endif

	debug_frmwrk_init();
	 _DBG(menu);

	value.CMPVAL = 10000000;
	value.COUNTVAL = 0x00000000;
	value.MASKVAL = 0x00000000;
	RIT_Init(LPC_RIT);
	RIT_TimerConfig(LPC_RIT,&value);
	RIT_TimerClearCmd(LPC_RIT,ENABLE);

	_DBG("The value compare is: ");
	_DBD32(value.CMPVAL); _DBG_(" system tick");

	//Config P2.2 as GPO2.2
	PinCfg.Funcnum = 0;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 2;
	PinCfg.Pinnum = 2;
	PINSEL_ConfigPin(&PinCfg);

	//turn on LED2.2
	GPIO_SetDir(2,(1<<2),1);
	GPIO_SetValue(2,(1<<2));

	NVIC_EnableIRQ(RIT_IRQn);

	while(1);
	return 1;
}
コード例 #4
0
/**
 * @brief Main Program body
 */
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	uint32_t adc_value;

	/*
	 * Initialize debug via UART
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);

	/* Configuration for ADC :
	 * 	Frequency at 1Mhz
	 *  ADC channel 2, no Interrupt
	 */
	ADC_Init(LPC_ADC, 1000000);
	ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,DISABLE);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,ENABLE);

	while(1)
	{
		// Start conversion
		ADC_StartCmd(LPC_ADC,ADC_START_NOW);
		//Wait conversion complete
		while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_2,ADC_DATA_DONE)));
		adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
		//Display the result of conversion on the UART0
		_DBG("ADC value on channel 2: ");
		_DBD32(adc_value);
		_DBG_("");
		//delay 1s
		Timer_Wait(1000);
	}
	ADC_DeInit(LPC_ADC);
	return 1;
}
コード例 #5
0
ファイル: rtc.cpp プロジェクト: webgou/Equinox-Clock
void RTC_print_time(void){
	char buffer[100];
    time_t rawtime;
    struct tm * timeinfo;


//	xprintf(INFO "%d/%d/%d %d:%d:%d" " (%s:%d)\n",GetDOM(),GetM(),GetY(),GetHH(),GetMM(),GetSS(),_F_,_L_);
	time( &rawtime );
    timeinfo = localtime ( &rawtime );
	strftime(buffer,90,"%d/%m/%Y %I:%M:%S%p WOY:%U DOY:%j",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);
//	xprintf(INFO "%d/%d/%d %d:%d:%d" " (%s:%d)\n",_F_,_L_);
//	xprintf(INFO "Unix: %d" " (%s:%d)\n",time2.unix,_F_,_L_);

//	xprintf(INFO "Sunrise: %d" " (%s:%d)\n",time2.sunrise_unix,_F_,_L_);
	timeinfo = localtime ( &time2.sunrise_unix );
	strftime(buffer,80,"Sunrise: %I:%M:%S%p.",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);

//	xprintf(INFO "Sunset: %d" " (%s:%d)\n",time2.sunset_unix,_F_,_L_);
	timeinfo = localtime ( &time2.sunset_unix );
	strftime(buffer,80,"Sunset: %I:%M:%S%p.",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);

//	xprintf(INFO "Noon: %d" " (%s:%d)\n",time2.noon_unix,_F_,_L_);
	timeinfo = localtime ( &time2.noon_unix );
	strftime(buffer,80,"Noon: %I:%M:%S%p.",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);

	xprintf(INFO "It's %s" " (%s:%d)\n",time2.day_night ? "Night time" : "Day time" ,_F_,_L_);
//	xprintf(INFO "Day/Night: %d" " (%s:%d)\n",time2.day_night,_F_,_L_);
	xprintf(INFO "DST begin: %d end: %d" " (%s:%d)\n",time2.DST_begin_calculated,time2.DST_end_calculated,_F_,_L_);


#if 0
	_DBG("[INFO]-Date=");
	_DBD(GetDOM());
	_DBG("/");
	_DBD(GetM());
	_DBG("/");
	_DBD16(GetY());
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");

	_DBG("[INFO]-Time=");
	_DBD(GetHH());
	_DBG(":");
	_DBD(GetMM());
	_DBG(":");
	_DBD(GetSS());
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");

	_DBG("[INFO]-Unix: ");
	_DBD32(time2.unix);
	_DBG("  Sunrise: ");
	_DBD32(time2.sunrise_unix);
	_DBG("  Sunset: ");
	_DBD32(time2.sunset_unix);
	_DBG("  Noon: ");
	_DBD32(time2.noon_unix);
	_DBG("  Day/Night: ");
	_DBD(time2.day_night);
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");

	_DBG("[INFO]-DST begin: ");
	_DBD32(time2.DST_begin_calculated);
	_DBG("  end: ");
	_DBD32(time2.DST_end_calculated);
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");
#endif
}
コード例 #6
0
/*********************************************************************//**
 * @brief		c_entry: Main ADC program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	uint32_t adc_value, tmp;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* Initialize ADC ----------------------------------------------------*/

	/* Because the potentiometer on different boards (MCB & IAR) connect
	 * with different ADC channel, so we have to configure correct ADC channel
	 * on each board respectively.
	 * If you want to check other ADC channels, you have to wire this ADC pin directly
	 * to potentiometer pin (please see schematic doc for more reference)
	 */
#ifdef MCB_LPC_1768
	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
#elif defined (IAR_LPC_1768)
	/*
	 * Init ADC pin connect
	 * AD0.5 on P1.31
	 */
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 31;
	PinCfg.Portnum = 1;
	PINSEL_ConfigPin(&PinCfg);
#endif

	/* Configuration for ADC :
	 *  Select: ADC channel 2 (if using MCB1700 board)
	 *  		ADC channel 5 (if using IAR-LPC1768 board)
	 *  ADC conversion rate = 200Khz
	 */
	ADC_Init(LPC_ADC, 200000);
	ADC_IntConfig(LPC_ADC,_ADC_INT,DISABLE);
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);

	while(1)
	{
		// Start conversion
		ADC_StartCmd(LPC_ADC,ADC_START_NOW);
		//Wait conversion complete
		while (!(ADC_ChannelGetStatus(LPC_ADC,_ADC_CHANNEL,ADC_DATA_DONE)));
		adc_value = ADC_ChannelGetData(LPC_ADC,_ADC_CHANNEL);
		//Display the result of conversion on the UART0
#ifdef MCB_LPC_1768
		_DBG("ADC value on channel 2: ");
#elif defined (IAR_LPC_1768)
		_DBG("ADC value on channel 5: ");
#endif
		_DBD32(adc_value);
		_DBG_("");
		//delay
		for(tmp = 0; tmp < 1000000; tmp++);
	}
	ADC_DeInit(LPC_ADC);
	return 1;
}
コード例 #7
0
ファイル: qei_test_velo.c プロジェクト: readermank/kico_si5
/*********************************************************************//**
 * @brief		c_entry: Main QEI program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	QEI_CFG_Type QEIConfig;
	QEI_RELOADCFG_Type ReloadConfig;
	uint32_t rpm, averageVelo;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();
	_DBG_("Hello QEI ...");
	_DBG("Speed will be sampled every each ");
	_DBD32(CAP_PERIOD);
	_DBG_(" us");
	_DBG_("This value will be accumulated to display as RPM after every each");
	_DBD32(DISP_TIME);
	_DBG_(" us");

	/* Initialize QEI configuration structure to default value */
#if CAP_MODE
	QEIConfig.CaptureMode = QEI_CAPMODE_4X;
#else
	QEIConfig.CaptureMode = QEI_CAPMODE_2X;
#endif
	QEIConfig.DirectionInvert = QEI_DIRINV_NONE;
	QEIConfig.InvertIndex = QEI_INVINX_NONE;
#if SIGNAL_MODE
	QEIConfig.SignalMode = QEI_SIGNALMODE_CLKDIR;
#else
	QEIConfig.SignalMode = QEI_SIGNALMODE_QUAD;
#endif

	/* Set QEI function pin
	 * P1.20: MCI0
	 * P1.23: MCI1
	 * P1.24: MCI2
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 20;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 23;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 24;
	PINSEL_ConfigPin(&PinCfg);

	/* Initialize QEI peripheral with given configuration structure */
	QEI_Init(LPC_QEI, &QEIConfig);

	// Set timer reload value for  QEI that used to set velocity capture period
	ReloadConfig.ReloadOption = QEI_TIMERRELOAD_USVAL;
	ReloadConfig.ReloadValue = CAP_PERIOD;
	QEI_SetTimerReload(LPC_QEI, &ReloadConfig);

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(QEI_IRQn, ((0x01<<3)|0x01));
	/* Enable interrupt for QEI  */
	NVIC_EnableIRQ(QEI_IRQn);

	// Reset VeloAccFlag
	VeloAccFlag = RESET;
	// Reset value of Acc and Acc count to default
	VeloAcc = 0;
	VeloCapCnt = 0;

	// Enable interrupt for velocity Timer overflow for capture velocity into Acc */
	QEI_IntCmd(LPC_QEI, QEI_INTFLAG_TIM_Int, ENABLE);
	// Enable interrupt for direction change */
	QEI_IntCmd(LPC_QEI, QEI_INTFLAG_DIR_Int, ENABLE);

#ifdef VIRTUAL_QEI_SIGNAL
	// This used for generating virtual QEI signal
	VirtualQEISignal_Init();
#endif

	// Main loop
	while (1) {

		// Check VeloAccFlag continuously
		if (VeloAccFlag == SET) {
			// Get Acc
			averageVelo = (uint32_t)(VeloAcc / VeloCapCnt);
			rpm = QEI_CalculateRPM(LPC_QEI, averageVelo, ENC_RES);
			// Disp the result
			_DBG("Sampling Speed: ");
			_DBD32(rpm);
			_DBG_("RPM");
			// Reset VeloAccFlag
			VeloAccFlag = RESET;
			// Reset value of Acc and Acc count to default
			VeloAcc = 0;
			VeloCapCnt = 0;
		}
	}
    return 1;
}
コード例 #8
0
/**
 * @brief Main program body
 */
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	GPDMA_Channel_CFG_Type GPDMACfg;
	uint32_t adc_value, tmp;

	// DeInit NVIC and SCBNVIC
	NVIC_DeInit();
	NVIC_SCBDeInit();

	/* Configure the NVIC Preemption Priority Bits:
	 * two (2) bits of preemption priority, six (6) bits of sub-priority.
	 * Since the Number of Bits used for Priority Levels is five (5), so the
	 * actual bit number of sub-priority is three (3)
	 */
	NVIC_SetPriorityGrouping(0x05);

	//  Set Vector table offset value
#if (__RAM_MODE__==1)
	NVIC_SetVTOR(0x10000000);
#else
	NVIC_SetVTOR(0x00000000);
#endif

	/*
	 * Initialize debug via UART
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* GPDMA block section -------------------------------------------- */

	/* Disable GPDMA interrupt */
	NVIC_DisableIRQ(DMA_IRQn);
	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01));

	/*
	 * Init LPC_ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);

	/* Configuration for ADC :
	 * 	Frequency at 1Mhz
	 *  ADC channel 2, generate interrupt to make a request for DMA source
	 */
	ADC_Init(LPC_ADC, 1000000);
	ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,SET);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,SET);

	/* Initialize GPDMA controller */
	GPDMA_Init();

	// Setup GPDMA channel --------------------------------
	// channel 0
	GPDMACfg.ChannelNum = 0;
	// Source memory - unused
	GPDMACfg.SrcMemAddr = 0;
	// Destination memory
	GPDMACfg.DstMemAddr = (uint32_t) &adc_value;
	// Transfer size
	GPDMACfg.TransferSize = DMA_SIZE;
	// Transfer width - unused
	GPDMACfg.TransferWidth = 0;
	// Transfer type
	GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M;
	// Source connection
	GPDMACfg.SrcConn = GPDMA_CONN_ADC;
	// Destination connection - unused
	GPDMACfg.DstConn = 0;
	// Linker List Item - unused
	GPDMACfg.DMALLI = 0;
	// Setup channel with given parameter
	GPDMA_Setup(&GPDMACfg, GPDMA_Callback);

	/* Reset terminal counter */
	Channel0_TC = 0;
	/* Reset Error counter */
	Channel0_Err = 0;

	/* Enable GPDMA interrupt */
	NVIC_EnableIRQ(DMA_IRQn);

	while (1) {

		// Enable GPDMA channel 0
		GPDMA_ChannelCmd(0, ENABLE);

		ADC_StartCmd(LPC_ADC,ADC_START_NOW);
		/* Wait for GPDMA processing complete */;
		while ((Channel0_TC == 0) );

		// Disable GPDMA channel 0
		GPDMA_ChannelCmd(0, DISABLE);

		//Display the result of conversion on the UART0
		_DBG("ADC value on channel 2: ");
		_DBD32(ADC_DR_RESULT(adc_value));
		_DBG_("");

		// Wait for a while
		for(tmp = 0; tmp < 1000000; tmp++);

		// Re-setup channel
		GPDMA_Setup(&GPDMACfg, GPDMA_Callback);

		/* Reset terminal counter */
		Channel0_TC = 0;
		/* Reset Error counter */
		Channel0_Err = 0;
	}
	ADC_DeInit(LPC_ADC);
	return 1;
}
コード例 #9
0
ファイル: mouse.c プロジェクト: AJDurant/haprrobot
void printCoords(int32_t x, int32_t y, int32_t t) {
	_DBG_("The coordinate position of the Pololu robot is: ( ");_DBD32(x);_DBG_(" , ");_DBD32(y);_DBG_(" , ");_DBD32(t);_DBG_(" )");
}
コード例 #10
0
/*********************************************************************//**
 * @brief       c_entry: Main MCPWM program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry(void)
{
    // MCPWM Channel configuration data
    MCPWM_CHANNEL_CFG_Type channelsetup[3];

    uint32_t i;

    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();

    _DBG_(menu);

    /* Pin configuration for MCPWM function:
     * Assign:  - P1.19 as MCOA0 - Motor Control Channel 0 Output A
     *          - P1.22 as MCOB0 - Motor Control Channel 0 Output B
     *          - P1.25 as MCOA1 - Motor Control Channel 1 Output A
     *          - P1.26 as MCOB1 - Motor Control Channel 1 Output B
     *          - P1.28 as MCOA2 - Motor Control Channel 2 Output A
     *          - P1.29 as MCOB2 - Motor Control Channel 2 Output B
     *          - P1.20 as MCI0  - Motor Control Feed Back Channel 0
     * Warning: According to Errata.lpc1768-18.March.2010: Input pin (MIC0-2)
     * on the Motor Control PWM peripheral are not functional
     */

    //MCOA0 — Motor control PWM channel 0, output A
    PINSEL_ConfigPin (1, 19, 4);

    //MCI0 — Motor control PWM channel 0 input
    PINSEL_ConfigPin (1, 20, 4);

    //MCOB0 — Motor control PWM channel 0, output B
    PINSEL_ConfigPin (1, 22, 4);

    // Motor control PWM channel 1, output A.
    PINSEL_ConfigPin (1, 25, 4);

    //MCOB1 — Motor control PWM channel 1, output B.
    PINSEL_ConfigPin (1, 26, 4);

    //MCOA2 — Motor control PWM channel 2, output A.
    PINSEL_ConfigPin (1, 28, 4);

    //MCOB2 — Motor control PWM channel 2, output B.
    PINSEL_ConfigPin (1, 29, 1);

    /* Disable interrupt for MCPWM  */
    NVIC_DisableIRQ(MCPWM_IRQn);

    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(MCPWM_IRQn, ((0x01<<3)|0x01));

    /* Init MCPWM peripheral */
    MCPWM_Init(LPC_MCPWM);

    channelsetup[0].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[0].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[0].channelDeadtimeEnable = DISABLE;
    channelsetup[0].channelDeadtimeValue = 0;
    channelsetup[0].channelUpdateEnable = ENABLE;
    channelsetup[0].channelTimercounterValue = 0;
    channelsetup[0].channelPeriodValue = 300;
    channelsetup[0].channelPulsewidthValue = 0;

    channelsetup[1].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[1].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[1].channelDeadtimeEnable = DISABLE;
    channelsetup[1].channelDeadtimeValue = 0;
    channelsetup[1].channelUpdateEnable = ENABLE;
    channelsetup[1].channelTimercounterValue = 0;
    channelsetup[1].channelPeriodValue = 300;
    channelsetup[1].channelPulsewidthValue = 100;

    channelsetup[2].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[2].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[2].channelDeadtimeEnable = DISABLE;
    channelsetup[2].channelDeadtimeValue = 0;
    channelsetup[2].channelUpdateEnable = ENABLE;
    channelsetup[2].channelTimercounterValue = 0;
    channelsetup[2].channelPeriodValue = 300;
    channelsetup[2].channelPulsewidthValue = 200;

    MCPWM_ConfigChannel(LPC_MCPWM, MCPWM_CHANNEL_0, &channelsetup[0]);
    MCPWM_ConfigChannel(LPC_MCPWM, MCPWM_CHANNEL_1, &channelsetup[1]);
    MCPWM_ConfigChannel(LPC_MCPWM, MCPWM_CHANNEL_2, &channelsetup[2]);

#if (MCPWM_WORKING_MODE == DC_MODE_TEST)
    /*
     * - DC mode enabled.
     * - Invert Output enabled
     * - A0 and A1 output pin is internally routed to A0 signal
     */
    MCPWM_DCMode(LPC_MCPWM, ENABLE, ENABLE, (MCPWM_PATENT_A0|MCPWM_PATENT_A1));
#elif (MCPWM_WORKING_MODE == AC_MODE_TEST)
    // AC mode is enabled.
    MCPWM_ACMode(LPC_MCPWM, ENABLE);
#endif

#if CAPTURE_MODE_TEST
    /*
     * Capture mode in this case is used to detect the falling edge on MCO0B output pin.
     * The MCFB0 input pin therefore must be connected to MCO0B. (P1.20 - P1.22)
     * - Capture Channel 0.
     * - Capture falling edge on MCFB0 input pin.
     * - Interrupt enabled on capture event.
     */
    captureCfg.captureChannel = MCPWM_CHANNEL_0;
    captureCfg.captureFalling = ENABLE;
    captureCfg.captureRising = DISABLE;
    captureCfg.hnfEnable = DISABLE;
    captureCfg.timerReset = DISABLE;
    MCPWM_ConfigCapture(LPC_MCPWM, MCPWM_CHANNEL_0, &captureCfg);

    // Reset flag for the first time
    CapFlag = RESET;

    // Enable interrupt for capture event on MCI0 (MCFB0)
    MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE);

    /* Enable interrupt for MCPWM  */
    NVIC_EnableIRQ(MCPWM_IRQn);
#endif

    MCPWM_Start(LPC_MCPWM, ENABLE, ENABLE, ENABLE);

    // Main loop
    while (1)
    {
        //delay
        for(i = 0; i < 100000; i++);

        channelsetup[0].channelPulsewidthValue = (channelsetup[0].channelPulsewidthValue >= 300) ?
                                                        0 : channelsetup[0].channelPulsewidthValue + 20;
        channelsetup[1].channelPulsewidthValue = (channelsetup[1].channelPulsewidthValue >= 300) ?
                                                        0 : channelsetup[1].channelPulsewidthValue + 20;
        channelsetup[2].channelPulsewidthValue = (channelsetup[2].channelPulsewidthValue >= 300) ?
                                                        0 : channelsetup[2].channelPulsewidthValue + 20;

        _DBG_("Update!");

        MCPWM_WriteToShadow(LPC_MCPWM, MCPWM_CHANNEL_0, &channelsetup[0]);
        MCPWM_WriteToShadow(LPC_MCPWM, MCPWM_CHANNEL_1, &channelsetup[1]);
        MCPWM_WriteToShadow(LPC_MCPWM, MCPWM_CHANNEL_2, &channelsetup[2]);

#if CAPTURE_MODE_TEST
        // Check capture flag is set or not
        if (CapFlag)
        {
            // Print out the value
            _DBG("Capture Value: ");

            _DBD32(CapVal); _DBG_("");

            // Must be re-configure the Capture Feature as below for the next capturing,
            //unless, it will not capture anything more.

            // Setup a new capture event
            MCPWM_ConfigCapture(LPC_MCPWM, MCPWM_CHANNEL_0, &captureCfg);

            // Re-Enable interrupt for capture event on MCI0 (MCFB0)
            MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE);

            // Reset flag
            CapFlag = RESET;
        }
#endif
    }

}
コード例 #11
0
/*********************************************************************//**
 * @brief		c_entry: Main ADC program body
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void c_entry(void)
{
	volatile uint32_t tmp;
#if !__DMA_USED__
	uint32_t adc_value;
#endif
    uint8_t  quit;
	EXTI_InitTypeDef EXTICfg;
#if __DMA_USED__
    GPDMA_Channel_CFG_Type GPDMACfg;
#endif
	
	GPIO_Init();
	
	/* Initialize debug via UART0
	* – 115200bps
	* – 8 data bit
	* – No parity
	* – 1 stop bit
	* – No flow control
	*/
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/*
	* Init ADC pin connect
	* AD0.2 on P0.25
	*/
	PINSEL_ConfigPin(BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO);
	PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE);

#ifdef LPC177x_8x_ADC_BURST_MULTI
	/*
	* Init ADC pin connect
	* AD0.3 on P0.26
	*/
	PINSEL_ConfigPin(0, 26, 1);
    PINSEL_SetAnalogPinMode(0,26,ENABLE);

#endif

	/* Configuration for ADC:
	*  select: ADC channel 2
	*  		ADC channel 3
	*  ADC conversion rate = 400KHz
	*/
	ADC_Init(LPC_ADC, 400000);
	ADC_ChannelCmd(LPC_ADC,BRD_ADC_PREPARED_CHANNEL,ENABLE);

#ifdef LPC177x_8x_ADC_BURST_MULTI
    ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,ENABLE);
#endif

#ifdef LPC177x_8x_ADC_INJECT_TEST
	//Config P2.10 as EINT0
	PINSEL_ConfigPin(2,10,1);
	EXTI_Init();

	EXTICfg.EXTI_Line = EXTI_EINT0;
	/* edge sensitive */
	EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
	EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;

	EXTI_Config(&EXTICfg);
	GPIO_SetDir(LED_PORT,LED_PIN,1);
	GPIO_SetValue(LED_PORT,LED_PIN);

	NVIC_EnableIRQ(EINT0_IRQn);
#endif

#if __DMA_USED__
     /* Initialize GPDMA controller */
	GPDMA_Init();

	// Setup GPDMA channel --------------------------------
	// channel 0
	GPDMACfg.ChannelNum = 0;
	// Source memory - unused
	GPDMACfg.SrcMemAddr = 0;
	// Destination memory
	GPDMACfg.DstMemAddr = (uint32_t)s_buf;
	// Transfer size
	GPDMACfg.TransferSize = DMA_SIZE;
	// Transfer width - unused
	GPDMACfg.TransferWidth = 0;
	// Transfer type
	GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M;
	// Source connection
	GPDMACfg.SrcConn = GPDMA_CONN_ADC;
	// Destination connection - unused
	GPDMACfg.DstConn = 0;
	// Linker List Item - unused
	GPDMACfg.DMALLI = 0;
	
	/* Enable GPDMA interrupt */
	NVIC_EnableIRQ(DMA_IRQn);

    while(1)
    {
		 for(tmp = 0; tmp < 0x1000; tmp++);
        /* Reset terminal counter */
	    Channel0_TC = 0;
	    /* Reset Error counter */
	    Channel0_Err = 0;
        for(tmp = 0; tmp < DMA_SIZE; tmp++)
        {
            s_buf[tmp] = 0;
        }
         //Start burst conversion
        ADC_BurstCmd(LPC_ADC,ENABLE);

        GPDMA_Setup(&GPDMACfg);
        // Enable GPDMA channel 1
        GPDMA_ChannelCmd(0, ENABLE);
         /* Wait for GPDMA processing complete */
    	while ((Channel0_TC == 0));
        GPDMA_ChannelCmd(0, DISABLE);
        
         for(tmp = 0; tmp < DMA_SIZE; tmp++)
          {
                if(s_buf[tmp] & ADC_GDR_DONE_FLAG)
                {
                    _DBG("ADC value on channel "); _DBD(ADC_GDR_CH(s_buf[tmp])); _DBG(": ");
                    _DBD32(ADC_GDR_RESULT(s_buf[tmp]));_DBG_("");
                }
          }
          if(_DG_NONBLOCK(&quit) &&
			(quit == 'Q' || quit == 'q'))
			break;
    }
#else
	//Start burst conversion
	ADC_BurstCmd(LPC_ADC,ENABLE);

	while(1)
	{
		adc_value =  ADC_ChannelGetData(LPC_ADC,BRD_ADC_PREPARED_CHANNEL);
		_DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(": ");
		_DBD32(adc_value);
		_DBG_("");

#ifdef LPC177x_8x_ADC_BURST_MULTI
		adc_value =  ADC_ChannelGetData(LPC_ADC,_ADC_CHANNEL_n);
		_DBG("ADC value on channel 3: ");
		_DBD32(adc_value);
		_DBG_("");
#endif
		// Wait for a while
		for(tmp = 0; tmp < 1500000; tmp++);

		if(_DG_NONBLOCK(&quit) &&
			(quit == 'Q' || quit == 'q'))
			break;
	}
#endif /*__DMA_USED__*/

    _DBG_("Demo termination!!!");
	ADC_DeInit(LPC_ADC);
	
	GPIO_Deinit();
	
}
/*********************************************************************//**
 * @brief		c_entry: Main ADC program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);

	/*
	 * Init P2.10
	 *
	 */
	PinCfg.Funcnum = 1; //EINT0
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 10;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);

	/* Configuration for ADC:
	 *  select: ADC channel 2 (if using MCB1700 board)
	 *  		ADC channel 5 (if using IAR-LPC1768 board)
	 *  ADC conversion rate = 200KHz
	 */
	ADC_Init(LPC_ADC, 200000);
	ADC_IntConfig(LPC_ADC,_ADC_INT,ENABLE);
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);
	ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING);

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(ADC_IRQn, ((0x01<<3)|0x01));

	while(1)
	{
		adc_value = 0;

		// Start conversion on EINT0 falling edge
		ADC_StartCmd(LPC_ADC,ADC_START_ON_EINT0);

		/* Enable ADC in NVIC */
		NVIC_EnableIRQ(ADC_IRQn);

		_DBG("Press INT0 button to start ADC conversion on AD0.2...");_DBG_("");
		while(adc_value==0);

		//Display the result of conversion on the UART0
		_DBG("ADC value on channel 2: ");

		_DBD32(adc_value);
		_DBG_("");
	}
	ADC_DeInit(LPC_ADC);
	return (0);
}
コード例 #13
0
ファイル: adc_burst_test.c プロジェクト: readermank/kico_si5
/*********************************************************************//**
 * @brief		c_entry: Main ADC program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	PINSEL_CFG_Type PinCfg1;
#endif
	uint32_t tmp;
	uint32_t adc_value;
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* Because the potentiometer on different boards (MCB & IAR) connect
	 * with different ADC channel, so we have to configure correct ADC channel
	 * on each board respectively.
	 * If you want to check other ADC channels, you have to wire this ADC pin directly
	 * to potentiometer pin (please see schematic doc for more reference)
	 */
#ifdef MCB_LPC_1768
	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	/*
	 * Init ADC pin connect
	 * AD0.3 on P0.26
	 */
	PinCfg1.Funcnum = 1;
	PinCfg1.OpenDrain = 0;
	PinCfg1.Pinmode = 0;
	PinCfg1.Pinnum = 26;
	PinCfg1.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg1);
#endif
#elif defined (IAR_LPC_1768)
	/* select P1.31 as AD0.5 */
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 31;
	PinCfg.Portnum = 1;
	PINSEL_ConfigPin(&PinCfg);
#endif


	/* Configuration for ADC:
	 *  select: ADC channel 2 (if using MCB1700 board)
	 *  		ADC channel 5 (if using IAR-LPC1768 board)
	 *  ADC conversion rate = 200KHz
	 */
	ADC_Init(LPC_ADC, 200000);
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE);
#endif

#ifdef MCB_LPC17XX_ADC_INJECT_TEST
	FIO_ByteSetDir(1, 3, POLL_LED, 1);
	FIO_ByteClearValue(1, 3, POLL_LED);
	// Enable GPIO interrupt P2.10
	GPIO_IntCmd(2,(1<<10),1);
	NVIC_EnableIRQ(EINT3_IRQn);
#endif

	//Start burst conversion
	ADC_BurstCmd(LPC_ADC,ENABLE);
	while(1)
	{
#ifdef MCB_LPC_1768
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
		_DBG("ADC value on channel 2: ");
#elif defined (IAR_LPC_1768)
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_5);
		_DBG("ADC value on channel 5: ");
#endif
		_DBD32(adc_value);
		_DBG_("");
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_3);
		_DBG("ADC value on channel 3: ");
		_DBD32(adc_value);
		_DBG_("");
#endif
		// Wait for a while
		for(tmp = 0; tmp < 1500000; tmp++);
	}
	ADC_DeInit(LPC_ADC);
	return (0);
}
コード例 #14
0
ファイル: ADC_Driver.c プロジェクト: tongjingyu/nxp-os
/*********************************************************************//**
 * @brief		c_entry: Main ADC program body
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void c_entry(void)
{
	GPDMA_Channel_CFG_Type GPDMACfg;
	volatile uint32_t adc_value, tmp;
	uint8_t  quit;

	/* Initialize debug via UART0
	 * ?115200bps
	 * ?8 data bit
	 * ?No parity
	 * ?1 stop bit
	 * ?No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* Initialize ADC ----------------------------------------------------*/

	/* Settings for AD input pin
	 */
	PINSEL_ConfigPin (BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO);
	PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE);

	/*  Configuration for ADC :
	 * 	ADC conversion rate = 400KHz
	 */
	ADC_Init(LPC_ADC, 400000);

	ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, ENABLE);
	ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE);

	/* GPDMA block section -------------------------------------------- */
	/* Disable GPDMA interrupt */
	NVIC_DisableIRQ(DMA_IRQn);

	/* preemption = 1, sub-priority = 1 */
	NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01));

	/* Initialize GPDMA controller */
	GPDMA_Init();

	// Setup GPDMA channel --------------------------------
	// channel 0
	GPDMACfg.ChannelNum = 0;
	// Source memory - unused
	GPDMACfg.SrcMemAddr = 0;
	// Destination memory
	GPDMACfg.DstMemAddr = (uint32_t) &adc_value;
	// Transfer size
	GPDMACfg.TransferSize = DMA_SIZE;
	// Transfer width - unused
	GPDMACfg.TransferWidth = 0;
	// Transfer type
	GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M;
	// Source connection
	GPDMACfg.SrcConn = GPDMA_CONN_ADC;
	// Destination connection - unused
	GPDMACfg.DstConn = 0;
	// Linker List Item - unused
	GPDMACfg.DMALLI = 0;
	GPDMA_Setup(&GPDMACfg);

	/* Reset terminal counter */
	Channel0_TC = 0;
	/* Reset Error counter */
	Channel0_Err = 0;

	/* Enable GPDMA interrupt */
	NVIC_EnableIRQ(DMA_IRQn);

	while (1)
	{
		// Enable GPDMA channel 0
		GPDMA_ChannelCmd(0, ENABLE);

		ADC_StartCmd(LPC_ADC, ADC_START_NOW);

		/* Wait for GPDMA processing complete */
		while ((Channel0_TC == 0));

		// Disable GPDMA channel 0
		GPDMA_ChannelCmd(0, DISABLE);

		//Display the result of conversion on the UART
		_DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL);
		_DBG(" is: "); _DBD32(ADC_DR_RESULT(adc_value)); _DBG_("");

		// Wait for a while
		for(tmp = 0; tmp < 1000000; tmp++);

		/* GPDMA Re-setup */
		GPDMA_Setup(&GPDMACfg);

		/* Reset terminal counter */
		Channel0_TC = 0;

		/* Reset Error counter */
		Channel0_Err = 0;

		if(_DG_NONBLOCK(&quit) &&
			(quit == 'Q' || quit == 'q'))
			break;
	}
    _DBG_("Demo termination!!!");

	ADC_DeInit(LPC_ADC);
}
コード例 #15
0
ファイル: main_m0.c プロジェクト: bebtio/pixy-dev
int main(void)
{
	//CTIMER_DECLARE();
#if 0
	uint32_t memory = SRAM1_LOC;
	uint32_t lut = SRAM1_LOC;

	//while(1);
	memset((void *)QQ_LOC, 0x01, 0x3000);
	g_qqueue->writeIndex = 0;
	g_qqueue->produced = 0;
	g_qqueue->consumed = 0;

 	while(1)
 		getRLSFrame(&memory, &lut); 
#endif
#if 0
	int i = 0x12345678;
	foo(&i);
	printf("%d\n", i);
	while(1);
#endif
#if 0
	int i;
	uint32_t lut = SRAM1_LOC;
 	uint32_t memory = SRAM1_LOC+0x1000;
	uint8_t *plut = (uint8_t *)lut;
	for (i=0; i<0x4000; i++)
		plut[i] = i%5==0 ? 1 : 0;
	
 	while(1)
 		getRLSFrame(&memory, &lut); 

#endif
#if 1
	_DBG("M0 start\n");

	chirpOpen();
	exec_init();
	frame_init();
	rls_init();

#if 0
	while(1)
	{
		if (g_foo)
			loop0();
	}
#endif

#if 0
	vsync();
#endif
#if 0
	//while(g_loop);
	uint8_t type = CAM_GRAB_M1R2;
	uint32_t memory = SRAM1_LOC;
	uint16_t offset = 0;
	uint16_t width = 320;
	uint16_t height = 200;
	while(1)
	{
		 getFrame(&type, &memory, &offset, &offset, &width, &height);
		 i++;

		 if (i%50==0)
		 {
			 _DBD32(i), _CR();
		 }
	}
#endif
	//printf("M0 ready\n");
	exec_loop();
#endif
#if 0
	while(1)
	{
		CTIMER_START();
		syncM1((uint32_t *)&LPC_GPIO_PORT->PIN[1], 0x2000);
		CTIMER_STOP();
		
		printf("%d\n", CTIMER_GET());
	}	
#endif
#if 0
{
	uint32_t i;
	uint8_t *lut = (uint8_t *)SRAM1_LOC + 0x10000;
	uint32_t memory = SRAM1_LOC;
	uint32_t size = SRAM1_SIZE/2;
	for (i=0; i<0x10000; i++)
		lut[i] = 0;
	lut[0xb400] = 0;
	lut[0xb401] = 1;
	lut[0xb402] = 1;
	lut[0xb403] = 1;
	lut[0xb404] = 0;
	lut[0xb405] = 1;
	lut[0xb406] = 1;
	lut[0xb407] = 0;
	lut[0xb408] = 0;
	lut[0xb409] = 0;

	while(1)
 		getRLSFrame(&memory, &size); //, (uint32_t *)&lut);
}
#endif

return 0;
}
コード例 #16
0
ファイル: mouse.c プロジェクト: AJDurant/haprrobot
void cb(uint8_t buttons, int8_t y, int8_t t) {

	static int32_t tempt;
	static int32_t tempy;
	static int32_t tempYCurve;
	static int32_t tempTCurve;
	static int state;
	static int prevState;
	_DBD32(t);
	_DBD32(y);
	//if there is a change in the t value only then the robot is spinning
	if(t != 0 && y == 0) {
		prevState = state;
		state = 1;
		overflowProtection(0, t);
		tempt += t;
		
		if (prevState == 2){
		  int32_t tempy2 = converterForCm(tempy);
		  add_to_x(tempy2);
		  add_to_y(tempy2);
		  tempy = 0;
		}
		else if (prevState == 3){
		  curve(converterForCm(tempYCurve), converterForCm(tempTCurve));
		  tempYCurve = 0;
		}
		
		if (tempt > 99){
		  double angleSpun = thetaOfArc(converterForCm(tempt), r); 
		  theta = theta + angleSpun; tempt = 0;
		}
	}
	
	//If there is a change in the y value only then the robot is moving forward
	if(y != 0 && t == 0) {
		prevState = state;
		state = 2;
		overflowProtection(y, 0);
		tempy += y;
		
		if (prevState == 1){
		  double spinVal = thetaOfArc(converterForCm(tempt), r);
		  theta = theta + spinVal; tempt = 0;
		}
		else if (prevState == 3){
		  curve(converterForCm(tempYCurve), converterForCm(tempTCurve));
		  tempYCurve = 0;
		}
		
		if (tempy > 99){
		  int32_t tempy2 = converterForCm(tempy);
		  add_to_x(tempy2);
		  add_to_y(tempy2);
		  tempy = 0;
		}
	}
	//If y and t are changing then the robot is moving in a curve
	if(t != 0 && y != 0) {
		prevState = state;
		state = 3;
		overflowProtection(y, t);
		tempYCurve += y;
		tempTCurve += t;
		if (prevState == 1){
		  double spinVal = thetaOfArc(converterForCm(tempt), r);
		  theta = theta + spinVal; tempt = 0;
		}
		else if (prevState == 2){
		  int32_t tempy2 = converterForCm(tempy);
		  add_to_x(tempy2);
		  add_to_y(tempy2);
		  tempy = 0;
		}
		if (tempYCurve > 99 && tempTCurve > 99){ ///@todo please check your brackets
		  curve(converterForCm(tempYCurve), converterForCm(tempTCurve));
		  tempYCurve = 0;
			tempTCurve = 0;
		}
	}
}
コード例 #17
0
ファイル: mcpwm_simple.c プロジェクト: nate203/32bitmicro
/*********************************************************************//**
 * @brief		c_entry: Main MCPWM program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
    // MCPWM Channel configuration data
    MCPWM_CHANNEL_CFG_Type channelsetup[3];
    uint32_t i;
    PINSEL_CFG_Type PinCfg;

    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();
    _DBG_("Hello MCPWM ...");

    /* Pin configuration for MCPWM function:
     * Assign: 	- P1.19 as MCOA0 - Motor Control Channel 0 Output A
     * 			- P1.22 as MCOB0 - Motor Control Channel 0 Output B
     * 			- P1.25 as MCOA1 - Motor Control Channel 1 Output A
     * 			- P1.26 as MCOB1 - Motor Control Channel 1 Output B
     * 			- P1.28 as MCOA2 - Motor Control Channel 2 Output A
     * 			- P1.29 as MCOB2 - Motor Control Channel 2 Output B
     * 			- P1.20 as MCI0	 - Motor Control Feed Back Channel 0
     * Warning: According to Errata.lpc1768-18.March.2010: Input pin (MIC0-2)
     * on the Motor Control PWM peripheral are not functional
     */
    PinCfg.Funcnum = 1;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = 0;
    PinCfg.Portnum = 1;
    PinCfg.Pinnum = 19;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 22;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 25;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 26;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 28;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 29;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 20;
    PINSEL_ConfigPin(&PinCfg);

    /* Disable interrupt for MCPWM  */
    NVIC_DisableIRQ(MCPWM_IRQn);
    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(MCPWM_IRQn, ((0x01<<3)|0x01));

    /* Init MCPWM peripheral */
    MCPWM_Init(LPC_MCPWM);

    channelsetup[0].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[0].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[0].channelDeadtimeEnable = DISABLE;
    channelsetup[0].channelDeadtimeValue = 0;
    channelsetup[0].channelUpdateEnable = ENABLE;
    channelsetup[0].channelTimercounterValue = 0;
    channelsetup[0].channelPeriodValue = 300;
    channelsetup[0].channelPulsewidthValue = 0;

    channelsetup[1].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[1].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[1].channelDeadtimeEnable = DISABLE;
    channelsetup[1].channelDeadtimeValue = 0;
    channelsetup[1].channelUpdateEnable = ENABLE;
    channelsetup[1].channelTimercounterValue = 0;
    channelsetup[1].channelPeriodValue = 300;
    channelsetup[1].channelPulsewidthValue = 100;

    channelsetup[2].channelType = MCPWM_CHANNEL_EDGE_MODE;
    channelsetup[2].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
    channelsetup[2].channelDeadtimeEnable = DISABLE;
    channelsetup[2].channelDeadtimeValue = 0;
    channelsetup[2].channelUpdateEnable = ENABLE;
    channelsetup[2].channelTimercounterValue = 0;
    channelsetup[2].channelPeriodValue = 300;
    channelsetup[2].channelPulsewidthValue = 200;

    MCPWM_ConfigChannel(LPC_MCPWM, 0, &channelsetup[0]);
    MCPWM_ConfigChannel(LPC_MCPWM, 1, &channelsetup[1]);
    MCPWM_ConfigChannel(LPC_MCPWM, 2, &channelsetup[2]);

#if DC_MODE_TEST
    /*
     * - DC mode enabled.
     * - Invert Output enabled
     * - A0 and A1 output pin is internally routed to A0 signal
     */
    MCPWM_DCMode(LPC_MCPWM, ENABLE, ENABLE, (MCPWM_PATENT_A0|MCPWM_PATENT_A1));
#endif

#if AC_MODE_TEST
    /*
     * - AC mode is enabled.
     */
    MCPWM_ACMode(LPC_MCPWM, ENABLE);
#endif

#if CAPTURE_MODE_TEST
    /*
     * Capture mode in this case is used to detect the falling edge on MCO0B output pin.
     * The MCFB0 input pin therefore must be connected to MCO0B. (P1.20 - P1.22)
     * - Capture Channel 0.
     * - Capture falling edge on MCFB0 input pin.
     * - Interrupt enabled on capture event.
     */
    captureCfg.captureChannel = 0;
    captureCfg.captureFalling = ENABLE;
    captureCfg.captureRising = DISABLE;
    captureCfg.hnfEnable = DISABLE;
    captureCfg.timerReset = DISABLE;
    MCPWM_ConfigCapture(LPC_MCPWM, 0, &captureCfg);

    // Reset flag for the first time
    CapFlag = RESET;

    // Enable interrupt for capture event on MCI0 (MCFB0)
    MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE);

    /* Enable interrupt for MCPWM  */
    NVIC_EnableIRQ(MCPWM_IRQn);
#endif

    MCPWM_Start(LPC_MCPWM, ENABLE, ENABLE, ENABLE);

    // Main loop
    while (1) {
//		Timer_Wait(LPC_TIM0, 1000);
        //delay
        for(i=0; i<100000; i++);

        channelsetup[0].channelPulsewidthValue = (channelsetup[0].channelPulsewidthValue >= 300) ?
                0 : channelsetup[0].channelPulsewidthValue + 20;
        channelsetup[1].channelPulsewidthValue = (channelsetup[1].channelPulsewidthValue >= 300) ?
                0 : channelsetup[1].channelPulsewidthValue + 20;
        channelsetup[2].channelPulsewidthValue = (channelsetup[2].channelPulsewidthValue >= 300) ?
                0 : channelsetup[2].channelPulsewidthValue + 20;
        _DBG_("Update!");
        MCPWM_WriteToShadow(LPC_MCPWM, 0, &channelsetup[0]);
        MCPWM_WriteToShadow(LPC_MCPWM, 1, &channelsetup[1]);
        MCPWM_WriteToShadow(LPC_MCPWM, 2, &channelsetup[2]);
#if CAPTURE_MODE_TEST
        // Check capture flag is set or not
        if (CapFlag) {
            // Print out the value
            _DBG("Capture Value: ");
            _DBD32(CapVal);
            _DBG_("");

            // Setup a new capture event
            MCPWM_ConfigCapture(LPC_MCPWM, 0, &captureCfg);

            // Re-Enable interrupt for capture event on MCI0 (MCFB0)
            MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_CAP0, ENABLE);

            // Reset flag
            CapFlag = RESET;
        }
#endif
    }

    /* Loop forever */
    return 1;
}
コード例 #18
0
/*********************************************************************//**
 * @brief		The entry of the program
 *
 * @param[in]None
 *
 * @return 	None.
 *
 **********************************************************************/
void c_entry (void)
{	    		
  uint32_t result[4];
  uint8_t ver_major, ver_minor;
  uint32_t i;
  uint8_t *ptr;
  uint32_t flash_prog_area_sec_start;
  uint32_t flash_prog_area_sec_end;
  IAP_STATUS_CODE status;

  // Initialize
  debug_frmwrk_init();
  for (i = 0;i < sizeof(buffer);i++)
  {
    buffer[i] = (uint8_t)i;
  }
  flash_prog_area_sec_start = GetSecNum(FLASH_PROG_AREA_START);
  flash_prog_area_sec_end =  GetSecNum(FLASH_PROG_AREA_START + FLASH_PROG_AREA_SIZE);

  _DBG_(menu);

  status = ReadPartID(result);
  if(status != CMD_SUCCESS)
  {
     _DBG("Read Part ID failed with code is ");_DBD(status);_DBG_("");
     while(1);
  }

  _DBG("PartID: ");_DBH32(result[0]);_DBG_("");
  
  status = ReadBootCodeVer(&ver_major, &ver_minor);
  if(status != CMD_SUCCESS)
  {
     _DBG("Read Boot Code Version failed with code is ");_DBD(status);_DBG_("");
     while(1);
  }

  _DBG("Boot Code Version: ");_DBD(ver_major);_DBG(".");_DBD(ver_minor);_DBG_("");

  status = ReadDeviceSerialNum(result);
  if(status != CMD_SUCCESS)
  {
     _DBG("Read UID failed with code is ");_DBD(status);_DBG_("");
     while(1);
  }

  _DBG("UID: ");
  for(i = 0; i < 4; i++)
  {
     _DBD32(result[i]);
	 if(i<3)
	   _DBG("-");
  }
  _DBG_("");

  status = EraseSector(flash_prog_area_sec_start, flash_prog_area_sec_end); 
  if(status != CMD_SUCCESS)
  {
     _DBG("Erase chip failed with code is ");_DBD(status);_DBG_("");
     while(1); 
  }

  status = BlankCheckSector(flash_prog_area_sec_start, flash_prog_area_sec_end,
                                  &result[0], &result[1]);
  if(status != CMD_SUCCESS)
  {
     _DBG("Blank Check failed with code is ");_DBD(status);_DBG_("");
	 if(status == SECTOR_NOT_BLANK)
	 {
	   _DBG(">>>>The first non-blank sector is sector ");
	   _DBD(flash_prog_area_sec_start + result[0]);
	   _DBG_("");
	 }
     while(1); 
  }

  _DBG_("Erase chip: Success");


  /* Be aware that Program and ErasePage take long time to complete!!! If bigger
  RAM is present, allocate big buffer and reduce the number of Program blocks. */

  /* Program flash block by block until the end of the flash. */
  for ( i = 0; i < FLASH_PROG_AREA_SIZE/BUFF_SIZE; i++ )
  {
    ptr = (uint8_t*)(FLASH_PROG_AREA_START + i*BUFF_SIZE);
	status =  CopyRAM2Flash(ptr, buffer,IAP_WRITE_1024);
	if(status != CMD_SUCCESS)
	{
	   _DBG("Program chip failed with code is ");_DBD(status);_DBG_("");
       while(1);
    }
  }
  // Compare
  for ( i = 0; i < FLASH_PROG_AREA_SIZE/BUFF_SIZE; i++ )
  {
    ptr = (uint8_t*)(FLASH_PROG_AREA_START + i*BUFF_SIZE);
	status =  Compare(ptr, buffer,BUFF_SIZE);
	if(status != CMD_SUCCESS)
	{
	   _DBG("Compare memory failed with code is ");_DBD(status);_DBG_("");
       while(1);
	}
  }

   _DBG_("Program chip: Success");

  _DBG_("Demo termination");  
  
  while (1);
}