Esempio n. 1
0
//
// Main Routine
//
int main(void) {
#ifdef DEBUG
	CSerial ser;		// declare a UART object
	ser.enable();
	CDebug dbg(ser);	// Debug stream use the UART object
	dbg.start();
#endif

	//
	// PWM (Using Timer1)
	//
	hwPWM pwm1(TIMER_1, 5, 6, 7);	// set pwm1 pins on P0.5 (CH1), P0.6 (CH2) and P0.7 (CH3)
	pwm1.period(0.0002);			// period time = 200us
	pwm1.enable();					// enable PWM module

	// update pwm2 channels duty-cycle (can be updated in any-time)
	pwm1.dutycycle(PWM_CH_1, 0.8f);	// CH1 duty-cycle = 80%
	pwm1.dutycycle(PWM_CH_2, 0.6f);	// CH2 duty-cycle = 60%
	pwm1.dutycycle(PWM_CH_3, 0.2f);	// CH3 duty-cycle = 20%

	//
	// PWM (Using Timer2)
	//
	hwPWM pwm2(TIMER_2, LED_PIN_1, LED_PIN_2);		// set pwm2 pins on LED1 (CH1) and LED2
	pwm2.period(0.0005);			// period time = 500us
	pwm2.enable();					// enable PWM module

	// update pwm2 channels duty-cycle (can be updated in any-time)
	pwm2.dutycycle(PWM_CH_1, 0.8f);	// CH1 duty-cycle = 80%
	pwm2.dutycycle(PWM_CH_2, 0.1f);	// CH2 duty-cycle = 10%

	//
	// LED
	//
	CPin led(LED_PIN_0);
	led.output();

	CTimeout tmLED;
	//
    // Enter main loop.
	//
    while(1) {
    	//
    	// FireFly loop
    	//
    	if ( tmLED.isExpired(500) ) {
    		tmLED.reset();
    		led.toggle();
    	}

    }
}
Esempio n. 2
0
void main(void) 
{
    GPIO = 0x00;
    TRISIO = ~(1<<0 | 1<<1 | 1<<4 );
    // Load OSCCAL value
    OSCCAL = __osccal_val();
    
    
    // Set pin 7(R), 6(G), 3(B) as Output
    UOUTPUT_PORT(TRISIO_R);
    UOUTPUT_PORT(TRISIO_G);
    UOUTPUT_PORT(TRISIO_B);

    // Set pin2(SW) as input
    UINPUT_PORT(TRISIO_SW);
    
    // Set IOC on pin2
    // Test
    rgb[0].duration = 200;//50
    rgb[0].pin = IND_B;
    
    rgb[1].duration = 200;//100
    rgb[1].pin = IND_G;

    rgb[2].duration = 200;//200
    rgb[2].pin = IND_R;
    
    while(1)
    { 
//        USET2(PIN_R, ON); 
        pwm2();
    }
//    while(1)
//    { 
//    USET2(PIN_R, ON);
//    __delay_ms(1000);
//    USET2(PIN_R, OFF);
//    USET2(PIN_G, ON);
//    __delay_ms(1000);
//    USET2(PIN_G, OFF);
//    USET2(PIN_B, ON);
//    __delay_ms(1000);
//    USET2(PIN_B, OFF);
//    }
}
int main(int argc, char** argv)
{
    int i, nBytes;
	int fd; /* file descriptor */
	char buffer[256];

    // create Robovero object
	Robovero test ("/dev/ttyACM0","testLogging.log");
	
    // connect pwm channels 1 and 4
	PWMDevice pwm1 (&test, 1);
	PWMDevice pwm2 (&test, 4);
	
	for (i=0;i<30;i++)
	{
		pwm1.move(196+(45+90*(i%2))*1820/180);
		pwm2.move(196+(0+90*(i%2))*1820/180);
		sleep(1);
	}
    	return 0;
}
Esempio n. 4
0
int main(void)
{
	/* FIFO Buffer */
	unsigned long temp[1];

	/*Set the clocking to directly run from the crystal at 8MHz*/
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

	/*Enable ADC Peripheral*/
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	//Enable Timers.
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

	/* Set the clock for the GPIO Port B */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	/* Set the type of the GPIO Pin */
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_5);

	/* UART configuration */
	InitConsole();

	//Setting the timer for PWM
	TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM);
	TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);

	/*Configure ADC Peripheral*/
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	/*Configure ADC Sequence*/
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);

	/*Enable ADC sequence*/
	ADCSequenceEnable(ADC0_BASE, 3);

	/*Clear ADC Interrupt*/
	ADCIntClear(ADC0_BASE, 3);

	IntMasterEnable();
    TimerLoadSet(TIMER2_BASE, TIMER_B, 500);
    TimerLoadSet(TIMER1_BASE, TIMER_A, 500);
    TimerLoadSet(TIMER0_BASE, TIMER_A, 500);


unsigned long i,k,counter=0,i1=0;

long num1,y=0,num2,num3,j=0,sum1=0,sum2=0,sum3=0;



 	while(1)
    {

		for(i=0;i<15648;i++)
		  {
             if(i%24 == 0)
             {
            	ADCProcessorTrigger(ADC0_BASE, 3);
				while(!ADCIntStatus(ADC0_BASE, 3, false))
				{
				}
	      ADCIntClear(ADC0_BASE, 3);
	      ADCSequenceDataGet(ADC0_BASE, 3, temp);
          x[i/24]=temp[0];
             }
		   }

		num1=0;
		num2=0;
		num3=0;
		n1=_IQ17(0);
		n2=_IQ17(0);
		n3=_IQ17(0);
		 for(k=0;k<652;k++)
			{
			 l1= _IQ17(b1[k]);
			 l2= _IQ17(b2[k]);
			 l3= _IQ17(b3[k]);
	    	  m= _IQ17(x[651-k]);
			 n1=n1 + _IQ17mpy(l1,m);
			 n2=n2 + _IQ17mpy(l2,m);
			 n3=n3 + _IQ17mpy(l3,m);
	         }
		 num1=_IQ17int(n1);
		 num2=_IQ17int(n2);
		 num3=_IQ17int(n3);
		 sum1+=num1*num1;
		 sum2+=num2*num2;
		 sum3+=num3*num3;
		 j++;

		 if(j==15)
		 {
			 sum1=sum1/500;
			 sum2=sum2/500;
			 sum3=sum3/500;
			 r1=isqrt(sum1);
		     r2=isqrt(sum2);
		     r3=isqrt(sum3);
			 sum1=sum2=0;
			 j=0;
		 }


        r01=r1*r1*r1;
        r02=r2*r2*r2;
        r03=r3*r3*r3;


        if(r01>0)
        	{
        	TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
        	pwm1(256-r01);
        	}
        else
        	{
        	TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC);
        	}


        if(r02>0)
        	{
        	TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
        	pwm2(256-r02);
        	}
        else
        	{
        	TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC);
        	}


        if(r03>0)
        	{
        	TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM);
            pwm3(256-r03);
        	}
        else
        	{
        	TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PERIODIC);
        	}

    }
}