Beispiel #1
0
int main(void) {
	/* Basic chip initialization is taken care of in SystemInit() called
	 * from the startup code. SystemInit() and chip settings are defined
	 * in the CMSIS system_<part family>.c file.
	 */

	/* Initialize 32-bit timer 0. TIME_INTERVAL is defined as 10mS */
	/* You may also want to use the Cortex SysTick timer to do this */
	init_timer32(0, TIME_INTERVAL);
	/* Enable timer 0. nOur interrupt handler will begin incrementing
	 * the TimeTick global each time timer 0 matches and resets.
	 */
	enable_timer32(0);

	/* Initialize GPIO (sets up clock) */
	GPIOInit();


	LPC_IOCON->R_PIO0_11 |= 1;

	/* Set LED port pin to output */
	GPIOSetDir(LED_PORT, LED_BIT, 1);




	synth_init();


	int i;
	for (i = 0; i < 6; i++) {
		synth_channels[i].freq = 100 * i;
		synth_channels[i].amp = 1 << (16 - i);
		synth_channels[i].func = SYNTH_SAW;
	}

	while (1) {
		int tmp = 500 * ADCValue[1]/512;
		for (i = 0; i < 6; i++)
			synth_channels[i].freq = tmp*(i+1);

	}
	while (1) /* Loop forever */
	{
		/* Each time we wake up... */
		/* Check TimeTick to see whether to set or clear the LED I/O pin */
		if ((timer32_0_counter % LED_TOGGLE_TICKS) < (LED_TOGGLE_TICKS / 2)) {
			GPIOSetValue(LED_PORT, LED_BIT, LED_OFF);
		} else {
			GPIOSetValue(LED_PORT, LED_BIT, LED_ON);
		}
		/* Go to sleep to save power between timer interrupts */
		__WFI();
	}
}
Beispiel #2
0
int main (void) 
{
  SystemCoreClockUpdate();
	
  /* Initialize 32-bits timer 0 */
  init_timer32(0, TIME_INTERVAL);
  enable_timer32(0);
	
  /* Initialize the PWM in timer32_1 enabling match0 output */
  init_timer32PWM(1, period, MATCH0);
  setMatch_timer32PWM (1, 0, period/4);
  enable_timer32(1);

  /* Initialize the PWM in timer16_0 enabling match1 output */
  init_timer16PWM(0, period, MATCH1, 0);
  setMatch_timer16PWM (0, 1, period/2);
  enable_timer16(0);

  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
	
  /* Set port 1_19 to output */
  GPIOSetDir( 1, 6, 1 );
	
  
  while (1)                                /* Loop forever */
  {
	/* I/O configuration and LED setting pending. */
	if ( (timer32_0_counter[0] > 0) && (timer32_0_counter[0] <= 50) )
	{
	  GPIOSetBitValue( 1, 6, 0 );
	}
	if ( (timer32_0_counter[0] > 50) && (timer32_0_counter[0] <= 100) )
	{
	  GPIOSetBitValue( 1, 6, 1 );
	}
	else if ( timer32_0_counter[0] > 100 )
	{
	  timer32_0_counter[0] = 0;
	}
  }
}
Beispiel #3
0
int main (void) 
{
  
  SystemCoreClockUpdate();

  /* TEST_TIMER_NUM is either 0 or 1 for 32-bit timer 0 or 1. */
  init_timer32(TEST_TIMER_NUM, TIME_INTERVAL);
  enable_timer32(TEST_TIMER_NUM);

  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
    
  /* Set port 0_7 to output */
  GPIOSetDir( 0, 7, 1 );

  while (1)                                /* Loop forever */
  {
#if TEST_TIMER_NUM
	/* I/O configuration and LED setting pending. */
	if ( (timer32_1_counter[0] > 0) && (timer32_1_counter[0] <= 50) )
	{
	  GPIOSetBitValue( 0, 7, 0 );
	}
	if ( (timer32_1_counter[0] > 50) && (timer32_1_counter[0] <= 100) )
	{
	  GPIOSetBitValue( 0, 7, 1 );
	}
	else if ( timer32_1_counter[0] > 100 )
	{
	  timer32_1_counter[0] = 0;
	}
#else
	/* I/O configuration and LED setting pending. */
	if ( (timer32_0_counter[0] > 0) && (timer32_0_counter[0] <= 50) )
	{
	  GPIOSetBitValue( 0, 7, 0 );
	}
	if ( (timer32_0_counter[0] > 50) && (timer32_0_counter[0] <= 100) )
	{
	  GPIOSetBitValue( 0, 7, 1 );
	}
	else if ( timer32_0_counter[0] > 100 )
	{
	  timer32_0_counter[0] = 0;
	}
#endif
  }
}
Beispiel #4
0
void FlowrateInit()
{
    uint32_t i;

    /* Initialize GPIO (sets up clock) */
    GPIOInit();
    /* Set flow-rate port pins to input */
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_1_BIT, 0);
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_2_BIT, 0);
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_3_BIT, 0);
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_4_BIT, 0);
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_5_BIT, 0);
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_6_BIT, 0);
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_7_BIT, 0);
    GPIOSetDir(FLOWRATE_PORT, FLOWRATE_8_BIT, 0);

    //enable interrupt on both edge of the flow-rate pins
    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_1_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_1_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_1_BIT);

    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_2_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_2_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_2_BIT);

    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_3_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_3_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_3_BIT);

    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_4_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_4_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_4_BIT);

    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_5_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_5_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_5_BIT);

    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_6_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_6_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_6_BIT);

    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_7_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_7_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_7_BIT);

    GPIOSetInterrupt(FLOWRATE_PORT, FLOWRATE_8_BIT, 0, 1, 0);
    GPIOIntClear(FLOWRATE_PORT, FLOWRATE_8_BIT);
    GPIOIntEnable(FLOWRATE_PORT, FLOWRATE_8_BIT);

    for (i = 0; i < 8; i++)
    {
        Flowrate[i] = 0;
        count[i] = 0;
    }
    //initialize time1
    init_timer32(1, SystemCoreClock - 1);
    enable_timer32(1);
    //enable interrupt for timer and pins
    NVIC_EnableIRQ(EINT2_IRQn);
    NVIC_EnableIRQ(TIMER_32_1_IRQn);
}
Beispiel #5
0
static void touchTimerInit(){
  init_timer32(1, (SystemCoreClock/1000/1000),0,0); //TC :1us
  enable_timer32(1);
}
Beispiel #6
0
int
main(void)
{
	SystemInit();
	xpcc::lpc11::SysTickTimer::enable();

	scl::setOutput(xpcc::lpc::OPEN_DRAIN);
	sda::setOutput(xpcc::lpc::OPEN_DRAIN);

	// Set LED port pin to output
	rot::setOutput();
	gelb::setOutput();
	blau::setOutput();
	gruen::setOutput();
	weiss::setOutput();
	rot::reset();
	gelb::reset();
	blau::reset();
	gruen::reset();
	weiss::set();


	// Initialize 32-bit timer 0. TIME_INTERVAL is defined as 10mS
	// You may also want to use the Cortex SysTick timer to do this
	init_timer32(0, TIME_INTERVAL);
	
	// Enable timer 0. Our interrupt handler will begin incrementing
	// the TimeTick global each time timer 0 matches and resets.
	enable_timer32(0);
	
	xpcc::lpc::Uart1 uart(115200);

	xpcc::delay_ms(10); // glitch ?

	i2c::initialize();
	XPCC_LOG_DEBUG << "TCS3414" << xpcc::endl;

	// Initialize colour sensor
	const uint8_t address = 0b0111001 << 1;

	if(!tcs::initialize()) {
		XPCC_LOG_DEBUG << "ERROR WITH INTIALIZING!" << xpcc::endl; }
	xpcc::delay_ms(100);
	tcs::setGain(xpcc::tcs3414::Gain::X16);
	xpcc::delay_ms(100);
	tcs::setIntegrationTime(xpcc::tcs3414::IntegrationMode::DEFAULT, xpcc::tcs3414::NominalIntegrationTime::MSEC_100);

	while (1)
	{
		gelb::toggle();
		xpcc::delay_ms(150);

		const xpcc::tcs3414::Rgb colors = tcs::getNewColors();
		xpcc::color::HsvT<xpcc::tcs3414::UnderlyingType> hsv;
		colors.toHsv(&hsv);

		XPCC_LOG_DEBUG << "RGB: " << colors << ";" << xpcc::endl;
		XPCC_LOG_DEBUG << "HSV: " << hsv.hue << "\t" << hsv.saturation << "\t" << hsv.value << "\t" << xpcc::endl;

		if(colors.red > 55)
			rot::set();
		else
			rot::reset();

		if(colors.red < 45)
			blau::set();
		else
			blau::reset();
	}
}