Ejemplo n.º 1
0
int main(void){
    OS_Init();
    PortF_Init();
		Timer5_Init();
//    SW1_Init(&SW1Press,3);
//    SW2_Init(&SW2Press,3);
    PC6_Init(&PC6High,3);
    PC7_Init(&PC7High,3);
    OS_AddThread(&IdleTask, 128, 7);
    OS_Launch(TIMESLICE);
    return 0;
}
Ejemplo n.º 2
0
/*******************************************************
* MAIN function, just setup some inits and loops
* "soft" real-time event handlers, defined hereafter
********************************************************/
int main(void)
{    
// configuro l'oscillatore interno che mi fornisce Tcy
// Fosc = Fin (M/(N1*N2))
// FCY = Fosc/2
    PLLFBD = 39; 			// M = 40
    CLKDIVbits.PLLPOST=0; 	// N2 = 2
    CLKDIVbits.PLLPRE=0; 	// N1 = 2

    RCONbits.SWDTEN = 0;	//disabilito il watchdog 

	DataEEInit();

    //Init Peripheral Pin Selection (QEI and UART)
    PPS_Init();
   
    control_flags.first_scan = 1;
    slow_ticks_limit = SLOW_RATE * (FCY_PWM / 1000) - 1 ;
    medium_ticks_limit = MEDIUM_RATE * (FCY_PWM / 1000) - 1;
    
    mposition1 = zero_pos1;//parto dalla posizione iniziale 90 90 90
	mposition2 = zero_pos2;
	mposition3 = zero_pos3;

	/*mtheta1 = 0;
	mtheta2 = 0;
	mtheta3 = 0;

	x_cart = 0;
	y_cart = 0;
	z_cart = 0;*/

	coordinates_actual.x = 0;
	coordinates_actual.y = 0;
	coordinates_actual.z = 0;

	coordinates_temp.x = 0;
	coordinates_temp.y = 0;
	coordinates_temp.z = 0;

	angleJoints_actual.theta1 = 0;
	angleJoints_actual.theta2 = 0;
	angleJoints_actual.theta3 = 0;

	angleJoints_temp.theta1 = 0;
	angleJoints_temp.theta2 = 0;
	angleJoints_temp.theta3 = 0;

	update_params();
    
    direction_flags_prev = direction_flags.word;

     // UARTs init
     // no need to set TRISx, they are "Module controlled"
    UART1_Init();  

    // Setup control pins and PWM module,
    // which is needed also to schedule "soft"
    // real-time tasks w/PWM interrupt tick counts
    DIR1 = direction_flags.motor1_dir;//0;
    DIR2 = direction_flags.motor2_dir;//1; 
    DIR3 = direction_flags.motor3_dir;
             
    //BRAKE1 = 0;
    //BRAKE2 = 0; 

    DIR1_TRIS = OUTPUT;
    DIR2_TRIS = OUTPUT;
    DIR3_TRIS = OUTPUT;
    //BRAKE1_TRIS = OUTPUT;
    //BRAKE2_TRIS = OUTPUT;
    
    CURRSENSE1_TRIS = INPUT;
    CURRSENSE2_TRIS = INPUT;
    CURRSENSE3_TRIS = INPUT;
    
    PWM_Init();
    
    // MUST SETUP ALSO ANALOG PINS AS INPUTS
    AN0_TRIS = INPUT;
    AN1_TRIS = INPUT;
    AN2_TRIS = INPUT;
    
    ADC_Init();
    DMA0_Init();
    
    // SETUP ENCODER INPUTS
    // QEI inputs are "module controlled"
    // -> no need to set TRISx
    QEI1_Init();
    QEI2_Init();
    
    // Timers used to acquire Encoder 3
    // corresponding PINS set as inputs
    T1CK_TRIS = INPUT;
    T4CK_TRIS = INPUT;
    Timer1_Init();
	Timer2_Init();
    Timer4_Init();
	
    // Timer5 used to schedule POSITION loops
    Timer5_Init();

	//Input capture
	IC1_Init();
	IC2_Init();

    // TEST PIN
    TEST_PIN_TRIS = OUTPUT;
    TEST_PIN = FALSE;

    while(1)//a ciclo infinito ripeto queste 2 routine
        {	            
			medium_event_handler();
            slow_event_handler();
        }
    
    return 0; //code should never get here
}// END MAIN()
Ejemplo n.º 3
0
void smartbusInit(uint32_t sbPeriod, uint8_t sbIdent, uint8_t sbPrio) {
    sbPriority = sbPrio;
    sbID = sbIdent;
    Timer5_Init(&tickTask, sbPriority, sbPeriod);
    pinsInit(&PC6High, &PC7High, sbPriority);
}