コード例 #1
0
void drivers_setOutputs(void)
{
	
	// drive the digital outputs
	int index;
	bool temp;
	
	for (index = 0; index < 8; index++)
	{
		
		if (index < 1)
		{
			if (msp430.PORT_5.digitalOutput.state == high) { setDigitalOutput(&msp430.PORT_5.digitalOutput); }
			else										   { clearDigitalOutput(&msp430.PORT_5.digitalOutput); }
		}
		if (index < 4)
		{
			temp = msp430.PORT_7.digitalOutput[index].state;
			temp ?	setDigitalOutput(&msp430.PORT_7.digitalOutput[index]) :
					clearDigitalOutput(&msp430.PORT_7.digitalOutput[index]);
		}
		if (index < 8)
		{
			temp = msp430.PORT_8.digitalOutput[index].state;
			temp ?	setDigitalOutput(&msp430.PORT_8.digitalOutput[index]) :
					clearDigitalOutput(&msp430.PORT_8.digitalOutput[index]);
			
			temp = msp430.PORT_9.digitalOutput[index].state;
			temp ?	setDigitalOutput(&msp430.PORT_9.digitalOutput[index]) :
					clearDigitalOutput(&msp430.PORT_9.digitalOutput[index]);

		}
		if (index < 6)
		{
			temp = msp430.PORT_10.digitalOutput[index].state;
			temp ?	setDigitalOutput(&msp430.PORT_10.digitalOutput[index]) :
					clearDigitalOutput(&msp430.PORT_10.digitalOutput[index]);
		}
		
	}
	
	// TODO setup digital to analog converter and set outputs here
	
	// TODO send serial outputs
}
コード例 #2
0
/* Sets the logical values of the output control signal pins.
   This should be called frequently (not just when the values change).
   Bit 0 is DTR.
   Bit 1 is RTS. */
void ioTxSignals(uint8 signals)
{
    static uint8 nTrstPulseStartTime;
    static uint8 lastSignals;

    // Inverted outputs
    setDigitalOutput(param_nDTR_pin, (signals & ACM_CONTROL_LINE_DTR) ? 0 : 1);
    setDigitalOutput(param_nRTS_pin, (signals & ACM_CONTROL_LINE_RTS) ? 0 : 1);

    // Non-inverted outputs.
    setDigitalOutput(param_DTR_pin, (signals & ACM_CONTROL_LINE_DTR) ? 1 : 0);
    setDigitalOutput(param_RTS_pin, (signals & ACM_CONTROL_LINE_RTS) ? 1 : 0);

    // Arduino DTR pin.
    if (!(lastSignals & ACM_CONTROL_LINE_DTR) && (signals & ACM_CONTROL_LINE_DTR))
    {
        // We just made a falling edge on the nDTR line, so start a 1-2ms high pulse
        // on the nTRST line.
        setDigitalOutput(param_arduino_DTR_pin, HIGH);
        nTrstPulseStartTime = getMs();
    }
    else if ((uint8)(getMs() - nTrstPulseStartTime) >= 2)
    {
        setDigitalOutput(param_arduino_DTR_pin, LOW);
    }

    lastSignals = signals;
}
コード例 #3
0
void main()
{
    systemInit();
	
    //Among other things, allocates byte arrays for sending commands.
    dynamixel_init();

    // Oooh. what's this?
    setDigitalOutput(param_arduino_DTR_pin, LOW);
    ioTxSignals(0);

    //usbInit();
    uart1Init();
    uart1SetBaudRate(param_baud_rate);

    
	
    // Initial setting of serial mode
    updateSerialMode();

    // Set up P1_5 to be the radio's TX debug signal.
    // P1DIR |= (1<<5);
    // IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode)

	// P1DIR |= 0x20; //Enable pin P1_5
	
    while(1)
    {
	uint32 ms;
	uint16 now;
	uint16 speed;
		
	updateSerialMode();
	boardService();
	updateLeds();
	errorService();

	// Code for oscillating a servo back and forth
	ms = getMs();		// Get current time in ms
	now = ms % (uint32)10000; 	// 10 sec for a full swing
	if(now >= (uint16)5000){				// Goes from 0ms...5000ms
		now = (uint16)10000 - now;			// then 5000ms...0ms
	}
	speed = interpolate(now, 0, 5000, 100, 900); // speed is really the position.
	
	ax12SetGOAL_POSITION(32, speed);

	delayMs(30);
    }
}
コード例 #4
0
ファイル: adc_test.c プロジェクト: AdrianLxM/wixel-sdk
/* the functions that puts the system to sleep (PM2) and configures sleep timer to
wake it again in 250 seconds.*/
void makeAllOutputs(BIT value)
{
	//we only make the P1_ports low, and not P1_2 or P1_3
    int i = 10;
    for (;i < 17; i++)
	{
		//we don't set P1_2 low, it stays high.
/*		if(i==12)
			setDigitalOutput(i, HIGH);
		else if(i==13)
			setDigitalInput(i, PULLED);
		else
*/			setDigitalOutput(i, value);
    }
}
コード例 #5
0
void main()
{
    systemInit();

    setDigitalOutput(param_arduino_DTR_pin, LOW);
    ioTxSignals(0);

    usbInit();

    uart1Init();
    uart1SetBaudRate(param_baud_rate);

    if (param_serial_mode != SERIAL_MODE_USB_UART)
    {
        radioComRxEnforceOrdering = 1;
        radioComInit();
    }

    // Set up P1_5 to be the radio's TX debug signal.
    P1DIR |= (1<<5);
    IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode)

    while(1)
    {
        updateSerialMode();
        boardService();
        updateLeds();
        errorService();
/*        toggle_led();*/
        if (param_serial_mode != SERIAL_MODE_USB_UART)
        {
            radioComTxService();
        }

        usbComService();

        switch(currentSerialMode)
        {
        case SERIAL_MODE_USB_RADIO:  usbToRadioService();  break;
        case SERIAL_MODE_UART_RADIO: uartToRadioService(); break;
        case SERIAL_MODE_USB_UART:   usbToUartService();   break;
        }
    }
}
コード例 #6
0
void main()
{
	int8 SPI_SEND = 0;
	int8 prev_send = 0;
    systemInit();

    setDigitalOutput(param_arduino_DTR_pin, LOW);
    ioTxSignals(0);

    usbInit();

    spi0MasterInit();
    spi0MasterSetFrequency(38400);
//    uart1Init();
//    uart1SetBaudRate(param_baud_rate);

    if (param_serial_mode != SERIAL_MODE_USB_SPI)
    {
        radioComRxEnforceOrdering = 1;
        radioComInit();
    }

    // Set up P1_5 to be the radio's TX debug signal.
    //P1DIR |= (1<<5);
    //IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode)

    while(1)
    {
        updateSerialMode();
        boardService();
        updateLeds();
        //errorService();

        if(!spi0MasterBusy() && SPI_SEND != prev_send){
        	spi0MasterSendByte(SPI_SEND);
        	prev_send = SPI_SEND;
        }

        if (param_serial_mode != SERIAL_MODE_USB_SPI)
        {
            radioComTxService();
        }

        usbComService();

//        switch(currentSerialMode)
//        {
//        case SERIAL_MODE_USB_RADIO:  usbToRadioService();  break;
//        case SERIAL_MODE_SPI_RADIO: uartToRadioService(); break;
//        case SERIAL_MODE_USB_SPI:   usbToUartService();   break;
//        }


		switch(usbComRxReceiveByte()){

		case 0:		// STOP
			SPI_SEND += 15;
			SPI_SEND = (SPI_SEND%255);
			break;
		case 1:		// Initialize
			SPI_SEND -= 15;
			SPI_SEND = (SPI_SEND%255);
			break;
		}
    }
}
コード例 #7
0
ファイル: twitch_mx_xbee.c プロジェクト: erelson/wixel-sdk
void main()
{

    // uint32 ms;
    // uint32 now;
    
    // 
    uint8 cmdrAlive = 0;
    
    // Here we define what pins we will be using for PWM.
    // uint8 CODE pwmPins[] = {ptrGunMotor->pwmpin};
    uint8 CODE pwmPins[] = {11};
    
    MOTOR gunMotor = MAKE_MOTOR_3_PIN(pwmPins[0], 12, 13);  //(PWM, B, A)
    MOTOR *ptrGunMotor = &gunMotor;
    
    // setDigitalOutput(param_arduino_DTR_pin, LOW);
    // ioTxSignals(0);

    // Initialize UARTs
    uart0Init();
    uart0SetBaudRate(param_baud_rate_UART);
    uart1Init();
    uart1SetBaudRate(param_baud_rate_XBEE);
    
    pwmStart((uint8 XDATA *)pwmPins, sizeof(pwmPins), 10000);
    
    
    guns_firing_duration = 125; // time in ms
    gunbutton = zFALSE;
    solenoid_on_duration = 80; // time in ms
    solenoidbutton = zFALSE;
    laserbutton = zFALSE;
    
    systemInit();
    
    // Initialize other stuff
    index_cmdr = -1;

    /// MAIN LOOP ///
    while(1)
    {
        
        // updateSerialMode();
        boardService();
        updateLeds();
        errorService();
        
        
        // cmdr counts down from CMDR_ALIVE_CNT by -1 whenever no packets are received?
        cmdrAlive = (uint8) CLAMP(cmdrAlive + CmdrReadMsgs(), 0, CMDR_ALIVE_CNT);
        
        // ms = getMs();        // Get current time in ms
        // now = getMs();
        // now = ms % (uint32)10000;     // 10 sec for a full swing
        // if(now >= (uint16)5000){                // Goes from 0ms...5000ms
            // now = (uint16)10000 - now;            // then 5000ms...0ms
        // }
        // speed = interpolate(now, 0, 5000, 100, 900);
        
        if (laserbutton == zTRUE && cmdrAlive > 0){
            // uart0TxSendByte('L');
            setDigitalOutput(param_laser_pin, HIGH);
        }
        else {setDigitalOutput(param_laser_pin, LOW);}
        
        //FIRE THE GUNS!!!!!
        //Resets timer while gunbutton is held down.
        if (gunbutton == zTRUE){
            // uart0TxSendByte('Z');
            guns_firing = zTRUE;
            setMotorSpeed(ptrGunMotor, -60); //NOTE: (7.2 / 12.6) * 127 = 72.5714286
            guns_firing_start_time = getMs();
        }
        
        //Check whether to stop firing guns
        if (guns_firing && clockHasElapsed(guns_firing_start_time, guns_firing_duration)){
            // uart0TxSendByte('X');
            guns_firing = zFALSE;
            setMotorSpeed(ptrGunMotor, 0); //NOTE: (7.2 / 12.6) * 127 = 72.5714286
            guns_firing_start_time = getMs();
        }
        
        
        //Activate solenoid for hopup feed unjammer
        if (solenoidbutton == zTRUE){
            // uart0TxSendByte('Z');
            solenoid_on = zTRUE;
            setDigitalOutput(10, HIGH);
            solenoid_on_start_time = getMs();
        }
        
        //Check whether to disable solenoid
        if (solenoid_on && clockHasElapsed(solenoid_on_start_time, solenoid_on_duration)){
            // uart0TxSendByte('X');
            solenoid_on = zFALSE;
            setDigitalOutput(10, LOW);
            solenoid_on_start_time = getMs();
        }
    
        delayMs(5);
    }
}