示例#1
0
文件: main.c 项目: ptLong/Embedded-Pi
//*****************************************************************************
//
//! \brief Using PWM to Driver Motor.
//!
//! \param None
//!
//! \note None.
//!
//! \return None.
//
//*****************************************************************************
void xPWMotorControl(void)
{

    xSysCtlAndPwmInit();

    //
    // Set invert, dead zone and mode
    //
    xPWMInitConfigure(xPWMB_BASE, xPWM_CHANNEL7, xPWM_TOGGLE_MODE |
                      xPWM_OUTPUT_INVERTER_DIS |
                      xPWM_DEAD_ZONE_DIS);

    //
    // Set CNR, Prescale and Divider
    //
    xPWMFrequencyConfig(xPWMB_BASE, xPWM_CHANNEL7, xPWM_FREQ_CONFIG(16,150,5000));


    //
    // Set CMR
    //
    xPWMDutySet(xPWMB_BASE, xPWM_CHANNEL7, 50);

    //
    // Set output enable
    //
    xPWMOutputEnable(xPWMB_BASE, xPWM_CHANNEL7);


    //
    // start PWM
    //
    xPWMStart(xPWMB_BASE, xPWM_CHANNEL7);
}
示例#2
0
// init servo signal and pin
// does not check arguments, make sure to pass valide arguments
void servo_init(void)
{
	xSysCtlPeripheralClockSourceSet(xSYSCTL_PWMB_MAIN, 1);

	// Enable PWM peripheral
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_PWMB);

	// Enable gpio pin peripheral
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	// Enable PWM and set GPIO Pin as PWM
	xSPinTypePWM(TIM1CH0, PB0);
//	xSPinTypePWM(TIM0CH3, PE30);

	// Set invert, dead zone and mode
	xPWMInitConfigure(xPWMB_BASE, xPWM_CHANNEL0, xPWM_TOGGLE_MODE);

	// Set CNR, Prescale and Divider. FHz = 50Hz
	xPWMFrequencySet(xPWMB_BASE, xPWM_CHANNEL0, 50);

	// Set CMR, high pulse @ 1,5 ms middle position
	servo_angle(0);

	// Set output enable
	xPWMOutputEnable(xPWMB_BASE, xPWM_CHANNEL0);

	// start pwm
	xPWMStart(xPWMB_BASE, xPWM_CHANNEL0);

	// initialization ok

}
示例#3
0
文件: xpwmtest2.c 项目: 0xc0170/cox
static void xpwm002Execute(void)
{          
  
    unsigned long ulBase;
        
    int i, j;
    for(i = 0; i < 2; i++)
    {   
        for(j = 0; j < 4; j++)
        {
            ulBase = PWMBase[i];
                                                     
            //
            // Set invert, dead zone and mode
            //
            xPWMInitConfigure(ulBase, PWMChannel[i], xPWM_TOGGLE_MODE | 
                                            xPWM_OUTPUT_INVERTER_DIS | xPWM_DEAD_ZONE_DIS);
                
            // Set CNR, Prescale and Divider
            xPWMFrequencyConfig(ulBase, PWMChannel[i], 0x0E100028);
                
            //    
            // Set CMR
            //
            xPWMDutySet(ulBase, PWMChannel[i], 40);
                
            //    
            // Set output enable
            //
            xPWMOutputEnable(ulBase, PWMChannel[i]);   
            
            //
            // Set interrupt call back 
            //
            xPWMIntCallbackInit(ulBase, user_Callback);
                
            //
            // PWM output interrupt enable
            //
            xPWMIntEnable(ulBase, PWMChannel[i], xPWM_INT_PWM);
                
            //
            // NVIC interrupt enable
            //
            xIntEnable(xINT_TIMER1);
            xIntEnable(xINT_TIMER2);
            xIntEnable(xINT_TIMER3);
            xIntEnable(xINT_TIMER4);
                
            //    
            // start pwm
            //
            xPWMStart(ulBase, PWMChannel[i]);
            TestAssertQBreak("a", " pwm intterupt test error!", 0xffffffff);
        }             
    }   
}
示例#4
0
void pwmInit(){
	xSysCtlPeripheralClockSourceSet(xSYSCTL_PWMA_HCLK, 1);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_PWMA);
	xSysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	xSPinTypePWM(TIM0CH0, PB11);
	xSPinTypePWM(TIM0CH1, PB10);

	xPWMInitConfigure(xPWMA_BASE, xPWM_CHANNEL0, xPWM_TOGGLE_MODE);
	xPWMInitConfigure(xPWMA_BASE, xPWM_CHANNEL1, xPWM_TOGGLE_MODE);
	xPWMFrequencySet(xPWMA_BASE, xPWM_CHANNEL0, 50);
	xPWMDutySetPrec(xPWMA_BASE, xPWM_CHANNEL0, 750);
	xPWMOutputEnable(xPWMA_BASE, xPWM_CHANNEL0);
	xPWMStart(xPWMA_BASE, xPWM_CHANNEL1);
	xPWMFrequencySet(xPWMA_BASE, xPWM_CHANNEL1, 50);
	xPWMDutySetPrec(xPWMA_BASE, xPWM_CHANNEL1, 750 + STEER_OFFSET);
	xPWMOutputEnable(xPWMA_BASE, xPWM_CHANNEL1);
	xPWMStart(xPWMA_BASE, xPWM_CHANNEL1);
}
示例#5
0
//*****************************************************************************
//
//! \brief PWM output function example.
//!
//! \return None.
//
//*****************************************************************************
void PWM_Output()
{
    //
    // Initionalize system clock and I/O port.
    //
    IOInit();

    PrintLine( "*** Cox PWM example ***" );

    //
    // Set GPIO Pin as PWM and enable PWM
    //
    xSPinTypePWM(PWM2, PA14);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_PWMA);

    //
    // Set invert, dead zone and mode
    //
    xPWMInitConfigure(xPWMA_BASE, xPWM_CHANNEL2, xPWM_TOGGLE_MODE |
                      xPWM_OUTPUT_INVERTER_DIS | xPWM_DEAD_ZONE_DIS );

    // Set CNR, Prescale and Divider
    xPWMFrequencyConfig(xPWMA_BASE, xPWM_CHANNEL2, 0x3FF1111);

    //
    // Set CMR
    //
    xPWMDutySet(xPWMA_BASE, xPWM_CHANNEL2, 40);

    //
    // Set output enable
    //
    xPWMOutputEnable(xPWMA_BASE, xPWM_CHANNEL2);

    // Set interrupt call back
    xPWMIntCallbackInit(xPWMA_BASE, user_Callback);

    //
    // PWM output interrupt enable
    //
    xPWMIntEnable(xPWMA_BASE, xPWM_CHANNEL2, xPWM_INT_PWM);

    //
    // NVIC interrupt enable
    //
    xIntEnable(xINT_PWMA);

    //
    // start pwm
    //
    xPWMStart(xPWMA_BASE, xPWM_CHANNEL2);
}