Example #1
1
int main(void)
{
	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;
	volatile uint8_t ui8Adjust;
	ui8Adjust = 254;

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPinConfigure(GPIO_PF1_M1PWM5);

	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
	GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);

	while(1)
	{

		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00)
		{
			ui8Adjust--;
			if (ui8Adjust < 10)
			{
				ui8Adjust = 10;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
		}

		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00)
		{
			ui8Adjust++;
			if (ui8Adjust > 254)
			{
				ui8Adjust = 254;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
		}

		SysCtlDelay(100000);
	}

}
Example #2
0
// Send bit pattern
// Start pulse first, then the bits, lsb first
void SendIRCode(uint32_t code) {

	// 1. send start pattern
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
	delay_ms(T4);

	// 2. send code bit-by-bit
	int i;
	// UARTprintf("TX: sending %x\n", code);
	for (i = 0; i < IR_MAX_BITS_VAL; i++) {

		// transmit start of the bit (PWM off)
		PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, false);
		delay_ms(T1);

		// transmit end of the bit (PWM on)
		PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
		// int bit = (code >> i) & 0x1; // LSB first
		int bit = (code >> ((IR_MAX_BITS_VAL - 1) - i)) & 0x1; // MSB first
		// UARTprintf("tx: bit %d - %d\n", i, bit);
		if (bit)
		{
			delay_ms(T2);
		} else
		{
			delay_ms(T1);
		}
	}

	// 3. Set the PWM off
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, false);

	// debug blink-out
	// blink_n(code);
}
Example #3
0
//Task that plays a sound that gets within a range of 900 - 1200 distance within the distance sensor
void vTaskSpeaker(void *vParameters) {
  while(1) {
    //if the state is 5 or 6, this implies that the motor is not in standby(as determined from the menu options)
    if((state == 5 || state == 6) && (dist0 > 600 || dist1 > 600 || dist2 > 600 || dist3 > 600)){
      
       GPIO_PORTF_DEN_R |= 0x00000001;
      //Set u1Period (4400 Hz) as the period of PWM0
//      PWM_0_CMPA_R = 0x00012B;
       PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
      //Set the output of the speaker to true, so sound is heard
      PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
      //delay for 100 units, so sound can be heard 
      delay(100);
      //Set u1Period (4400 Hz * 2) as the period of PWM0
      PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod*2);
      //delay(100);
    }else{
      //if this is  not in the range of the sensor, set output to false
      //so sound is not heard anymore
//        GPIO_PORTF_DEN_R ^= 0x1;
//        PWM_0_CMPA_R = 0x0;
      PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, false);
    }
    //delay task for 10 units
    vTaskDelay(10);
  }
}
Example #4
0
//*****************************************************************************
//
//! Turns off all the PWM outputs.
//!
//! This function turns off all of the PWM outputs, preventing them from being
//! propagates to the gate drivers.
//!
//! \return None.
//
//*****************************************************************************
void
PWMOutputOff(void)
{
    //
    // Disable all six PWM outputs.
    //
	PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
	PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);

    //
    // Set the PWM duty cycles to 50%.
    //
    g_ulPWMDutyCycleRoll = 32768;
    g_ulPWMDutyCyclePitch = 32768;

    //
    // Set the PWM period so that the ADC runs at 1 KHz.
    //
    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, PWMRATE / 1000);
	PWMGenPeriodSet(PWM_BASE, PWM_GEN_1, PWMRATE / 1000);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, PWMRATE / 1000);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, PWMRATE / 1000);

    //
    // Update the PWM duty cycles.
    //
    PWMUpdateDutyCycle();
}
void DRV8833_InitMotorA(){
	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlDelay(3);
	GPIOPinConfigure(GPIO_PB6_M0PWM0);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_6,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
	PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
			PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);


	uint32_t duty = 0;
	PWMOutputUpdateMode(PWM0_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT,PWM_OUTPUT_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, freq);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);


	GPIOPinConfigure(GPIO_PB7_M0PWM1);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);

	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);

	PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
Example #6
0
//PWM³õʼ»¯
void initPWM()
{
    //³õʼ»¯ÍâÉè¶Ë¿Ú
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);  
    
    //ÉèÖÃPWMÐźÅʱÖÓ
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    
    //ÉèÖÃPG2ºÍPD1ΪPWMÊä³ö
    GPIOPinConfigure(GPIO_PG2_PWM0);
    GPIOPinConfigure(GPIO_PD1_PWM1);
    GPIOPinTypePWM(GPIO_PORTG_BASE, PWM_L);
    GPIOPinTypePWM(GPIO_PORTD_BASE, PWM_R);
    
    //ÅäÖÃPWM·¢ÉúÄ£¿é1
    PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC);
    //PWMGenConfigure(PWM_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC);

    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 1000);
    //PWMGenPeriodSet(PWM_BASE, PWM_GEN_3, 800);
    
   // PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,700);//×ó
   // PWMPulseWidthSet(PWM_BASE, PWM_OUT_1,500);//ÓÒ
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,banlanceL);//×ó
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_1,banlanceR);//ÓÒ
    //ʹÄÜPWM2Êä³ö
    PWMOutputState(PWM_BASE,PWM_OUT_0_BIT,true);
    //ʹÄÜPWM3Êä³ö
    PWMOutputState(PWM_BASE,PWM_OUT_1_BIT,true);
    
    PWMGenEnable(PWM_BASE, PWM_GEN_0);
}
int test_b_output_toggle(void)
{
	static int count = 0;
	static int state = 0;
	static int num_waits = 1;

	// generates 3 pulses, looks like 2 on a scope
	// but a very narrow pulse is generated on the cycle where
	// PWM is disabled, this is slightly hacky, but
	// the pulse is reliably recieved by the uut.
 	if (count >= 2 && state == 0)
	{
		state = 1;
		count = 0;

		PWMOutputState(PWM0_BASE, PWM_GEN_1_BIT, 0); //Disable PWM output

		return 0; // Because a pulse is still generated this cycle
	}
	else if (count > num_waits + 5 && state == 1)
	{
		num_waits = (num_waits * 283 + 23)%7; // make some pseudorandomness

		state = 0;
		count = 0;

		PWMOutputState(PWM0_BASE, PWM_GEN_1_BIT, 1); // Reenable output

	}

	count++;
	return state;
}
void DRV8833_InitMotorB(){
	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	if(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlDelay(3);


	GPIOPinConfigure(GPIO_PB4_M0PWM2);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
	PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_1,
			PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

	uint32_t duty = 0;
	PWMOutputUpdateMode(PWM0_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT,PWM_OUTPUT_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, freq);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);


	GPIOPinConfigure(GPIO_PB5_M0PWM3);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_5,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);

	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, duty);
	PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true);

	HWREG(GPIO_PORTB_BASE+GPIO_O_AFSEL) &= ~0x30;
	PWMGenEnable(PWM0_BASE, PWM_GEN_1);
}
/* Act on select button pushes received from the ISR.
 * Toggle the helicopter rotor on and off with each push.
 */
static void vStartStopPWM ( void *pvParameters )
{
    /* Take the semaphore once to start with so the semaphore is empty before the
    infinite loop is entered.  The semaphore was created before the scheduler
    was started so before this task ran for the first time.*/
    xSemaphoreTake( xBinarySelectSemaphore, 0 );
    portBASE_TYPE flying = pdFALSE;

    for( ;; )
    {
        /* Use the semaphore to wait for the event. */
        xSemaphoreTake( xBinarySelectSemaphore, portMAX_DELAY );

        if (flying == pdFALSE) {
		    pid_init();
		    // Turn the main rotor on.
			PWMOutputState(PWM_BASE, PWM_OUT_1_BIT, true);
			// Reset the desired height
			desiredAltitude = INITIAL_ALT;
			flying = pdTRUE;
        } else {
        	// Turn the thing off.
        	while (desiredAltitude > 5) {
        		desiredAltitude -= 2;
        		vTaskDelay( 100 / portTICK_RATE_MS );
        	}
		    PWMOutputState(PWM_BASE, PWM_OUT_1_BIT, false);
        	flying = pdFALSE;
        }
    }
}
Example #10
0
void motor(int hastighed)
{
    unsigned long ulPeriod;
    //
    //! Compute the PWM period based on the system clock.
    //
    ulPeriod = SysCtlClockGet() / hastighed;//! line 99 if the @param hastighed is 100 there is 100 hz on pin PWM 1 with 200 there is 200 hz aso.

    //
    // Set the PWM0 period to 440 (A) Hz if on hastighed=100
    //
    PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
    //
    //! line 109 and 110 Set PWM0 to a duty cycle of 25% and PWM1 to a duty cycle of 75%.
    //
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ulPeriod / 4);
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod * 3 / 4);

	if(hastighed > 0)//! line 112 to turn on PWM if they a set to a speed
	{
		PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
	}
	if(hastighed == 0)//! line 116 to turn of PWM and set the port to 0 so they a not run some thing on the motors
	{
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
		PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
	}

}
//******************************************************************
// Initialise the PWM generator (PWM1 & PWM4)
//******************************************************************
void
initPWMchan (void)
{
	unsigned long period;

    SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM);
    //
    // Compute the PWM period based on the system clock.
    //
        SysCtlPWMClockSet (PWM_DIV_CODE);

    PWMGenConfigure (PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenConfigure (PWM_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    period = SysCtlClockGet () / PWM_DIVIDER / MOTOR_RATE_HZ;
    PWMGenPeriodSet (PWM_BASE, PWM_GEN_0, period);
    PWMGenPeriodSet (PWM_BASE, PWM_GEN_2, period);
    PWMPulseWidthSet (PWM_BASE, PWM_OUT_1, period * main_duty / 100);
    PWMPulseWidthSet (PWM_BASE, PWM_OUT_4, period * tail_duty / 100);
    //
    // Enable the PWM output signal.
    //
    PWMOutputState (PWM_BASE, PWM_OUT_1_BIT, false);
    PWMOutputState (PWM_BASE, PWM_OUT_4_BIT, false);
    //
    // Enable the PWM generator.
    //
    PWMGenEnable (PWM_BASE, PWM_GEN_0);
    PWMGenEnable (PWM_BASE, PWM_GEN_2);
}
Example #12
0
void rampGenericPWM(bool rampDirection, uint32_t pwmBase, uint32_t pwm,
		uint32_t pwmBit, uint32_t delay) {

	// Start value is the current PWM pulse width regardless the ramp direction
	uint32_t i = PWMPulseWidthGet(pwmBase, pwm);

	if (rampDirection == PWM_RAMP_UP) {
		uint32_t targetPwmLoad = PWMGenPeriodGet(pwmBase, PWM_GEN_3);
		PWMOutputState(pwmBase, pwmBit, true);

		for (; i < targetPwmLoad; i += PWM_STEP)
		{
			PWMPulseWidthSet(pwmBase, pwm, i);
			SysCtlDelay(delay);
		}
	} else // rampDirection == PWM_RAMP_DOWN
	{
		for (; i > PWM_LOW; i -= PWM_STEP)
		{
			PWMPulseWidthSet(pwmBase, pwm, i);
			SysCtlDelay(delay);
		}

		PWMOutputState(pwmBase, pwmBit, false);
	}
}
Example #13
0
//*****************************************************************************
//
// Interrupt handlers
//
//*****************************************************************************
void
SysTickIntHandler(void){
	// Handle state changes
	if (done){
		tick++;
		if (tick>1){
			if (lose){
				// Turn off the noise
				PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
				PWMGenDisable(PWM0_BASE, PWM_GEN_0);
				unsigned long ulPeriod = SysCtlClockGet() / 220;

				// Set the PWM period to 220 (A) Hz.
				PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
						PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
				PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);

				// Make some noise again
				PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
				PWMGenEnable(PWM0_BASE, PWM_GEN_0);
			}
		}
		if (tick>2){
			if (lose){
				// Turn off the noise
				PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
				PWMGenDisable(PWM0_BASE, PWM_GEN_0);

				unsigned long ulPeriod = SysCtlClockGet() / 440;
				// Set the PWM period to 440 (A) Hz. again
				PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
						PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
				PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
				lose = 0;
			}
			if (state==1){
				startClassic();
				tick = 0;
				done = 0;
			}
			else if(state==2){
				if(tick>4){
					RIT128x96x4Clear();
					initMain();
					state = 0;
					pointer = 0;
					tick = 0;
					done = 0;
				}
			}
			else if (state==3){
				startContinuous();
				tick = 0;
				done = 0;
			}
		}
	}
}
Example #14
0
File: bsp.c Project: saiyn/web
void bsp_lcd_bright_control(uint8 duty)
{
	 if(duty){
		  PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, 1);
		  PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, duty*PWMGenPeriodGet(PWM0_BASE,PWM_GEN_0)/100);
	 }else{
		  PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, 0);
	 }
}
int main(void)
{

	SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable the GPIO A ports
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Enable the GPIO E ports
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	GPIOPinConfigure(GPIO_PB6_M0PWM0);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);

	GPIOPinConfigure(GPIO_PB7_M0PWM1);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);

	PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 6400000);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) / 1.25);
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
	PWMGenEnable(PWM0_BASE, PWM_GEN_0);

	PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 6400000);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, PWMGenPeriodGet(PWM0_BASE, PWM_GEN_1) / 1.25);
	PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
	PWMGenEnable(PWM0_BASE, PWM_GEN_1);


	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6|GPIO_PIN_7); // Set pin 7 as the output port
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2);
	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_5);


	GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7,64); // Give '1' to pin 7
	GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_1|GPIO_PIN_2,4);
	while(1)
	{
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7,64); // Give '1' to pin 7
		GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_1|GPIO_PIN_2,4);
		SysCtlDelay(4000000*10);
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7,0); // Give '1' to pin 7
	    GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_1|GPIO_PIN_2,0);
	    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,32);
	    SysCtlDelay(400000);
	    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,0);
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7,128); // Give '1' to pin 7
		GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_1|GPIO_PIN_2,2);
		SysCtlDelay(4000000*10);
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7,0); // Give '1' to pin 7
		GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_1|GPIO_PIN_2,0);
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,32);
		SysCtlDelay(400000);
		GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,0);

	}
}
Example #16
0
void SetA3906Logic(enum MOTOR motor, enum A3906Logic direction)
{
  unsigned long bit0,bit1;
  tBoolean b0,b1;
  switch (motor)
  {
    case PITCH_MOTOR:
      bit0 = PWM_OUT_0_BIT;
      bit1 = PWM_OUT_1_BIT;
      break;
    case ROLL_MOTOR:
      bit0 = PWM_OUT_2_BIT;
      bit1 = PWM_OUT_3_BIT;
      break;
  }
  switch (direction)
  {
    case A3906_FORWARD:
      b0 = true;
      b1 = false;
      break;
    case A3906_REVERSE:
      b0 = false;
      b1 = true;
      break;
    case A3906_BRAKE:
      b0 = true;
      b1 = true;
      break;
    case A3906_DISABLE:
      b0 = false;
      b1 = false;
      break;
  }

  if (motor == PITCH_MOTOR)
  {
	  PWMOutputState(PWM_BASE, bit0, b0);
	  PWMOutputState(PWM_BASE, bit1, b1);
  }
  else
  {
	  PWMOutputState(PWM1_BASE, bit0, b0);
	  PWMOutputState(PWM1_BASE, bit1, b1);
  }  
  
  
  
}
/*
 *  ======== PWMTiva_close ========
 *  @pre    Function assumes that the handle is not NULL
 */
void PWMTiva_close(PWM_Handle handle)
{
    unsigned int           key;
    uint8_t                pwmPairOutput;
    PWMTiva_Object        *object = handle->object;
    PWMTiva_HWAttrs const *hwAttrs = handle->hwAttrs;

    PWMTiva_setDuty(handle, 0);
    PWMOutputState(hwAttrs->baseAddr, hwAttrs->pwmOutput, false);

    key = Hwi_disable();

    pwmPairOutput = (hwAttrs->pwmOutput & 0x01) ? object->pwmOutputBit >> 1 :
                                                  object->pwmOutputBit << 1;

    /* Disable PWM generator only if the pair output is not being used. */
    if (!((object->pwmStatus)->activeOutputs & pwmPairOutput)) {
        PWMGenDisable(hwAttrs->baseAddr, hwAttrs->pwmOutput & PWM_GEN_MASK);
        *((object->pwmStatus)->genPeriods +
          ((hwAttrs->pwmOutput / PWM_OUT_0) - 1)) = 0;
    }

    (object->pwmStatus)->activeOutputs &= ~(object->pwmOutputBit);

    if (!(object->pwmStatus)->activeOutputs) {
        /* PWM completely off, clear all settings */
        (object->pwmStatus)->cyclesPerMicroSec = 0;
        (object->pwmStatus)->prescalar = 0;
    }

    Hwi_restore(key);

    Log_print1(Diags_USER1, "PWM: (%p) closed", (UArg) handle);
}
Example #18
0
void
GPIOFIntHandler(void)
{
    // Clear the GPIO interrupt.
    GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1);

    y = 0;
    // Counter for how long the snooze button was pressed
    while (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1)==0){
    	y++;
       }
    // If the snooze button was held long enough, add 5 minutes to the alarm
    if (y>500000){
    	int z;
    	for (z=0; z<5; z++){
    		IncrementTimeA();
        }
    }
    // Clear the screen
    RIT128x96x4Clear();
    // Turn off the LED
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
    // Turn off the alarm
    PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
    PWMGenDisable(PWM0_BASE, PWM_GEN_0);
    // Disable the interrupt so that snooze and turn off alarm cannot be used
    GPIOPinIntDisable(GPIO_PORTF_BASE, GPIO_PIN_1);
}
Example #19
0
void PWM_Setup()
{
	SysCtlPWMClockSet(PWM_SYSCLK_DIV_64);
	//
	// Configure the PWM generator for count down mode with immediate updates
	// to the parameters.
	//
	PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	// Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20
	// microseconds. For a 20 MHz clock, this translates to 400 clock ticks.
	// Use this value to set the period.
	//
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, MAXPERIOD);
	//
	// Set the pulse width of PWM1 for a 75% duty cycle.
	//
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, 0);
	
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, 0);
	// 50MHZ is to fast
	PWMClockSet(PWM1_BASE,PWM_SYSCLK_DIV_64);
	//
	// Start the timers in generator 3.
	//
	PWMGenEnable(PWM1_BASE, PWM_GEN_3);
	//
	// Enable the outputs.
	//
	PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT , true);

}
Example #20
0
void motors_init(void) {

	int i;
	uint8_t pin_mask;
	uint32_t motor_per;

	// Set Pins to output/PWM in GPIO
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	GPIOPinConfigure(GPIO_PF2_M1PWM6);
	GPIOPinConfigure(GPIO_PF3_M1PWM7);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);

	// Configure the pin for standby control
	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);

	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
	// Configure the PWM for each pin:
	// Turn on the generators and set the PW to 0
	// The output is still OFF. Turn on with set_motor_pwm_state
	for (i = 0; i < NUM_MOTORS; i++) {
		PWMGenConfigure(motors[i].pwm_base_module, motors[i].pwm_generator, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
		motor_per = calc_cycles(MOTOR_PERIOD);
		PWMGenPeriodSet(motors[i].pwm_base_module, motors[i].pwm_generator, motor_per);
		PWMPulseWidthSet(motors[i].pwm_base_module, motors[i].pwm_pin, 0);
		PWMGenEnable(motors[i].pwm_base_module, motors[i].pwm_generator);
		pin_mask = 1 << (0x0000000F & motors[i].pwm_pin);
		PWMOutputState(motors[i].pwm_base_module, pin_mask, 0);
	}

}
Example #21
0
//--------------------------------
void pwm_stepper::Initialize() {
	g_pTheStepper = this;
	SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA6_M1PWM2);
	GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);
	PWMGenConfigure(Base, Generator, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	// Set the PWM period to 250Hz.  To calculate the appropriate parameter
	// use the following equation: N = (1 / f) * SysClk.  Where N is the
	// function parameter, f is the desired frequency, and SysClk is the
	// system clock frequency.
	// In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles.  Note that
	// the maximum period you can set is 2^16.
	PWMGenPeriodSet(Base, Generator, Default_StartSpeed);
	PWMPulseWidthSet(Base, PWM_OUT_2, 64);
	// Allow PWM1 generated interrupts.  This configuration is done to
	// differentiate fault interrupts from other PWM1 related interrupts.
	PWMIntEnable(Base, PWM_INT_GEN_1);
	// Enable the PWM1 LOAD interrupt on PWM1.
	PWMGenIntTrigEnable(Base, Generator, PWM_INT_CNT_LOAD);
	// Enable the PWM1 interrupts on the processor (NVIC).
	IntEnable(INT_PWM1_1);
	// Enable the PWM1 output signal (PA6).
//	PWMOutputInvert(Base, PWM_OUT_2_BIT, true);
	PWMOutputState(Base, PWM_OUT_2_BIT, true);
}
Example #22
0
//*****************************************************************************
//
// Set up the PWM0 output to be used as a signal source for the CCP1 input
// pin.  This example application uses PWM0 as the signal source in order
// to demonstrate the CCP usage and also to provide a predictable timing
// source that will produce known values for the capture timer.  In a real
// application some external signal would be used as the signal source for
// the CCP input.
//
//*****************************************************************************
static void
SetupSignalSource(void)
{
    //
    // Enable the GPIO port used for PWM0 output.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Enable the PWM peripheral and configure the GPIO pin
    // used for PWM0.  GPIO pin D0 is used for PWM0 output.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
    GPIOPinConfigure(GPIO_PD0_PWM0);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);

    //
    // Configure the PWM0 output to generate a 50% square wave with a
    // period of 5000 processor cycles.
    //
    PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, TIMEOUT_VAL);
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, TIMEOUT_VAL / 2);
    PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, 1);
    PWMGenEnable(PWM_BASE, PWM_GEN_0);
}
//*****************************************************************************
//
//! Turns off all the PWM outputs.
//!
//! This function turns off all of the PWM outputs, preventing them from being
//! propagates to the gate drivers.
//!
//! \return None.
//
//*****************************************************************************
void
PWMOutputOff(void)
{
    //
    // Disable all six PWM outputs.
    //
    PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
                               PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT),
                   false);

    //
    // Set the PWM duty cycles to 50%.
    //
    g_ulPWMDutyCycleA = 32768;
    g_ulPWMDutyCycleB = 32768;
    g_ulPWMDutyCycleC = 32768;

    //
    // Set the PWM period so that the ADC runs at 1 KHz.
    //
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PWM_CLOCK / 1000);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, PWM_CLOCK / 1000);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, PWM_CLOCK / 1000);

    //
    // Disable Deadband and update the PWM duty cycles.
    //
    PWMClearDeadBand();
    PWMUpdateDutyCycle();
}
Example #24
0
//*****************************************************************************
//
//! This is the code that gets called when the processor receives an unexpected
//! interrupt.  This simply enters an infinite loop, preserving the system
//! state for examination by a debugger.
//!
//! \return None.
//
//*****************************************************************************
void
IntDefaultHandler(void)
{
    //
    // Disable all interrupts.
    //
    IntMasterDisable();

    //
    // Turn off all the PWM outputs.
    //
    PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
                              PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT,
                              false);

    //
    // Turn on STATUS and MODE LEDs.  They will remain on.
    //
    BlinkStart(STATUS_LED, 1, 1, 1);
    BlinkStart(MODE_LED, 1, 1, 1);
    BlinkHandler();

    //
    // Go into an infinite loop.
    //
    while(1)
    {
    }
}
Example #25
0
	void ConfiguracionPWM(uint8_t Ancho){
		PWMClock = SysCtlClockGet() / 64;
		Load = (PWMClock / Frecuencia) - 1;
		PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
		PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, Load);
		PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
		PWMGenEnable(PWM1_BASE, PWM_GEN_0);
	}
Example #26
0
void set_pulse_width(motor_index_t index, uint32_t *uSec) {
	uint32_t cycles = calc_cycles(*uSec);

	uint8_t pin_mask;
	// set uSec as closest value as possible with Timer settings
	*uSec = calc_usec(cycles);
	pin_mask = 1 << (0x0000000F & motors[index].pwm_pin);

	if(cycles <= 0){
		PWMOutputState(motors[index].pwm_base_module, pin_mask, 0);
	}
	else{
		PWMOutputState(motors[index].pwm_base_module, pin_mask, 1);
		PWMPulseWidthSet(motors[index].pwm_base_module, motors[index].pwm_pin, cycles);
	}

}
Example #27
0
//*****************************************************************************
//
// Turn PWM on/off
//
//*****************************************************************************
void
io_set_pwm(tBoolean bOn)
{
    //
    // Enable or disable the PWM1 output.
    //
    PWMOutputState(PWM_BASE, PWM_OUT_1_BIT, bOn);
}
Example #28
0
void RedSetup(volatile uint8_t ui8Adjust){
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPinConfigure(GPIO_PF1_M1PWM5);
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);
}
Example #29
0
void GreenSetup(volatile uint8_t ui8Adjust){
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);
	GPIOPinConfigure(GPIO_PF3_M1PWM7);
	PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8Adjust * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_3);
}
Example #30
0
void Init_PWM() {
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
	SysCtlPWMClockSet(SYSCTL_PWMDIV_2);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
	PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 400);
	PWMGenEnable(PWM_BASE, PWM_GEN_0);
	PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true);
}