Example #1
0
File: main.c Project: eeshanl/ee472
// This function initializes all hardware used by our system.
void InitializeHardware() {
  RIT128x96x4Init(1000000);
  //Initializes the LED
  //LED_init();
  //Initializes the ADC
  ADCInit();
  //Initializes the keys on the keypad on the Stellaris Board
  key_init();
  //Initializes GPIO PORT E and enables its interrupts
  init_GPIOE();
  //Initializes GPIO PORT F and enables its interrupts
  init_GPIOF();
  // Initializes the PWM's used
  PWMinit();
  // Initializes Port D to use for sending signals to the H-bridge
  PORTD_init();
  PORTC_init();
  // This method is used by FreeRtos
  prvSetupHardware();
  // This initializes the speaker
  speakerInit();
  //Sets the UART port
  uARTInit();

}
Example #2
0
int main()
{
    //SYSTEMConfigPerformance(SYS_FREQ);
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    PORTFbits.RF1 = 0;

    //Function that initializes all of the required I/O
    initIO();

    //Initialize all of the LED pins
    ledinit();
    adcConfigureAutoScan();
    timersInit();
    motorinit();
    PWMinit();
    motorRstop();
    motorLstop();
    leftspeed = 290;
    rightspeed = 300;

    while(PORTDbits.RD3 == 0)
            {}

            for(i = 0; i < 5000000; i++)
            {
            }
    setpwmR(rightspeed);
    setpwmL(leftspeed);
    motorRfwd();
    motorLfwd();

    //turnright();
    //turnleft();
	while (1)
	{}

    return (EXIT_SUCCESS);
}
Example #3
0
void TurnOnHTPA(void)
{
	PWMinit();
	_5V_ENlat = 1;
	Delay10us(15);
	InputCapInit();
	ADCInit(); // enables SPI2 interrupt
	HTPAInit(); // enables SPI1 interrupt and Timer 5 init
    // set delay for analog signal to settle and low-pass filter cutoff
	if (_system_flags.uart_hi_speed) {
        PR5 = 60;
        PR4 = 1080;
        PWMGenerate(4,8);
    } else {
		PR4 = 4250;
		PR5 = 160;
        PWMGenerate(16,32);
    }
	HTPA_CONT_lat = 1;
	HTPA_counter = 0;
	_system_flags.Stopflag =0;
	_system_flags.StopHTPAflag=0;
}
Example #4
0
int main()
{
    //SYSTEMConfigPerformance(SYS_FREQ);
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    PORTFbits.RF1 = 0;

    //Function that initializes all of the required I/O
    initIO();

    //Initialize all of the LED pins
    ledinit();
    adcConfigureAutoScan();
    timer1Init();
    encodersInit();
    motorinit();
    PWMinit();
    motorRstop();
    motorLstop();
    leftspeed = 310;
    rightspeed = 300;

    while(PORTDbits.RD3 == 0)
            {}

            for(i = 0; i < 5000000; i++)
            {
            }
    setpwmR(rightspeed);
    setpwmL(leftspeed);
    motorRfwd();
    motorLfwd();

    //turnright();
    //turnleft();
	while (1)
	{
                if(readpins(0) > 300)   //left
		{
                    setpwmR(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed < 315)
                        leftspeed++;
                    if(rightspeed > 275)
                        rightspeed--;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 600)
                if(readpins(2) > 600) //right
		{
                    setpwmL(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed > 265)
                        leftspeed--;
                    if(rightspeed < 325)
                        rightspeed++;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 900)
                if(readpins(1) > 900) //middle
		{
                    setpwmR(0);
                    setpwmL(0);
                    motorRstop();
                    motorLstop();
                    turnright();

                }
                //for(i = 0; i < 1500; i++){};


	}

    return (EXIT_SUCCESS);
}
Example #5
0
int main(void)
{
	
    /* Configure Oscillator to operate the device at 30Mhz
       Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
       Fosc= 7.37*(32)/(2*2)=58.96Mhz for Fosc, Fcy = 29.48Mhz */

    /* Configure PLL prescaler, PLL postscaler, PLL divisor */
    //PLLFBDbits.PLLDIV=38;   /* M = PLLFBD + 2 */ // izlazna frekvencija = 30Mhz
    //Fin=8MHz, Fcy=30MHz 
	// Configure PLL prescaler, PLL postscaler, PLL divisor
	PLLFBD = 28; 				// M=40    ---> PLLFBD + 2 = M
	CLKDIVbits.PLLPOST = 0; 	// N2=2    ---> 2x(PLLPOST + 2) = N2
	CLKDIVbits.PLLPRE = 0; 	// N1=2    ---> PLLPRE + 2 = N1

	//new oscillator selection
	__builtin_write_OSCCONH(0b011);  				//0b011 ---> XT with PLL
	//enable oscillator source switch
	__builtin_write_OSCCONL (OSCCONL | (1<<0)); 	//OSWEN 

	//wait for PLL lock -> wait to new settings become available
	while (OSCCONbits.COSC != 0b011); 
	//wait for PLL lock
	while (OSCCONbits.LOCK != 0b1); 
    
    AD1PCFGL = 0xFFFF;// all PORT Digital

   
    RPINR18bits.U1RXR = 0;		//UART1 RX na RP0- pin 4
    RPOR0bits.RP1R = 3;			//UART1 TX na RP1- pin 5
    RPINR14bits.QEA1R = 2;		//QEI1A na RP2
    RPINR14bits.QEB1R = 3;		//QEI1B na RP3

    RPINR16bits.QEA2R = 4;		//QEI2A na RP4
    RPINR16bits.QEB2R = 7;		//QEI2B na RP7
    
    CAN_init(DRIVER_IDENTIFICATOR); // inicijalizacija CAN BUS- a-> argument je adresa drajvera

    int tmp;
    char komanda, v, smer;
    int Xc, Yc, ugao;
    
    NewLine();

    PortInit();
    //UARTinit();
    TimerInit();
    QEIinit();
    PWMinit();
   // CloseMCPWM();

    resetDriver();

    setSpeed(0x80);
    setSpeedAccel(K2);	//K2 je za 1m/s /bilo je 2
    int tmpX, tmpY, tmpO;
    unsigned char rxBuffer[8];
    while(1)
    {

        __delay_ms(1000);
        setSpeed(30);
       // kretanje_pravo(-1000, 0);
        if(getStatus() == STATUS_MOVING)
            CAN_getLastMessage(rxBuffer);
        else
            CAN_read(rxBuffer);

        komanda = rxBuffer[0];

        switch(komanda)
        {
            // zadavanje pozicije
            case 'I':
                tmpX = rxBuffer[1] << 8;
                tmpX |= rxBuffer[2];

                tmpY = rxBuffer[3] << 8;
                tmpY |= rxBuffer[4];

                tmpO = rxBuffer[5] << 8;
                tmpO |= rxBuffer[6];

                setPosition(tmpX, tmpY, tmpO);

                break;

            // citanje pozicije i statusa
            case 'P':
                sendStatusAndPosition();

                break;

            //zadavanje max. brzine (default K2/2)
            case 'V':
                tmp = rxBuffer[1];
                setSpeed(tmp);

                break;

            //kretanje pravo [mm]
            case 'D':
                tmp = rxBuffer[1] << 8;
                tmp |= rxBuffer[2];
                v = rxBuffer[3];

                PWMinit();
                kretanje_pravo(tmp, v);

                break;

            //relativni ugao [stepen]
            case 'T':
                tmp = rxBuffer[1] << 8;
                tmp |= rxBuffer[2];

                PWMinit();
                okret(tmp);

                break;

            //apsolutni ugao [stepen]
            case 'A':
                tmp = rxBuffer[1] << 8;
                tmp |= rxBuffer[2];

                PWMinit();
                apsolutni_ugao(tmp);

                break;

            //idi u tacku (Xc, Yc) [mm]
            case 'G':
                tmpX = rxBuffer[1] << 8;
                tmpX |= rxBuffer[2];
                tmpY = rxBuffer[3] << 8;
                tmpY |= rxBuffer[4];
                v = rxBuffer[5];
                smer = rxBuffer[6];

                PWMinit();
                gotoXY(tmpX, tmpY, v, smer);

                break;

            //kurva
            case 'Q':
                tmpX = rxBuffer[1] << 8;
                tmpX |= rxBuffer[2];
                tmpY = rxBuffer[3] << 8;
                tmpY |= rxBuffer[4];
                tmpO = rxBuffer[5] << 8;
                tmpO |= rxBuffer[6];
                smer = rxBuffer[7];

                PWMinit();
                kurva(tmpX, tmpY, tmpO, smer);

                break;

             //ukopaj se u mestu
            case 'S':
                stop();

                break;

            //stani i ugasi PWM
            case 's':
                stop();
                CloseMCPWM();

                break;

            case 'R':
                resetDriver();

                break;

            default:
                forceStatus(STATUS_ERROR);
                break;
        }
    }

    return 0;
}