Exemplo n.º 1
0
  void Laser::Init() {

    // Initialize timers for laser intensity control
    #if LASER_CONTROL == 1

      #if IS_TIMER_3_PWR
        timer3_init(LASER_PWR_PIN);
      #elif IS_TIMER_4_PWR
        timer4_init(LASER_PWR_PIN);
      #endif

    #elif LASER_CONTROL == 2

      #if IS_TIMER_3_PWM
        timer3_init(LASER_PWM_PIN);
      #elif IS_TIMER_4_PWM
        timer4_init(LASER_PWM_PIN);
      #endif

    #endif

    #if ENABLED(LASER_PERIPHERALS)
      OUT_WRITE(LASER_PERIPHERALS_PIN, HIGH);         // Laser peripherals are active LOW, so preset the pin
      OUT_WRITE(LASER_PERIPHERALS_STATUS_PIN, HIGH);  // Set the peripherals status pin to pull-up.
    #endif

    #if LASER_CONTROL == 2
      OUT_WRITE(LASER_PWR_PIN, LASER_UNARM);  // Laser FIRING is active LOW, so preset the pin
    #endif

    // initialize state to some sane defaults
    laser.intensity = 100.0;
    laser.ppm = 0.0;
    laser.duration = 0;
    laser.status = LASER_OFF;
    laser.firing = LASER_ON;
    laser.mode = CONTINUOUS;
    laser.last_firing = 0;
    laser.diagnostics = false;
    laser.time = 0;

    #if ENABLED(LASER_RASTER)
      laser.raster_aspect_ratio = LASER_RASTER_ASPECT_RATIO;
      laser.raster_mm_per_pulse = LASER_RASTER_MM_PER_PULSE;
      laser.raster_direction = 1;
    #endif // LASER_RASTER

    laser.extinguish();

  }
Exemplo n.º 2
0
/*==================================================================================
* 函 数 名: Set_System
* 参    数: None
* 功能描述:  初始化系统
* 返 回 值: None
* 备    注: 
* 作    者: gaodb
* 创建时间: 2012.10
==================================================================================*/
void Set_System(void)
{  
    rcc_init();
		
    peri_clk_init();  
		
  	NVIC_Configuration();  
  	
    pins_init();  
    
    systick_init();
		
    timer2_init();
    timer4_init(); 
    
    RAY12_ADC_Init();
    
    LCD_Config();    
    DispInit();
    
    uart1_init(BAUD_RATE_57600);	
		uart2_init(BAUD_RATE_57600);
		
		dac1_init();
		
    sys_variable_init();
}
Exemplo n.º 3
0
uint8_t module_system_start()
{
	s_module_status = MODULE_START;
	timer4_init(1000, 1, at_fifo_check);
	timer4_start();
	return s_module_status;
}
Exemplo n.º 4
0
void start_timer4(void)
{
	cli(); //Clears the global interrupts
	timer4_init();
	TIMSK4 = 0x01; //timer4 overflow interrupt enable
	sei();   //Enables the global interrupts

}
    /*!
	 initialize all devices. call all other initialization function
    */
void init_devices (void)
{
	cli(); //Clears the global interrupts
	port_init();
	adc_init();
	uart3_init();
	timer5_init();
	timer4_init();
	TCCR4B = 0x00;
	TIMSK4 = 0x01; //timer4 overflow interrupt enable
	TIMSK3 = 0x01;
	sei();   //Enables the global interrupts
}
//Function to initialize all the devices
void init_devices()
{
 cli(); //Clears the global interrupt
 port_init();  //Initializes all the ports
 left_position_encoder_interrupt_init();
 right_position_encoder_interrupt_init();
 timer4_init();
 adc_init();
 timer5_init();
 store_init();
 uart2_init();
 TIMSK4 = 0x01;
 sei();   // Enables the global interrupt 
}
Exemplo n.º 7
0
void PD1_INT_Handler(void)
{
//      volatile  U32 time, echo_time;
        if(trig_num2==0)
        {
        timer4_init();
        trig_num2 ++;
        *(RP)(GPIO_PORTD_INTLEL) |= (0x1<<1);//change PA1 to  trailing edge下降沿触发
        }
        else
        {
        time2 = *(RP)(TIMER_T4CCR);
        }
        *(RP)(GPIO_PORTD_INTCLR) |= (0x1<<1);//clear PA1 interrupt
}
Exemplo n.º 8
0
void laser_init()
{
  // Initialize timers for laser intensity control
  #if LASER_CONTROL == 1
    if (LASER_FIRING_PIN == 2 || LASER_FIRING_PIN == 3 || LASER_FIRING_PIN == 5) timer3_init(LASER_FIRING_PIN);
    if (LASER_FIRING_PIN == 6 || LASER_FIRING_PIN == 7 || LASER_FIRING_PIN == 8) timer4_init(LASER_FIRING_PIN);
  #endif
  #if LASER_CONTROL == 2
    if (LASER_INTENSITY_PIN == 2 || LASER_INTENSITY_PIN == 3 || LASER_INTENSITY_PIN == 5) timer3_init(LASER_INTENSITY_PIN);
    if (LASER_INTENSITY_PIN == 6 || LASER_INTENSITY_PIN == 7 || LASER_INTENSITY_PIN == 8) timer4_init(LASER_INTENSITY_PIN);
  #endif

  #ifdef LASER_PERIPHERALS
    digitalWrite(LASER_PERIPHERALS_PIN, HIGH);  // Laser peripherals are active LOW, so preset the pin
    pinMode(LASER_PERIPHERALS_PIN, OUTPUT);

    digitalWrite(LASER_PERIPHERALS_STATUS_PIN, HIGH);  // Set the peripherals status pin to pull-up.
    pinMode(LASER_PERIPHERALS_STATUS_PIN, INPUT);
  #endif // LASER_PERIPHERALS

  // initialize state to some sane defaults
  laser.intensity = 100.0;
  laser.ppm = 0.0;
  laser.duration = 0;
  laser.status = LASER_OFF;
  laser.firing = LASER_OFF;
  laser.mode = CONTINUOUS;
  laser.last_firing = 0;
  laser.diagnostics = false;
  laser.time = 0;
  #ifdef LASER_RASTER
    laser.raster_aspect_ratio = LASER_RASTER_ASPECT_RATIO;
    laser.raster_mm_per_pulse = LASER_RASTER_MM_PER_PULSE;
    laser.raster_direction = 1;
  #endif // LASER_RASTER
  #ifdef MUVE_Z_PEEL
    laser.peel_distance = 2.0;
    laser.peel_speed = 2.0;
    laser.peel_pause = 0.0;
  #endif // MUVE_Z_PEEL
  
  laser_extinguish();
}
void laser_init()
{
  #if LASER_CONTROL == 1
	timer3_init();
  #endif // LASER_CONTROL ==1
  #if LASER_CONTROL == 2
    timer3_init();
    timer4_init();
  #endif // LASER_CONTROL == 2

  // Engage the pullup resistor for TTL laser controllers which don't turn off entirely without it.
  pinMode(LASER_FIRING_PIN, OUTPUT);

  #ifdef LASER_PERIPHERALS
  digitalWrite(LASER_PERIPHERALS_PIN, HIGH);  // Laser peripherals are active LOW, so preset the pin
  pinMode(LASER_PERIPHERALS_PIN, OUTPUT);

  digitalWrite(LASER_PERIPHERALS_STATUS_PIN, HIGH);  // Set the peripherals status pin to pull-up.
  pinMode(LASER_PERIPHERALS_STATUS_PIN, INPUT);
  #endif // LASER_PERIPHERALS

  // initialize state to some sane defaults
  laser.intensity = 100.0;
  laser.ppm = 0.0;
  laser.duration = 0;
  laser.status = LASER_OFF;
  laser.firing = LASER_OFF;
  laser.mode = CONTINUOUS;
  laser.last_firing = 0;
  laser.diagnostics = false;
  laser.time = 0;
  #ifdef LASER_RASTER
    laser.raster_aspect_ratio = LASER_RASTER_ASPECT_RATIO;
    laser.raster_mm_per_pulse = LASER_RASTER_MM_PER_PULSE;
    laser.raster_direction = 1;
  #endif // LASER_RASTER
  #ifdef MUVE_Z_PEEL
    laser.peel_distance = 2.0;
    laser.peel_speed = 2.0;
    laser.peel_pause = 0.0;
  #endif // MUVE_Z_PEEL
}
Exemplo n.º 10
0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// proceso principal del juego que recibe el tablero, y las direcciones en las que indica el jugador la fila y la columna y la se?al de ready que indica que se han actualizado fila y columna
void reversi6(char tablero[][TAM_TABLERO])  // en esta versi?n el usuario lleva negras y el ordenador blancas
{   // no se comprueba que el jugador mueva bien. S?lo que el ordenador realice un movimiento correcto.
  int done; // nos indica si se ha conseguido mover
  int move = 0; //indica que el jugador ha movido;
  tiempo = 0; // inicializa el valor del tiempo transcurrido a 0
  display_tiempo(); // mostrar mensaje de tiempo
  display_actualizar_tiempo(tiempo); // mostrar el valor del tiempo
  display_mensaje_ayuda(); // mostrar mensaje de ayuda
  int fin = 0;// fin se pone a 1 si el jugador no ha podido mover (ha introducido un valor de movimiento con alg?n 6) y luego el ordenador tampoco puede.
  int blancas = 2, negras = 2; // se usan para contar el n?mero de fichas de cada color.
  char f,c; // fila y columna elegidas por el programa para su movimiento

  init_table(tablero);
  actualizar_lcd(tablero, blancas, negras);
  timer4_init(); // comienza el contador de tiempo transcurrido
  while (fin == 0) {
    move = 0;
    esperar_mov();
    if (((fila) != TAM_TABLERO) && ((columna) != TAM_TABLERO)) { // si la fila o columna son 8 asumimos que el jugador no puede mover
        tablero[fila][columna] = 2;
        actualizar_tablero(fila, columna, 2, tablero);
        contar(&blancas, &negras, tablero);
        actualizar_lcd(tablero, blancas, negras);
        actualizar_candidatos(fila, columna);
        move = 1;
    }
    done = elegir_mov(&f, &c, tabla_valor, tablero); //escribe el movimiento en las variables globales fila columna
    if (done == -1 && move == 0){
       fin = 1;
    }
    else {
        tablero[f][c] = 1;
        actualizar_tablero(f, c, 1, tablero);
        contar(&blancas, &negras, tablero);
        actualizar_lcd(tablero, blancas, negras);
        actualizar_candidatos(f, c);
    }
  }
  timer4_stop(); // parar reloj del tiempo transcurrido
  display_final(blancas,negras); // mostrar resultado final
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
int i=0;
int h=0;
int bupi=0;


cli();
memset(command,'$',58);
init();
timer0_init();
timer1_init();
timer3_init();
timer4_init();
timer5_init();
//lcd_init();
//lcd_string("Welcome");
//lcd_move(0,1);
//lcdconfig();
//lcd_string("Give me a code:");
//lcd_move(0,2);
UART_init();
//adc_init();
//lcdsenddata('F');
//lcd_num(123456);
_delay_ms(1500);
sei();

	while(1)
	{
//-------------------------------------------------scan for input	
		while(mode==0)
		{
			while(1)//scan line
			{				

				if(command[comm]=USART_Receive())
				{
					if((command[comm]==13||command[comm]=='\n'||command[comm]==59)&&(comm<59))
					{
					break;
					}

					if(echo==1)
					{
					//USART_Transmit('[');
				//	USART_Transmit(comm+48);
				//	USART_Transmit(']');
					USART_Transmit(command[comm]);
					}

					comm++;

				}
				else
				{
				}

			
			}
			mode=1;
		
			if(echo==1)
			{
			USART_String_Transmit("\nTransition to parsing.");
			}
		
		}
		


//-------------------------------------------------parse commands
		while(mode==1)//parse commands
		{
			for(i=0;i<comm;i++)//cycling i till \n-1
			{

				if(command[i]=='N'&&command[i+1]>47&&command[i+1]<58)//GET LINE NUMBER
				{
					if(echo)
					{
					USART_String_Transmit("\n Getting line number.");
					}

					temp_line_number=fetchlong(command,i,'N');
				}				

				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='5')//GET EXTRUDER TEMP
				{

				}
				

				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='4')//SET EXTRUDER TEMP FAST SXXX
				{
	
				}					

				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='9')//SET EXTRUDER TEMP AND WAIT RXXX
				{
				
				}

				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='4'&&command[i+3]=='0')//SET BED TEMP FAST SXXX
				{
				
				}
				

				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='9'&&command[i+3]=='0')//WAIT FOR BED TEMP TO HIT RXXX
				{
				
				}

				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='7')//FAN OFF
				{
				
				}
				
				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='6')//FAN ON WITH FAN SPEED S255MAX
				{
				
				}

				
				

				if(command[i]=='M'&&command[i+1]=='8'&&command[i+2]=='2'&&command[i+3]==' ')//EXTRUDER TO ABSOLUTE MODE
				{
				
				}
				

				
				if(command[i]=='G'&&command[i+1]=='2'&&command[i+2]=='1'&&command[i+3]==' ')//METRIC VALUES
				{
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='9'&&command[i+2]=='0'&&command[i+3]==' ')//ABSOLUTE POSITIONING
				{
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='9'&&command[i+2]=='2'&&command[i+3]==' ')//ZERO EXTRUDED LENGTH WITH E0 otherwise set origin?
				{
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='0'&&command[i+2]==' ')//MOVE WITHOUT EXTUSION
				{
				if(echo)
				{
				USART_String_Transmit("\nG0 command.");
				}
				line_engine(double_scan_x,double_scan_y,double_scan_z,double_scan_e,i);
				if((echo==1)&&(xroll==1)&&(yroll=1))
				{
				USART_String_Transmit("\n Xroll=1");
				USART_String_Transmit("\n Yroll=1");
				}
				mode==2;
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='1'&&command[i+2]==' ')//MOVE WITH EXTRUSION
				{



				}

				
				
				if(command[i]=='Q'&&command[i+1]=='1')//MOTOR TEST					{
				{
					if(echo)
					{
					USART_String_Transmit("\n Motor test on.");
					//xroll=1;
					yroll=1;
					//testval=(threefetchdouble(command,i,'E')/0.01)*16;
					}
				}

				
				
				if(command[i]=='Q'&&command[i+1]=='0')//MOTOR TEST
				{
					if(echo)
					{
					USART_String_Transmit("\n Motor test off.");
					}
					//xroll=0;
					yroll=0;
				}
				

				
			}
			mode=2;
				if(echo)
				{
				USART_String_Transmit("\nTransition to set outputs.");
				}
			


		}	



//-------------------------------------------------setting outputs
		while(mode==2)
		{
			while(zroll==1||eroll==1||xroll==1||yroll==1)
			{
				if(USART_Receive()=='.')
				{
				zroll=0;
				eroll=0;
				xroll=0;
				yroll=0;
				
				USART_String_Transmit("\nSW Emergency stopped, please reset!");
			//	PINK|=0b00000001;
			//	PINA|=0b00000100;
			//	PINF|=0b00000100;
			//	PIND|=0b10000000;

				}
			}

			if(zroll==0&&eroll==0&&xroll==0&&yroll==0)
			{
				if(echo)
				{
				USART_String_Transmit("\nTransition to mode 3, reseting parameters.");
				}

				mode=3;
			}


		}



//-------------------------------------------------clear things
		while(mode==3)
		{
		cli();

		memset(command,'$',58);
		comm=0;
		i=0;
		double_scan_x=-1.0;
		double_scan_y=-1.0;
		double_scan_z=-1.0;
		double_scan_e=-1.0;
		
			if(echo)
			{
			USART_String_Transmit("\nParameters reseted returning to scanning mode");
			}

		USART_String_Transmit("\n\rok");
		
		sei();

		mode=0;
		}



		
//-------------------------------------------------
		while(mode==4)
		{

		}		

	}



return 0;
}
Exemplo n.º 12
0
//--------------------------------------------------------------------
// Main Init function
//--------------------------------------------------------------------
void init(void)
{
  uint16_t dummy = 0;
  int16_t ret;

  LED_ERROR_ON;

  //enable AD converter
  adc_init();

  ResetImu();

  //enable communication to PC over USB
  HostInit();
  
  //enable communication to the bus
  BusInit();
  
  //enable communications with gps
  GpsInit();
  
  InitLeds();
  
  XbeeInit();

  //timer for sending out estop status
  timer3_init();
  //timer3_set_overflow_callback(SendEstopStatus);
  timer3_set_overflow_callback(globalTimerOverflow);  

  timer4_init();
  timer4_set_compa_callback(Rs485ResponseTimeout);
  timer4_disable_compa_callback();

  timer1_init();
  timer1_set_compa_callback(EncodersRequestFcn);

  //generate the request packets:
  encoderRequestRawPacketSize = DynamixelPacketWrapData(MMC_MOTOR_CONTROLLER_DEVICE_ID,
                          MMC_MOTOR_CONTROLLER_ENCODERS_REQUEST,
                          &dummy,sizeof(dummy),
                          encoderRequestRawPacket,
                          encoderRequestRawPacketMaxSize);

  Servo1Init(GlobalTimerGetTime());


  //buzzer port
  BUZZER_DDR |= _BV(BUZZER_PIN);

  //enable global interrupts 
  sei();
  
  DDRL |= _BV(PL3) | _BV(PL5) | _BV(PL4);
  PORTL |= _BV(PL3) | _BV(PL5) | _BV(PL4);
  //PORTL |= _BV(PL3);
  
  /*
  TCCR5A |= _BV(WGM51) | _BV(WGM50);
  TCCR5B |= _BV(WGM52) | _BV(WGM53);
  OCR5A = 2000;
  TCCR5A |= _BV(COM5A0);
  TCCR5A |= _BV(COM5B0);
  TCCR5A |= _BV(COM5C0);
  */

  LED_ERROR_OFF;
}
Exemplo n.º 13
0
/*
 * @brief radiotimer_init  Initialize the radio timer 
 *        with 32.768KHz input clock 
 *
 * @param None
 *
 */
void radiotimer_init(void)
{
    memset(&radiotimer_vars,0,sizeof(radiotimer_vars_t));
    timer4_init();
	tc4_irq_enable();	
}