Esempio n. 1
0
void MOTOR_Initialize ( void )
{
    /* Place the App state machine in its initial state. */
    motorData.state = MOTOR_STATE_INIT;
        /* Place the App state machine in its initial state. */
	motorData.RxSeqNum = 0;
	motorData.TxSeqNum = 0;
	motorData.LEncode = 0;
	motorData.REncode = 0;
	motorData.REncodeTotal = 0;
	motorData.LEncodeTotal = 0;
	motorData.LDist = 0;
	motorData.RDist = 0;
	motorData.LSet = 0;
	motorData.RSet = 0;
	motorData.LMes = 0;
	motorData.RMes = 0;
	motorData.LAvg = 0.0;
	motorData.RAvg = 0;
	motorData.LOCSet = 0;
	motorData.ROCSet = 0;
	motorData.ratio = 0;
	motorData.RTestTick = 0;
	motorData.LTestTick = 0;
	motorData.n = 0;
	//motorData.rxMessage.command = 0;
	//motorData.rxMessage.duration = 0;
	motorData.theQueue = xQueueCreate(MOTORQUEUELENGTH, sizeof(MOTOR_MESSAGE)); //sizeof(appData.rxMessage));
	if(motorData.theQueue == 0)
	{
		crash("E:Create Motor msgQ");
		//failed to create queue
	}
	PLIB_PORTS_DirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_G, 0x0002);
	PLIB_PORTS_DirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_D, 0x0003);
	PLIB_PORTS_DirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_C, 0x4000);
	PLIB_PORTS_PinWrite (PORTS_ID_0, PORT_CHANNEL_D, PORTS_BIT_POS_1, 0);
	PLIB_PORTS_PinWrite (PORTS_ID_0, PORT_CHANNEL_D, PORTS_BIT_POS_0, 0);

	DRV_OC1_Initialize();
	DRV_OC0_Initialize();
	//DRV_OC1_Enable();
	//DRV_OC0_Enable();	//same thing as start
	DRV_OC1_Stop();
	DRV_OC0_Stop();
	//25.6 us per count
	//count to 200 = 51.2ms per rollover
	DRV_TMR0_Initialize();	//OC Timer
	DRV_TMR1_Initialize();	//IC Timer
	DRV_TMR2_Initialize();	//duration Timer
	DRV_TMR0_CounterClear();
	DRV_TMR1_CounterClear();
	DRV_TMR2_CounterClear();
	DRV_TMR0_Stop();	//pwm timer
	DRV_TMR1_Stop();	//encoder timer 5ms
	DRV_TMR2_Stop();	//duration timer 1ms
	
//	theTimerInit(52);
}
Esempio n. 2
0
void SYS_Initialize ( void* data )
{
    /* Core Processor Initialization */
    SYS_CLK_Initialize( NULL );
    sysObj.sysDevcon = SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)&sysDevconInit);
    SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet());
    SYS_DEVCON_JTAGDisable();
    SYS_PORTS_Initialize();

    /* Initialize Drivers */
    /*Initialize TMR0 */
    DRV_TMR0_Initialize();
    /*Initialize TMR1 */
    DRV_TMR1_Initialize();
    /*Initialize TMR2 */
    DRV_TMR2_Initialize();
    /*Initialize TMR3 */
    DRV_TMR3_Initialize();

     DRV_USART0_Initialize();
    DRV_USART1_Initialize();


    /*Initialize OC0 */
    DRV_OC0_Initialize();

    /*Initialize OC1 */
    DRV_OC1_Initialize();

    /* Initialize System Services */
    SYS_INT_Initialize();  

    /*Setup the INT_SOURCE_EXTERNAL_1 and Enable it*/
    SYS_INT_VectorPrioritySet(INT_VECTOR_INT1, INT_PRIORITY_LEVEL1);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_INT1, INT_SUBPRIORITY_LEVEL0);
    SYS_INT_ExternalInterruptTriggerSet(INT_EXTERNAL_INT_SOURCE1,INT_EDGE_TRIGGER_RISING);
    SYS_INT_SourceEnable(INT_SOURCE_EXTERNAL_1);

    /*Setup the INT_SOURCE_EXTERNAL_2 and Enable it*/
    SYS_INT_VectorPrioritySet(INT_VECTOR_INT2, INT_PRIORITY_LEVEL1);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_INT2, INT_SUBPRIORITY_LEVEL0);
    SYS_INT_ExternalInterruptTriggerSet(INT_EXTERNAL_INT_SOURCE2,INT_EDGE_TRIGGER_RISING);
    SYS_INT_SourceEnable(INT_SOURCE_EXTERNAL_2);





    /* Initialize Middleware */
	initDebugU();

    /* Initialize the Application */
    COMMUNICATION_Initialize();
    MOTOR_Initialize();
}
Esempio n. 3
0
void SYS_Initialize ( void* data )
{
    /* Core Processor Initialization */
    SYS_CLK_Initialize( NULL );
    sysObj.sysDevcon = SYS_DEVCON_Initialize(SYS_DEVCON_INDEX_0, (SYS_MODULE_INIT*)&sysDevconInit);
    SYS_DEVCON_PerformanceConfig(SYS_CLK_SystemFrequencyGet());
    SYS_DEVCON_JTAGDisable();
    SYS_PORTS_Initialize();

    /* Initialize Drivers */
    /*Initialize TMR0 */
    DRV_TMR0_Initialize();
    /*Initialize TMR1 */
    DRV_TMR1_Initialize();
    /*Initialize TMR2 */
    DRV_TMR2_Initialize();
 
     sysObj.drvUsart0 = DRV_USART_Initialize(DRV_USART_INDEX_0, (SYS_MODULE_INIT *)&drvUsart0InitData);
    SYS_INT_VectorPrioritySet(INT_VECTOR_UART1, INT_PRIORITY_LEVEL3);
    SYS_INT_VectorSubprioritySet(INT_VECTOR_UART1, INT_SUBPRIORITY_LEVEL1);


    /*Initialize OC0 */
    DRV_OC0_Initialize();

    /*Initialize OC1 */
    DRV_OC1_Initialize();

    /* Initialize System Services */
    SYS_INT_Initialize();  

    /* Initialize Middleware */

    /* Initialize the Application */
    APP_Initialize();
}
Esempio n. 4
0
File: mcc.c Progetto: kunal15595/pic
void SYSTEM_Initialize(void)
{
    OSCILLATOR_Initialize();
    PIN_MANAGER_Initialize();
    DRV_TMR1_Initialize();
}