コード例 #1
0
ファイル: motors.c プロジェクト: OpenRobotiK/RobORK2
void MOTOR_Init(uint32_t motor) {

	if(motor == MOTOR_RIGHT) {

		PWM_Init(PWM1, 20);

		LPC_PINCON->PINSEL4 &= 0xFFFC0FFF; //  P2.6/7/8 are configured as GPIO.
		LPC_GPIO2->FIODIR0 |= (1<<6) | (1<<7) ; // P2.6/7 are configured as output.
		LPC_GPIO2->FIODIR1 |= (1<<0); // P2.8 is configured as output.

		LPC_GPIO2->FIOSET0 &= (0<<6) ; // P2.6 is set to 1.		InA
		LPC_GPIO2->FIOSET0 |= (1<<7 ); //P2.7 is set to 0.		InB
		LPC_GPIO2->FIOSET1 |= (1<< 0); //P2.8 is set to 1.		Diag


	} else if(motor == MOTOR_LEFT) {

		PWM_Init(PWM2, 20);

		LPC_PINCON->PINSEL4 &= 0xFC0FFFFF;

		LPC_GPIO2->FIODIR1 |= (1<<2) | (1<<3) | (1<<4); // P2.10/11/12 are configured as output.

		LPC_GPIO2->FIOSET1 |= (1<<2); // P2.10 is set to 1.
		LPC_GPIO2->FIOSET1 |= (1<<3 ); //P2.11 is set to 0. DIAG
		LPC_GPIO2->FIOSET1 |= (1<< 4); //P2.12 is set to 1.INb
		int i=0;
		for ( i = 0 ;i==10000;i++)
		{asm("nop");}
		//LPC_GPIO2->FIOSET1 &= (0<<2); // P2.10 is set to 1.
		LPC_GPIO2->FIOCLR1 |= (1<<3 ); //P2.11 is set to 0.DIAG
		//LPC_GPIO2->FIOSET1 &= (0<< 4); //P2.12 is set to 1. INb
	}
}
コード例 #2
0
ファイル: motors.c プロジェクト: OpenRobotiK/RobORK2
void MOTOR_Init(Motor motor) {

	if(motor == RIGHT_MOTOR) {

		PWM_Init(PWM1, 20);

		LPC_PINCON->PINSEL4 &= 0xFFFC0FFF; //  P2.6/7/8 are configured as GPIO.
		LPC_GPIO2->FIODIR0 |= (1<<6) | (1<<7) ; // P2.6/7 are configured as output.
		LPC_GPIO2->FIODIR1 |= (1<<0); // P2.8 is configured as output.

		LPC_GPIO2->FIOCLR0 |= (1<<6) ; // P2.6 is set to 0.		InA
		LPC_GPIO2->FIOSET0 |= (1<<7 ); //P2.7 is set to 1.		InB
		LPC_GPIO2->FIOSET1 |= (1<< 0); //P2.8 is set to 1.		Diag


	} else if(motor == LEFT_MOTOR) {

		PWM_Init(PWM2, 20);

		LPC_PINCON->PINSEL4 &= 0xFC0FFFFF;
		LPC_GPIO2->FIODIR1 |= (1<<2) | (1<<3) | (1<<4); // P2.10/11/12 are configured as output.

		LPC_GPIO2->FIOSET1 |= (1<<2); // P2.10 is set to 1.INa
		LPC_GPIO2->FIOCLR1 |= (1 << 3 ); //P2.11 is set to 0. INb
		LPC_GPIO2->FIOSET1 |= (1<< 4); //P2.12 is set to 1.DIAG
	}
}
コード例 #3
0
ファイル: pwm_set.c プロジェクト: tsymiar/4AxisFlying
void PWM_Set(int moto1, int moto2, int moto3, int moto4)
{
	PWM_Init(GPIO_Pin_3);
	/*output*/
	TIM_SetCompare2(TIM8,moto1);
	
	PWM_Init(GPIO_Pin_4);
	TIM_SetCompare2(TIM8,moto2);
	
	PWM_Init(GPIO_Pin_5);
	TIM_SetCompare2(TIM8,moto3);
	
	PWM_Init(GPIO_Pin_6);
	TIM_SetCompare2(TIM8,moto4);
}
コード例 #4
0
/*************************************************************
//! 函数名:void main (void)
//! 函数说明:主程序
*************************************************************/
void main (void)
{
   unsigned char i,max_data_chn; 
   struct movement_info *car_cmd;

   PCA0MD &= ~0x40;    //关闭看门狗                
   Oscillator_Init();  //时钟晶振初始化
    // ADC_PortInit();                  
   Timer1_Init();      //定时器1初始化                
   //Timer3_Init ();                                                        
   SMBus_Init ();      //SMBus初始化(IIC控制器)    
   PWM_Init();		   //PWM初始化
   servo_init();	   //舵机控制初始化            
  //Watchdog_Init();
   EA = 1;             // 开中断
  
	do
	{	      

	    Flag = 0; 
		while (!rec_flag) ;	//检测接收控制数据的标志

		rec_flag = 0;
		car_cmd = (struct movement_info *)Data; //若接收到数据,则从全局区取出
		car_movement_control(car_cmd);			//根据控制信息执行车体控制代码
		
	}while(1);

}
コード例 #5
0
ファイル: bsp.c プロジェクト: Vanganesha/oufffteam
void  BSP_InitIO (void)    
{
#ifdef _TARGET_440H
	BSP_IO_Init();
	LCD_Init();
	Tmr_Init();
    LED_Init();                                                         /* Initialize LEDs                                  */
	LS2_UART_Init();
#else
	SYSTEMConfig(BSP_CLK_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
	
    BSP_IO_Init(); 
#ifndef AX12_REG_PROGRAMMING                                                     // Initialize the board's I/Os
    Tmr_Init();                                                         // Initialize the timers
    BSP_InitIntCtrl();                                                  // Initialize the interrupt controller
#endif

    LED_Init();                                                         // Initialize LEDs
    //PB_Init();                                                        // Initialize the push buttons
    ADC_Init();
	PMP_Init();
	LS2_UART_Init();
	PWM_Init();
#endif
}
コード例 #6
0
ファイル: roach.c プロジェクト: BananaSlug/24_hour_bot_2013
/****************************************************************************
 Function
     Roach_Init

 Parameters
    None.

 Returns
     SUCCESS if operation successful
     ERROR  otherwise

 Description
      Performs all the initialization necessary for the roach.
      this includes initializing the PWM module, the A/D converter, the
      data directions on some pins, and setting the initial motor directions.
 Notes
     None.

 Author
    Max Dunne, 2012.01.06
 ****************************************************************************/
char Roach_Init(void) {
    //Initialize the serial port
    SERIAL_Init();
    TIMERS_Init();
    //set the control pins for the motors
    PWM_Init(LEFT_PWM | RIGHT_PWM, 200);
    LEFT_DIR_TRIS = 0;
    LEFT_DIR_INV_TRIS = 0;
    RIGHT_DIR_TRIS = 0;
    RIGHT_DIR_INV_TRIS = 0;
    LEFT_DIR = 0;
    LEFT_DIR_INV = ~LEFT_DIR;
    RIGHT_DIR = 0;
    RIGHT_DIR_INV = ~RIGHT_DIR;

    //set up the hall effect and divorce all the A/D pins
    AD1PCFG = 0xFF;
    HALL_FRONT_LEFT_TRIS = 1;
    HALL_FRONT_RIGHT_TRIS = 1;
    HALL_REAR_RIGHT_TRIS = 1;
    HALL_REAR_LEFT_TRIS = 1;


    //Initialize the light sensor
    AD_Init(LIGHT_SENSOR);

    //enable interrupts
    INTEnableSystemMultiVectoredInt();
}
コード例 #7
0
ファイル: main.c プロジェクト: danbao/SmartCar
void main(void) 
{

 // int temp_laserStatus;           //定义一个数组用来接受 上下舵机值
  DisableInterrupts;
  SetBusCLK_40M();    //   设置时钟初始化。40MHz.
  PITInit();          //PIT初始
  PWM_Init();
  LIGHT_Init();
  SCI_Init();
  Tect_Speed_Init();    //ECT 捕捉初始
 // AD_Init(); 
  delayms(3200);
  Laser_num();
  EnableInterrupts;
  for(;;) 
  {     
  TestSMinfo(test_info_send);   
  }

          
// _FEED_COP(); /*看门狗,防死循环用的 */
 /* loop forever */
  /* please make sure that you never leave main */
}
コード例 #8
0
ファイル: setters.c プロジェクト: drivkin/cubesat
void init_MDB(void){
PWM_Init();
PWM_AddPins(PWM_PORTY04);// this is J5-03 on the uno or RD3 (this is the same one we use for slave select in SPI mode)
PWM_SetFrequency(PWM_500HZ);
TRISDbits.TRISD10 = 0; // this is the one that we'll use for direction
DIRECTION = FORWARD;
}
コード例 #9
0
ファイル: demoXSPWM.c プロジェクト: danbao/SmartCar
void Init_Dev(void)
{
    setbusclock();
    Port_Init();
    SCI_Init();
    PWM_Init();   
}
コード例 #10
0
char Bot_Init(void)
{
    // Initialize modules
    AD_Init();
    PWM_Init();


    // Configure digital pins
    IO_PortsSetPortOutputs(MUX_PINS_PORT, MUX_PINS_OR);
    IO_PortsSetPortOutputs(MOTOR_PINS_PORT, MOTOR_PINS_LEFT_DIR |
			    MOTOR_PINS_RIGHT_DIR | MOTOR_PINS_LIFT_DIR | MOTOR_PINS_LIFT_EN);
    IO_PortsSetPortOutputs(SENSOR_PINS_PORT, SENSOR_PINS_LEDS);
    IO_PortsSetPortInputs(SENSOR_PINS_PORT, SENSOR_PINS_BUMP | SENSOR_PINS_TRACK);

	// Init lift motor to off
	IO_PortsClearPortBits(MOTOR_PINS_PORT, MOTOR_PINS_LIFT_EN);

    // Configure PWM pins
//    PWM_SetFrequency(PWM_BOT_FREQUENCY);
//    PWM_AddPins(MOTOR_PINS_LEFT_EN | MOTOR_PINS_RIGHT_EN);

    // Configure AD pins
    AD_AddPins(SENSOR_PINS_BEACON | SENSOR_PINS_TAPE);

    return SUCCESS;
}
コード例 #11
0
int main(void) {



	//preparing the chip & board
	SystemCoreClockUpdate();
	Board_Init();
	PWM_Init();
	PWM_SetCycle(400,1000);

	//the actual code
	Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup);
	Chip_ADC_EnableChannel(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE);
	Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
	//int i;

	SysTick_Config(SystemCoreClock / TICKRATE_HZ1);

    while(1) {
    	__WFI();
    	/*
    	if(rotation_counter==MEMORY_CAPACITY){			//not rotation_cycle?
    		for(i=0;i<MEMORY_CAPACITY;i++){
    		DEBUGOUT("%d \n",rotation_debug_holder[i]);//,rotation_debug_holder2[i]);
    		}
    		rotation_counter++;
    	}
    	*/
    }
    return 0 ;
}
コード例 #12
0
static void DoSleep (void) {
	while (PWM_Busy());				// wait for PWM to complete
	PWM_Set(0, 0, 0, 0);
	__delay_ms(50);
	
	TRISBbits.TRISB4  = 1;			// change SDA to input temporarily
	TRISBbits.TRISB6  = 1;			// change SCL to input temporarily
	
	TRISAbits.TRISA0  = 1;			// temporarily make JTAG pins inputs
	TRISAbits.TRISA1  = 1;
	WPUAbits.WPUA0 = 1;				// enable pull-ups
	WPUAbits.WPUA1 = 1;	
	IOCANbits.IOCAN0 = 1;			// enable interrupt on negative edge on pin A0	
	
   	TRISBbits.TRISB5 = 1;			// Set as pulled up digital inputs
   	WPUBbits.WPUB5 = 1;	
   		
	TMR4IE = 0;						// Disable Timer4 interrupts 
	TMR6IE = 0;						// Disable Timer6 interrupts 

    FVRCON = 0;						// Disable voltage reference
    IOCIE = 1;						// Enable I/O interrupts
    
//*************************************************************************************     	  				
	SLEEP();						// processor goes into sleep mode and clears watchdog
//*************************************************************************************				
	NOP();
	IOCIE = 0;
	SBUS_Init();
	PWM_Init();
	PushButtons_Init();
	NightSense_Init();
					
	ConfirmCommand();
}
コード例 #13
0
// --------------------------------------------------
// Initialization of the backlight LCD. Using PWM.
void Init_LCD_BackLight(void)
{
    uint32_t pclk;
	PWM_TIMERCFG_Type PWMCfgDat;
	PWM_MATCHCFG_Type PWMMatchCfgDat;

	pclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
	PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL;
	PWMCfgDat.PrescaleValue = 1;
	PWM_Init(LCD_BL_PWM_PERI_ID, PWM_MODE_TIMER, (void *) &PWMCfgDat);
	PINSEL_ConfigPin(LCD_BL_PWM_PORT, LCD_BL_PWM_PIN, 1);		// funct.no.1 - PWM1[2] — Pulse Width Modulator 1, channel 2 output.
	PWM_MatchUpdate(LCD_BL_PWM_PERI_ID, LCD_BL_PWM_PERI_CHA, pclk / LCD_BL_PWM_BASE, PWM_MATCH_UPDATE_NOW);

	// UPDATE VALUE OF THE PWM DUTY CYCLE
	PWM_MatchUpdate(LCD_BL_PWM_PERI_ID, LCD_BL_PWM_PERI_CHB , 0 *(( pclk / LCD_BL_PWM_BASE) / 100), PWM_MATCH_UPDATE_NOW); // switch off backlight
	PWMMatchCfgDat.IntOnMatch = DISABLE;							// without interrupt
	PWMMatchCfgDat.MatchChannel = LCD_BL_PWM_PERI_CHB;			// Match channel register - duty cycle	- xx %
	PWMMatchCfgDat.ResetOnMatch = DISABLE;						//
	PWMMatchCfgDat.StopOnMatch = DISABLE;
	PWM_ConfigMatch(LCD_BL_PWM_PERI_ID, &PWMMatchCfgDat);		// store it
	PWM_ChannelCmd(LCD_BL_PWM_PERI_ID, LCD_BL_PWM_PERI_CHB, ENABLE);	// Enable PWM Channel Output

	PWM_ResetCounter(LCD_BL_PWM_PERI_ID);						// reset and start counter
	PWM_CounterCmd(LCD_BL_PWM_PERI_ID, ENABLE);					// start PWM Counter
	PWM_Cmd(LCD_BL_PWM_PERI_ID, ENABLE);						// start PWM
}
コード例 #14
0
ファイル: Principal_3.c プロジェクト: kostaman/insacortexdev
//=======================================================================================
int main(void)
{


Puissance=0;
UpDown=0;
PWM_Init(4, 4, 20.0, 8000.0 );
Port_IO_Init('B', 9, 'o', 2);

Port_IO_Init('B', 8, 'o', 0);
Port_IO_Init('B', 10, 'i', 2);
Port_IO_Init('B', 11, 'i', 2);
Port_IO_Init('B', 12, 'i', 2);
Port_IO_Init('B', 13, 'i', 2);
Port_IO_Init('B', 14, 'i', 2);
Port_IO_Init('B', 15, 'i', 2);



// Gestion du Systick
Systick_Prio_IT(2);
Systick_Period(8.0,20000.0); // 20ms seconde
SysTick_CkSource_ProcessorClk;
SysTick_Enable_IT;
SysTick_On;

while(1)
{

}
	
}
コード例 #15
0
ファイル: LowerLevelFinal7.c プロジェクト: rmolin88/robotBody
int main(void)
{
	stdout = &mystdout;
	general_init();
	UART_INIT();
	PWM_Init();
	ADC_Init();
	
	_delay_ms(250);
	Interrupt_Init();
	
	//beep();
	printf("Initialization Complete\n");
	
	for(;;){
		if(Serial_Finish){
			serialDecodify();
			
			actuateMotors();
			//sonarRead();
			//if( (sonarReading0 < 1000) | (sonarReading1 < 1000) | (sonarReading2 < 1000)) sonarReading0 = sonarReading1 = sonarReading2 = 1000;
			//printf("%u%u%u", sonarReading0, sonarReading1, sonarReading2);		//might get an error here because needs interrupts to send data through UART
			ledCounter--;
			if(!ledCounter){
				toggle_leds();
				ledCounter = 5;
			}
		}
	}
}
コード例 #16
0
ファイル: example_pwm.c プロジェクト: ddavidebor/PicLib
void main(void)
{
	//initialize portc
	PORTC = 0x00;
	TRISC = 0x00;
	
	//initialize pwm
	PWM_Init(5000); //initialize pwm at 5khz
	PWM1_Duty(0); //set initial duty cycle at 0 on pin RC2
	PWM2_Duty(0); 
	
	//start pwm
	PWM1_Start();
    PWM2_Start();
	
	
	while (1)
	{
	
		for (int i=0; i<1023; i+=4)
		{
			PWM1_duty();
			PWM2_Duty(1023-i);
			__delay_ms(2);
		}
	
	
	}


}
コード例 #17
0
ファイル: platform.c プロジェクト: ARMinARM/elua
// Helper function: set timer clock
u32 platform_pwm_set_clock( unsigned id, u32 clock )
{
  PWM_TIMERCFG_Type PWMCfgDat;
  
  PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_USVAL;
  PWMCfgDat.PrescaleValue = 1000000ULL / clock;
  PWM_Init( LPC_PWM1, PWM_MODE_TIMER, &PWMCfgDat );

  return clock;
}
コード例 #18
0
ファイル: main.c プロジェクト: danbao/SmartCar
void main(void) 
{
  EnableInterrupts;
  setbusclock();
  SCI_Init();
  PWM_Init();
  DDRB=0xff;
  for(;;)   {
  }
}
コード例 #19
0
ファイル: driveMotor.c プロジェクト: JustinEwing/R2BJT2
uint8_t initMotors() {
    PWM_Init();
    PWM_SetFrequency(PWM_FREQ);

    //set I/O direction for h-bridge directions pins
    RIGHT_MOTOR_PIN_DIR = OUTPUT;
    LEFT_MOTOR_PIN_DIR = OUTPUT;

    return (PWM_AddPins(LEFT_MOTOR_ENABLE | RIGHT_MOTOR_ENABLE));
}
コード例 #20
0
ファイル: pwm.c プロジェクト: jnugen/robus
void pwm_init(void)
{
	PWM_TIMERCFG_Type PWMCfgDat;
	PWM_MATCHCFG_Type PWMMatchCfgDat;
	PINSEL_CFG_Type PinCfg;

	/* Initialize PWM peripheral, timer mode
	 * PWM prescale value = 1 (absolute value - tick value) */
	PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL;
	PWMCfgDat.PrescaleValue = 500;
	PWM_Init(LPC_PWM1, PWM_MODE_TIMER, (void *) &PWMCfgDat);

	/* Initialize PWM pin connect for PWM1[4] on P2[3] */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 2;
	PinCfg.Pinnum = (EN_PWM_CHN - 1);	// hack
	PINSEL_ConfigPin(&PinCfg);

	/* Set match value for PWM match channel 0 = 256, update immediately */
	PWM_MatchUpdate(LPC_PWM1, 0, 256, PWM_MATCH_UPDATE_NOW);

	/* PWM Timer/Counter will be reset when channel 0 matching
	 * no interrupt when match
	 * no stop when match */
	PWMMatchCfgDat.IntOnMatch = DISABLE;
	PWMMatchCfgDat.MatchChannel = 0;
	PWMMatchCfgDat.ResetOnMatch = ENABLE;
	PWMMatchCfgDat.StopOnMatch = DISABLE;
	PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);

	/* Configure PWM channel edge option for EN_PWM_CHN */
	PWM_ChannelConfig(LPC_PWM1, EN_PWM_CHN, PWM_CHANNEL_SINGLE_EDGE);

	/* Set initial match value for EN_PWM_CHN to disable output change */
	PWM_MatchUpdate(LPC_PWM1, EN_PWM_CHN, 0, PWM_MATCH_UPDATE_NOW);

	/* Configure match option for EN_PWM_CHN*/
	PWMMatchCfgDat.IntOnMatch = DISABLE;
	PWMMatchCfgDat.MatchChannel = EN_PWM_CHN;
	PWMMatchCfgDat.ResetOnMatch = DISABLE;
	PWMMatchCfgDat.StopOnMatch = DISABLE;
	PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);

	/* Enable PWM Channel Output for EN_PWM_CHN */
	PWM_ChannelCmd(LPC_PWM1, EN_PWM_CHN, ENABLE);

	/* Reset and Start counter */
	PWM_ResetCounter(LPC_PWM1);
	PWM_CounterCmd(LPC_PWM1, ENABLE);

	/* Start PWM now */
	PWM_Cmd(LPC_PWM1, ENABLE);
}
コード例 #21
0
ファイル: PWM.c プロジェクト: thurstonzhu/ELE302-Carlab
/*******************************************************************************
* Function Name: PWM_Start
********************************************************************************
*
* Summary:
*  The start function initializes the pwm with the default values, the 
*  enables the counter to begin counting.  It does not enable interrupts,
*  the EnableInt command should be called if interrupt generation is required.
*
* Parameters:  
*  None  
*
* Return: 
*  None
*
* Global variables:
*  PWM_initVar: Is modified when this function is called for the 
*   first time. Is used to ensure that initialization happens only once.
*
*******************************************************************************/
void PWM_Start(void) 
{
    /* If not Initialized then initialize all required hardware and software */
    if(PWM_initVar == 0u)
    {
        PWM_Init();
        PWM_initVar = 1u;
    }
    PWM_Enable();

}
コード例 #22
0
void initMoteur()
{
	//Init GPIO
	Port_IO_Init_Output(GPIOA, 2); // PA2 (sens)
	Port_IO_Init_Alternate_Output(GPIOA, 1); // PA1 [PWM] (puissance)
	
	//Configure TIMER
	PWM_Init(TIM2, 2, 10);
	
	commandeMoteur(0);
}
コード例 #23
0
ファイル: motor.c プロジェクト: Guerric/Drone_project
void configure_motor(GPIO_TypeDef* Port, u8 Pin, TIM_TypeDef * Timer, u8 Channel){
	//init clocks
	Port_IO_Init_Clock (Port);
	Timer_Init_Clock (Timer);
	
	//setting output pin as alternate function push pull
	Port_IO_Init_Output (Port, Pin, AF_PUSHPULL, OUT_10MHZ);
	
	//start pwm on the defined channel
	PWM_Init (Timer, Channel, MOTOR_PWM_FREQ);
}
コード例 #24
0
ファイル: main.c プロジェクト: jackeyjiang/3DPrinter-firmware
static void periphInit()
{
	USART_Config(BT_USART, BT_BaudRate);
	FileManager_Init();
	PWM_Init(HEATER_PWM_FREQ);
	Move_Init();
	Extruder_Init();
	HeatBed_Init();
	USBDevice_Config();
	Command_Init();
	HostCtrl_Init();
}
コード例 #25
0
ファイル: main.c プロジェクト: nowhard/LED_LAMP
int main(void)
{
	SystemInit();

	PWM_Init();//инициализация шим
	IR_Control_Init();//инициализация ик управления
	Vibration_Init();//инициализация вибродатчика
	Effects_Init();//инициализация световых эффектов

    vTaskStartScheduler();

    while(1);
}
コード例 #26
0
void Drive_Init(void)
{
	// Configure PWM components
	PWM_Init();
	PWM_SetFrequency(PWM_BOT_FREQUENCY);

	// Add motor pins
	PWM_AddPins(MOTOR_PINS_LEFT_EN | MOTOR_PINS_RIGHT_EN | MOTOR_PINS_LIFT_EN);

	// Configure direction pins
	IO_PortsSetPortOutputs(MOTOR_PINS_PORT, MOTOR_PINS_RIGHT_DIR | MOTOR_PINS_LEFT_DIR |
		MOTOR_PINS_LIFT_DIR);
}
コード例 #27
0
ファイル: buzzer.c プロジェクト: Blue-Design/R2C2_Firmware
static void buzzer_pwm_set_frequency (uint16_t frequency)
{
  uint32_t match_value = (((float) 1/frequency)) * 1000000;

  PWM_TIMERCFG_Type PWMCfgDat;
  PWM_MATCHCFG_Type PWMMatchCfgDat;

  /* PWM block section -------------------------------------------- */
  /* Initialize PWM peripheral, timer mode
   * PWM prescale value = 1 (absolute value - tick value) */
  PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_USVAL;
  PWMCfgDat.PrescaleValue = 1;
  PWM_Init(LPC_PWM1, PWM_MODE_TIMER, (void *) &PWMCfgDat);

  /* Set match value for PWM match channel 0 = match_value, update immediately */
  PWM_MatchUpdate(LPC_PWM1, 0, match_value, PWM_MATCH_UPDATE_NOW);
  /* PWM Timer/Counter will be reset when channel 0 matching
   * no interrupt when match
   * no stop when match */
  PWMMatchCfgDat.IntOnMatch = DISABLE;
  PWMMatchCfgDat.MatchChannel = 0;
  PWMMatchCfgDat.ResetOnMatch = ENABLE;
  PWMMatchCfgDat.StopOnMatch = DISABLE;
  PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);

  /* Configure PWM channel: --------------------------------------------- */
  /* - Single edge
   * - PWM Duty on each PWM channel determined by
   * the match on channel 0 to the match of that match channel.
   * Example: PWM Duty on PWM channel 1 determined by
   * the match on channel 0 to the match of match channel 1.
   */

  /* Configure PWM channel edge option
   * Note: PWM Channel 1 is in single mode as default state and
   * can not be changed to double edge mode */
  PWM_ChannelConfig(LPC_PWM1, 3, PWM_CHANNEL_SINGLE_EDGE);

  /* Set up match value */
  PWM_MatchUpdate(LPC_PWM1, 3, match_value/2, PWM_MATCH_UPDATE_NOW);
  /* Configure match option */
  PWMMatchCfgDat.IntOnMatch = DISABLE;
  PWMMatchCfgDat.MatchChannel = 3;
  PWMMatchCfgDat.ResetOnMatch = DISABLE;
  PWMMatchCfgDat.StopOnMatch = DISABLE;
  PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);
  /* Enable PWM Channel Output */
  PWM_ChannelCmd(LPC_PWM1, 3, ENABLE);
}
コード例 #28
0
//--------------------------------------------------------------------------------------------------------
void System_Init(void)
{
  GPIO_Init();
  UART_Init();
  ADC_Init();
  PIT_Init();
  PWM_Init();
  LED_Init();
  InitFlashLed();
  //----------进入按键调参--------
  SetLED();
  
  //---------初始化全局变量-------
  CarControlStop();
  

  
  
  g_nCarCount=0;
  g_nSpeedControlCount=0;
  g_nSpeedControlPeriod=0;
  g_nDirectionControlCount=0;
  g_nDirectionControlPeriod=0;
  
  g_fAngleControlOut=0;
  
  g_nLeftMotorPulse=0;
  g_nRightMotorPulse=0;
  g_fCarSpeed=0;
  g_fSpeedControlOutNew=0;
  g_fSpeedControlOutOld=0;
  g_fSpeedControlIntegral=0;
  g_fSpeedControlOut=0;
  
  VOLTAGE_RIGHT=0;
  VOLTAGE_LEFT=0; 
  DIR_LEFT_OFFSET=0;
  DIR_RIGHT_OFFSET=0;
  g_fDirectionControlOutP=0;
  g_fDirectionControlOutD=0;
  g_fDirectionControlOutOld=0;
  g_fDirectionControlOutNew=0;
  g_fDirection=0;
  g_nDirectionGyro=0;
  g_fDirectionControlOut=0;
  
  g_fLeftMotorOut=0;
  g_fRightMotorOut=0;
}
コード例 #29
0
/***************************************************************************************************
                         void PWM_Start(uint32_t pin)
 ****************************************************************************************************
 * I/P Arguments: none.
 * Return value    : none

 * description :This function is used to start the pwm generation..
 ***************************************************************************************************/
void PWM_Start(uint32_t pin)
{
    uint32_t pinSelect=0;   


    if(pwmInitDoneFlag_u32 == 0)
    {
        PWM_Init(PWM_CYCLE);   // Set the PWM_CYCLE to 255 if user has not called the PWM_Init function.
        pwmInitDoneFlag_u32 = 1;
    }  

    pin = pin & PWM_CHANNEL_MASK; /* Ensure only supported channel bits are set */

    while(pin)
    {
        pinSelect = ((~pin)+1) & pin; /* Extract the first bit  from left side */
        pin = pin & (~pinSelect);     /* Clear the Bit after extracting, as it is being processed now*/

        switch(pinSelect)
        {
        case PWM_1:
            LPC_PWM1->PCR |= PWMENA1; 
            break;

        case PWM_2:
            LPC_PWM1->PCR |= PWMENA2;             
            break;

        case PWM_3:
            LPC_PWM1->PCR |= PWMENA3;
            break;

        case PWM_4:
            LPC_PWM1->PCR |= PWMENA4;
            break;

        case PWM_5:
            LPC_PWM1->PCR |= PWMENA5;
            break;

        case PWM_6:
            LPC_PWM1->PCR |= PWMENA6;
            break;

        default :
            break;            
        }
    }   
}
コード例 #30
0
ファイル: LcdDriver.c プロジェクト: chen1990/wsnlab
void HAL_LCD_initDisplay(void)
{
	GPIO_Init();
	usleep(100000);
	HAL_LCD_enableDisplay();
	usleep(100000);
	SPI_Init();
	usleep(100000);
	PWM_Init();
	usleep(100000);

	PWM_Run();

	Display_Init();
}