Example #1
0
/**
 *
 * @return
 */
int main(void) {
	int i, j=0;
	uint8_t colourbuf[24][3];//={255,0,127,255,0,127};
	Timer3_init();

	while(1)
	{
		for (i = 0; i < 24; i++)
		{
			colourbuf[i][0] = 0;	//R

			if (i == j)				//G
				colourbuf[i][1] = 255;
			else
				colourbuf[i][1] = 0;

			colourbuf[i][2] = 0;	//B
		}
		WS2812_send2(/*(const uint8_t(*)[]) &*/colourbuf, 24);
		Delay(2000000L);

		if (++j > 24)
			j = 0;
	}

	while (1)
	{
		myWS2812();
		Delay(200000);

	}
}
int main(void)
{

	StructPMC* pmcbase	= PMC_BASE;	// Basisadresse PMC
	StructPIO* piobaseA   	= PIOA_BASE;	// Basisadresse PIOA
	StructPIO* piobaseB   	= PIOB_BASE;	// Basisadresse PIOB
	StructAIC* aicbase	= AIC_BASE;	// Basisadresse AIC

	pmcbase->PMC_PCER	= 0x6200;	//PIOA, PIOB, TIMER3 einschalten  
	
// ab hier entsprechend der Aufgabestellung ergänzen
//**************************************************
	
	piobaseB->PIO_PER = 0x18;		// SW1 und SW2 aktivieren
	piobaseB->PIO_ODR = 0x18;		// SW1 und SW2 als Input definieren
	
	
	aicbase->AIC_IDCR = 0x4000; 		//deaktivieren interrupts for PIOB
	aicbase->AIC_ICCR = 0x4000;		// Löschen der Interrupts
	aicbase->AIC_SVR[PIOB_ID] = (unsigned int)taste_irq_handler;
	aicbase->AIC_SMR[PIOB_ID] = 0x7; 
	aicbase->AIC_IECR = 0x4000;		//Aktiviere Interrupts an PIOB
	piobaseB->PIO_IER = KEY1 | KEY2; 	//enable Interrupts inerhalb der PIOB	
		
	Timer3_init();
 
			
	while(1);
	
	return 0;
}
Example #3
0
void bsp_init(void)
{
  SystemInit(); //系统时钟初始化
	Timer3_init();
	Systick_Init();
	LED_GPIO_Config();//LED引脚初始化
	Moto_Init();	//电机初始化
	I2c_Init();		//IIC初始化
	Delay_ms(50);

}
Example #4
0
void main_init(){

	dashboard_state=DASHBOARD_STATE_STARTING;
	
	ports_init();
	
	Timer0_init(TMR0_PRESCALER);
	
	CANInit();

	#if HAS_50HZ|HAS_200HZ|HAS_50HZ
	Timer1_init(TMR1_PRESCALER,FALSE);
	#endif

	#if HAS_10HZ|HAS_5HZ|HAS_4HZ
	Timer3_init(TMR3_PRESCALER,FALSE);
	#endif

	#if HAS_50HZ
	TIMER_Timer1_OCR1A_on();
	#endif

	#if HAS_25HZ
	TIMER_Timer1_OCR1B_on();
	#endif

	#if HAS_200HZ
	TIMER_Timer1_OCR1C_on();
	#endif

	#if HAS_10HZ
	TIMER_Timer3_OCR3A_on();
	#endif

	#if HAS_BUZZER
	buzzer_init();
	TIMER_Timer3_OCR3C_on();
	#endif
	
	#if HAS_LEDS
	led_init();
	#endif
	
	#if HAS_BUTTONS
	button_init();
	#endif
	
	#if HAS_DISPLAY
	display_init();
	#endif
	
	#if HAS_RADIO
	radio_init();
	#endif
	
	InitWDT();
	
	EventAddEvent(EVENT_INIT);
	
		
}
Example #5
0
int main(void)
{
    m_clockdivide(0);
    Timer3_init();//timer for setting delta t for angle value
     timer1_init();
    m_usb_init();
    m_imu_init(2, 3);
    sei();
    //for motor control-testing
    while(1)
    {
        if (update_angle) {
            
            m_imu_raw(data);
            Ax = (float)data[0]*g/accel_scale;
            Ay = (float)data[1]*g/accel_scale;
            Az = (float)data[2]*g/accel_scale;
            Gx = (float)data[3]/gyro_scale;
            Gy = (float)data[4]/gyro_scale;
            Gz = (float)data[5]/gyro_scale;
           // Mx = (float)data[6];
           // My = (float)data[7];
           // Mz = (float)data[8];
            
            
            //angle calculation
            theta_Ay = (float)Ay*90/g;
            angle = alpha*(angle_old + Gx*timestep*5)+ (1-alpha)*theta_Ay;
            angle_old = angle;
            delta_angle = angle_old + Gx*timestep*5;
            integral_angle += angle;
            //PID
            //output = (Kp*angle) + Kd*(angle - angle_old)*timestep + (Ki*integral_angle*timestep) ;
            output = Kp*angle + Kd*Gx*timestep + Ki*integral_angle*timestep;
            
            m_usb_tx_string("\t Ax: ");
            m_usb_tx_int(Ax);
            m_usb_tx_string("\t Ay: ");
            m_usb_tx_int(Ay);
            m_usb_tx_string("\t Az: ");
            m_usb_tx_int(Az);
            m_usb_tx_string("\t Gx: ");
            m_usb_tx_int(Gx);
            m_usb_tx_string("\t Gy: ");
            m_usb_tx_int(Gy);
            m_usb_tx_string("\t Gz: ");
            m_usb_tx_int(Gz);
            m_usb_tx_string("\t angle_Gx: ");
            m_usb_tx_int(angle);
            m_usb_tx_string("\t output: ");
            m_usb_tx_int(output);
     
            m_usb_tx_string("\n");
            update_angle = 0;
        }
        
        //PID Control
      // 
        
        //pwm , sensor , whell rotation spd, fbk loop, pwm generate;
        //pseudo code to control motor
        //      initialise timer for motor here, and set OCR1A,OCR1B,OCR1C value based on the speed u want to control the bot.
         //                  go slow or fast, angle less, slow, angle more faster
                
                
                if (angle > base_angle){//>
                    //move forward
                    set(DDRB,6);//set Port B pin 6 for output
                    clear(PORTB,6); //clear Port B pin 6}
                    clear(DDRB,7);
                    flag_foward = 1;
                    flag_back = 0;
                                    }
                if (angle < -base_angle){
                    //move backwards
                    set(DDRB,7);//set Port B pin 7 for output
                    clear(PORTB,7); //clear Port B pin 7
                    clear(DDRB,6);
                    flag_back = 1;
                    flag_foward = 0;
                }
        //timer1_init();//testing fr working
        timer_update();
    }
}