Exemple #1
0
main()
{
int i,n,m;

init_IPIC();
ip = (IP_STEPPER*)IPABase;
init_stepper();
init_encoder();
//
ip->AxisCtrl1.Polarity = 0; 
ip->AxisCtrl1.Source = 0;
ip->SyncCtrl = 0;
ip->intVector = 0xF0;

//programmer timer MCchip : une it toutes les TICK mili secondes
StoreByte(MCchip_Base + General_Control_R, 0x2);	/* MIEN 	*/
StoreByte(MCchip_Base+Timer1_Control_R, 3);      	/* CEN COC 	*/
StoreLong(MCchip_Base+Timer1_Compare_R, TICK*1000);	
StoreByte(MCchip_Base+Timer1_Interrupt_R, 0x11);   	/* IEN IL=1 	*/
SetHandler(((IVBR+Timer1_IRQ)*4 + VBR), it_timer );

sti();
//start
ip->Motor1.csr = START_STOP_CMD | START_MOTION | FH1_SPEED | RAMP_UP_SPEED;

while(1) stop();
}
Exemple #2
0
int main(void)
{
    int8_t byte_str[4];	    // Wird benutzt um hier ein Byte als String abzulegen

    // LCD Display intialisieren
    lcd_init();

    // Startmeldung ausgeben
    show_start_message();

    // Stepper Initialisieren
    init_stepper();

    // Motor Initialisieren
    init_motor();

    // Steursignale BYTE_READY, SYNC und SOE Initialisieren
    init_controll_signals();

    // Schreibschutz setzen
    clear_wps();

    // Timer0 --> GCR senden
    init_timer0();

    // Tasten Initialisieren
    init_keys();

    // Timer2 --> wird alle 1ms aufgerufen
    // z.B. zu Tasten entprellen
    init_timer2();

    // Meldung ausgeben, das auf SD Karte gewartet wird
    lcd_setcursor(0,2);
    lcd_string("Wait for SD-Karte...");

    // SD Karte initialisieren
    // Partition und Filesystem öffnen
    // Warten bis alles O.K. ist
    while(init_sd_card()){}

    lcd_clear();

    view_dir_entry(0,&file_entry);

#ifdef DEBUG_MODE
    lcd_setcursor(0,4);
    lcd_string("T:");

    lcd_setcursor(5,4);
    lcd_string("M:");

    lcd_setcursor(9,4);
    lcd_string("K:");

    lcd_setcursor(2,4);
    sprintf(byte_str,"%d",akt_half_track >> 1);
    lcd_string(byte_str);
#endif

    // Interrupts erlauben
    sei();

    while(1)
    {
	// Auf Steppermotor aktivität prüfen
	// und auswerten

	if(stepper_signal_r_pos != stepper_signal_w_pos)
	{
	    uint8_t stepper = stepper_signal_puffer[stepper_signal_r_pos++]>>2 | stepper_signal_puffer[stepper_signal_r_pos-1];

	    switch(stepper)
	    {
	    case 0x30: case 0x40: case 0x90: case 0xE0:
		// DEC
		stepper_dec();
		    stepper_signal_time = 0;
		    stepper_signal = 1;
		break;

	    case 0x10: case 0x60: case 0xB0: case 0xC0:
		// INC
		stepper_inc();
		    stepper_signal_time = 0;
		    stepper_signal = 1;
		break;
	    }
#ifdef DEBUG_MODE
	    lcd_setcursor(2,4);
	    lcd_string("   ");
	    lcd_setcursor(2,4);
	    sprintf(byte_str,"%d",akt_half_track >> 1);
	    lcd_string(byte_str);
#endif
	}
	else if(stepper_signal && (stepper_signal_time >= STEPPER_DELAY_TIME))
int main(void)
{
    /* Initialize Interfaces */
    if(PINB & (1<<SEL2)){   //SEL2 not installed, modeA
        init_StepDir();
        //init_pwm();
    } else {                //SEL2 installed, modeB
        init_SPI();
        init_UART(12,1);    //For 1MHz testing, change to 14.7456Mhz
        init_I2C();
    }
    //init_I2C();
    //init_SPI();
    //init_UART(95,0);    /* Run UART at 9600 baud */
    //init_StepDir();
    init_stepper();
    init_chopper();
    sei();
    int8_t motor_state = 0;
    motor_enable = WAVE;
    while(1)
    {
        if(motor_enable == FULL){
            if(desired_step_cnt < 0){   //backwards
                if(motor_state == 0) normstep4();
                if(motor_state == 2) normstep1();
                if(motor_state == 4) normstep2();
                if(motor_state == 6) normstep3();
                motor_state -= 2;
                if(motor_state < 0) motor_state = 6;
                desired_step_cnt++;
            } else if(desired_step_cnt > 0){
                if(motor_state == 0) normstep2();
                if(motor_state == 2) normstep3();
                if(motor_state == 4) normstep4();
                if(motor_state == 6) normstep1();
                motor_state += 2;
                if(motor_state > 6) motor_state = 0;
                desired_step_cnt--;
            }
        } else if(motor_enable == HALF){
            if(desired_step_cnt < 0){
                if(motor_state == 0) halfstep8();
                if(motor_state == 1) halfstep1();
                if(motor_state == 2) halfstep2();
                if(motor_state == 3) halfstep3();
                if(motor_state == 4) halfstep4();
                if(motor_state == 5) halfstep5();
                if(motor_state == 6) halfstep6();
                if(motor_state == 7) halfstep7();
                motor_state--;
                if(motor_state < 0) motor_state = 7;
                desired_step_cnt++;
            } else if(desired_step_cnt > 0){
                if(motor_state == 0) halfstep2();
                if(motor_state == 1) halfstep3();
                if(motor_state == 2) halfstep4();
                if(motor_state == 3) halfstep5();
                if(motor_state == 4) halfstep6();
                if(motor_state == 5) halfstep7();
                if(motor_state == 6) halfstep8();
                if(motor_state == 7) halfstep1();
                motor_state++;
                if(motor_state > 7) motor_state = 0;
                desired_step_cnt--;
            }            
        } else if(motor_enable == WAVE){
            if(desired_step_cnt < 0){
                if(motor_state == 1) wavestep4();
                if(motor_state == 3) wavestep1();
                if(motor_state == 5) wavestep2();
                if(motor_state == 7) wavestep3();
                motor_state -= 2;
                if(motor_state < 1) motor_state = 7;
                desired_step_cnt++;
            } else if(desired_step_cnt > 0){
                if(motor_state == 1) wavestep2();
                if(motor_state == 3) wavestep3();
                if(motor_state == 5) wavestep4();
                if(motor_state == 7) wavestep1();
                motor_state += 2;
                if(motor_state > 7) motor_state = 1;
                desired_step_cnt--;
            }
        }
        _delay_ms(100);//Change according to speed input
//        normstep1();
//        _delay_ms(100);
//        normstep2();
//        _delay_ms(100);
//        normstep3();
//        _delay_ms(100);
//        normstep4(); 
//        _delay_ms(100);          
//        halfstep1();
//        _delay_ms(100);
//        halfstep2();
//        _delay_ms(100);
//        halfstep3();
//        _delay_ms(100);
//        halfstep4();
//        _delay_ms(100);
//        halfstep5();
//        _delay_ms(100);
//        halfstep6();
//        _delay_ms(100);
//        halfstep7();
//        _delay_ms(100);
//        halfstep8();
//        _delay_ms(100);
//        wavestep1();
//        _delay_ms(100);
//        wavestep2();
//        _delay_ms(100);
//        wavestep3();
//        _delay_ms(100);
//        wavestep4();
//        _delay_ms(100);
    }
    return 0;
}
Exemple #4
0
int main(int argc, char** argv)
{
	//close server and RedPitaya if CTRL+C
	signal(SIGINT, signal_callback_handler);

	//client TCP initialisation
	unsigned int MaxClient=5;
	sock=0;

	init_TCP_server(&sock, PORT, &client_list, MaxClient);
	launch_server(&sock, &client_list);

	//RedPitaya and settings initialisation
	init_RP();
	uint32_t buffer_length=0;
	float  level0=0.80, levelf=1.0;
	int delay;

	float *buffer_float=NULL;
	char *buffer_char=NULL;

	set_acquisition(dec);
	init_ramp(1, level0, x0, levelf, xf);
	init_variable(x0, xf, dec, &buffer_length, &delay);
	printf("length = %i\n",(int)buffer_length);

	buffer_float=(float *)malloc(((int)buffer_length)*sizeof(float));
	buffer_char=(char *)malloc(((int)buffer_length+1)*sizeof(char));

	//stepper initialisation
	init_stepper(&stepper);
	set_mode(&stepper, full_16);
	double angle=0.0, speed=3.0;
	angle=sector/((double)Nline);
	init_position(&stepper, 160.0-sector/2.0);

	int i=0;

	while(1)
	{
		for (i=0 ; i<Nline ; i++)
		{
			move(&stepper, &angle, &speed, sens1);
			trigg(delay);
			pulse();
			on_trigger_acquisition(buffer_float, buffer_length);
			send_via_tcp(i+1, buffer_char, buffer_float, buffer_length, &client_list);
			pulse();
		}
		for (i=Nline ; i>0 ; i--)
		{
			move(&stepper, &angle, &speed, sens2);
			trigg(delay);
			pulse();
			on_trigger_acquisition(buffer_float, buffer_length);
			send_via_tcp(i, buffer_char, buffer_float, buffer_length, &client_list);
			pulse();
		}
		
	}

	free(buffer_float);
	free(buffer_char);
	end_ramp();
	disable_stepper(&stepper);
	printf("Process done\n");

	//close TCP client
	close_TCP_client(&sock);
	//close RedPitaya
	close_RP();

	return 0;
}
Exemple #5
0
/******************************************************************
 * 			Main-function
 */
int main(void) {

	/**************************************
	 * 	Set the clock to run at 80 MHz
	 */
	SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

	/**************************************
	 * 	Enable the floating-point-unit
	 */
	FPUEnable();
	// We also want Lazystacking, so enable that too
	FPULazyStackingEnable();
	// We also want to put numbers close to zero to zero
	FPUFlushToZeroModeSet(FPU_FLUSH_TO_ZERO_EN);

	/**************************************
	 * 	Init variables
	 */
	uint16_t mapData[MAP_DATA_SIZE];
	uint8_t stepDir = 0;

	/**************************************
	 * 	Init peripherals used
	 */
	bluetooth_init();
	init_stepper();							// Init the GPIOs used for the stepper and loading LED
	InitI2C1();								// Init the communication with the lidar-unit through I2C
	InitPWM();
	setupTimers();

	/**************************************
	 * 	State 2
	 */
	// Disable the timers that are used
	disableTimer(TIMER1_BASE);
	disableTimer(TIMER2_BASE);

	// Enable all interrupts
	IntMasterEnable();
	/**************************************
	 * 	State 3
	 */
	// Indicate we should start with a scan regardless of what other things we have already got
	// from UART-interrupt
	// This means setting the appropriate bit in the status vector
	stat_vec |= TAKE_MEAS;

	/**************************************
	 * 	State 4
	 */
	// Contains main-loop where decisions should be made
	for ( ; ; ) {
		/**********************************
		 * 	Decision tree
		 */
		// Highest priority case first


		// Check both interrupts at each iteration in the loop
		if ( int_vec & UART_INT ) {
			// Reset the indication
			int_vec &= ~UART_INT;

			// Remove drive-stop flag to enable movement
			stat_vec &= ~DRIVE_STOP;

			// Init data array
			uint8_t dataArr[MAX_UART_MSG_SIZE];

			// Collect the message
			if ( readUARTMessage(dataArr, MAX_UART_MSG_SIZE) < SUCCESS ) {
				// If we have recieved more data than fits in the vector we should simply
				// go in here again and grab data
				int_vec |= UART_INT;
			}
			// We have gathered a message
			// and now need to determine what the message is
			parseMsg(dataArr, MAX_UART_MSG_SIZE);
		}
		// Checking drive (movement) interrupt
		if ( int_vec & TIMER2_INT ) {
			int_vec &= ~TIMER2_INT;
			// Disable TIMER2
			disableTimer(TIMER2_BASE);
			// Set drive-stop in status vector
			stat_vec |= DRIVE_STOP;
		}
		// Checking measure interrupt
		if ( int_vec & TIMER1_INT ) {
			int_vec &= ~TIMER1_INT;
			// Disable TIMER1
			disableTimer(TIMER1_BASE);

			// Take reading from LIDAR
			mapData[stepCount++] = readLidar();
			SysCtlDelay(2000);

			// Take step
			// Note: We need to take double meas at randvillkor (100) !!!!!
			if ( stepCount > 0 && stepCount < 100 ) {
				stepDir = 1;
			}
			else if ( stepCount >= 100 && stepCount < 200) {
				stepDir = 0;
			}
			else {
				stepDir = 1;
				stepCount = 0;

				// Reset busy-flag
				stat_vec &= ~TAKE_MEAS;
			}
			step = takeStep(step, stepDir);

			// Request reading from LIDAR
			reqLidarMeas();

			if ( stat_vec & TAKE_MEAS ) {
				// Restart TIMER1
				enableTimer(TIMER1_BASE, (SYSCLOCK / MEASUREMENT_DELAY));
			}
			else {
				sendUARTDataVector(mapData, MAP_DATA_SIZE);
				stat_vec &= ~BUSY;
			}
		}

		// Check the drive_stop flag, which always should be set unless we should move
		if ( stat_vec & DRIVE_STOP ) {
			// Stop all movement
			SetPWMLevel(0,0);
			halt();

			// MAKE SURE all drive-flags are not set
			stat_vec &= ~(DRIVE_F | DRIVE_L | DRIVE_R | DRIVE_LL | BUSY);
		}
		// Should we drive?
		else if ( stat_vec & DRIVE ) {
			// Remove drive flag
			stat_vec &= ~DRIVE;
			// Increase PWM
			increase_PWM(0,MAX_FORWARD_SPEED,0,MAX_FORWARD_SPEED);
			if ( stat_vec & DRIVE_F ) {
				enableTimer(TIMER2_BASE, DRIVE_FORWARD_TIME);
			}
			else if ( stat_vec & DRIVE_LL ) {
				enableTimer(TIMER2_BASE, DRIVE_TURN_180_TIME);
			}
			else {
				enableTimer(TIMER2_BASE, DRIVE_TURN_TIME);
			}
		}
		if ( !(stat_vec & BUSY) ) {
			// Tasks
			switch ( stat_vec ) {
				case ((uint8_t)DRIVE_F) :
					// Call drive function
					go_forward();
					// Set the drive flag & BUSY
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)DRIVE_L) :
					// Call drive-left function
					go_left();
					// Set the drive flag
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)DRIVE_R) :
					// Call drive-right function
					go_right();
					// Set the drive flag
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)DRIVE_LL) :
					// Call turn 180-degrees function
					go_back();
					// Set the drive flag
					stat_vec |= DRIVE | BUSY;
					break;
				case ((uint8_t)TAKE_MEAS) :
					// Request reading from LIDAR
					reqLidarMeas();
					// Start TIMER1
					enableTimer(TIMER1_BASE, (SYSCLOCK / MEASUREMENT_DELAY)); // if sysclock = 1 s, 1/120 = 8.3 ms
					// We are busy
					stat_vec |= BUSY;
					break;

				default:
					break;
			}
		}
	}
}