Пример #1
0
/*=====================================================================================================*/
int main( void )
{
  u32 i = PWM_MOTOR_MIN;

  SystemInit();
  GPIO_Config();
  PWM_Config();

  while(1) {
    LED_G = ~LED_G;

    while(KEY_WU == 1) {
      PWM1  = i;
      PWM2  = i;
      PWM3  = i;
      PWM4  = i;
      PWM5  = i;
      PWM6  = i;
      PWM7  = i;
      PWM8  = i;
      PWM9  = i;
      PWM10 = i;
      PWM11 = i;
      i++;
      if(i>=PWM_MOTOR_MAX) {
        i = PWM_MOTOR_MIN;
        LED_R = ~LED_R;
      }
      Delay_1us(500);
    }

    Delay_10ms(10);
  }
}
Пример #2
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint16_t pulse_width = 0;
  /* TIM Configuration */
  TIM_Config();
  /* LED Configuration */
  LED_Config();
  /* PWM Configuration */
  PWM_Config(MAX_PERIOD);

  PWM_SetDC(1,100);
  PWM_SetDC(2,100);
  PWM_SetDC(3,100);
  PWM_SetDC(4,100);
  while (1)
  {
    /* PD12 to be toggled */
//    GPIO_ToggleBits(GPIOD, GPIO_Pin_13);
    PWM_SetDC(1,pulse_width++);
    if (pulse_width > MAX_PERIOD / 10)
    {
      pulse_width = MAX_PERIOD / 20;
    }
    Delay(900000);
  }
}
/*=====================================================================================================*/
int main( void )
{
  u16 freq = PWM_FREQ_MIN;
	u16 duty = PWM_DUTY_MAX_205k;
	u8 state = STATE_FREQ;
	
  GPIO_Config();
  PWM_Config();

  while(1) {
    LED_G = ~LED_G;

    if(KEY_WU == 1){
			if(state == STATE_FREQ){
				freq++;
			  if(freq>=PWM_FREQ_MIN){
          freq = PWM_FREQ_MIN;
          LED_R = ~LED_R;
        }
        FREQ = freq-1;
		  	PWM1 = freq>>1;
      }else if(state == STATE_DUTY){
				duty++;
				if(duty>= PWM_DUTY_MAX_205k){
					duty = PWM_DUTY_MAX_205k;
					state = STATE_FREQ;
				}
				PWM1 = duty;
			}
			Delay_1ms(10);
    }else if(KEY_BO == 1){
/*=====================================================================================================*/
int main( void )
{
	u32 i = PWM_MOTOR_MIN;

	SystemInit();
	GPIO_Config();
	PWM_Config();

//	PWM1  = PWM_MOTOR_MIN;
//	PWM2  = PWM_MOTOR_MIN;
//	PWM3  = PWM_MOTOR_MIN;
//	PWM4  = PWM_MOTOR_MIN;
//	PWM5  = PWM_MOTOR_MIN;
//	PWM6  = PWM_MOTOR_MIN;
//	PWM7  = PWM_MOTOR_MIN;
//	PWM8  = PWM_MOTOR_MIN;
//	PWM9  = PWM_MOTOR_MIN;
//	PWM10 = PWM_MOTOR_MIN;
//	PWM11 = PWM_MOTOR_MIN;
//	PWM12 = PWM_MOTOR_MIN;

  while(1) {
    LED_G = ~LED_G;

		while(KEY == 1) {
			PWM1  = i;
			PWM2  = i;
			PWM3  = i;
			PWM4  = i;
			PWM5  = i;
			PWM6  = i;
			PWM7  = i;
			PWM8  = i;
			PWM9  = i;
			PWM10 = i;
			PWM11 = i;
			PWM12 = i;
			i++;
			if(i>=PWM_MOTOR_MAX) {
				i = PWM_MOTOR_MIN;
				LED_R = ~LED_R;
			}
			Delay_100us(5);
		}

    Delay_100ms(1);
	}
}
/************************MAIN*********************************************/
int main(void)
{
	TIM_Config();
	PWM_Config();
	UART1_DMA_CONFIG(txbuffer,txsize,rxbuffer,rxsize,57600);
	USART_config ();
	Zero_state ();
	if (SysTick_Config(SystemCoreClock / SysTick_interval)) // systick_interrupt occur every 0.1 ms (1000=1ms)
  {/* Capture error */ while (1);}
	while (1)
	{
		//control signal
		X360_button ();
		X360_Y1_Analog();
	}
}
Пример #6
0
void init_platform(void) {
	MP._Lspeed = 100;
	MP._Rspeed = 100;
	MP._state = 0;
	MP._flags = 0;


	MP._left_side._forward_pin 		= GPIO_Pin_11;
	MP._left_side._backward_pin 	= GPIO_Pin_9;
	MP._left_side._calibrate_speed 	= 0.945;
	MP._left_side._state 			= 0;

	MP._right_side._forward_pin 	= GPIO_Pin_10;
	MP._right_side._backward_pin 	= GPIO_Pin_12;
	MP._right_side._calibrate_speed = 1;
	MP._right_side._state 			= 0;

	MP._rotary_driver_state			= 0;
	MP.rotary_driver_ticks			= 0;
	MP.rotary_driver_target_ticks	= 0;

	//Orders
	MP.completed_order = 0;

	//Heading
	MP.heading_state = PLATFORM_HEADING_YNEG;
	MP.x_max 		 = 664; //682
	MP.y_max 		 = 304;
	MP.x_pos 		 = 1;
	MP.y_pos 		 = 151;

	//Adjust
	MP.adjust_state = 0;

	orderComplete=0;
	timer=0;

	//uint16_t pulse_width = 0;
	/* TIM Configuration */
	TIM_Config();
	/* PWM Configuration */
	PWM_Config(1000);

}
int main(void) 
{
	/* Init */
	TIM_Config();
	PWM_Config();
	ENC_Config();
	UART_DMA_CONFIG(txbuffer,txsize,rxbuffer,rxsize,57600);
	USART_config ();
	/* MPU 1 */
	MPU6050_Status = TM_MPU6050_Init(&MPU6050_Data0, TM_MPU6050_Device_0, TM_MPU6050_Accelerometer_2G, TM_MPU6050_Gyroscope_250s);
	Delay (200);
	/* MPU2 */
	//I2C_Config();
	//MPU_Config(MPU_Adress);
	//MPU_Wake(MPU_Adress);
	
	if (SysTick_Config(SystemCoreClock / 1000))
  {/* Capture error */ while (1);}
	
	while (1);	
}
Пример #8
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */     
  
  if (SysTick_Config(SystemCoreClock / 1000))
  { 
    /* Capture error */ 
    while (1);
  }
  
  //All Init here
  
  led_init();
  usart_init();
  
  TIM_Config();
  PWM_Config();
  EnableInterrupt();

  while (1)
  {
    /*
    if((asn % N_TIME_SLOT == TSLOT_ID) && (ts_enable_transmision == 1))
    {
      ts_enable_transmision = 0;
      
      for(int i=0; i < 4; i++)
      {
        while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
        USART_SendData(USART1, message[i]);
      }
    }*/
      
  }
}
Пример #9
0
/*=====================================================================================================*/
int main( void )
{
  uint32_t i = PWM_MOTOR_MIN;

  GPIO_Config();
  PWM_Config();

  while(1) {
    LED_G = !LED_G;

    if(KEY_BO == 1) {
      PWM1  = PWM_MOTOR_MIN;
      PWM2  = PWM_MOTOR_MIN;
      PWM3  = PWM_MOTOR_MAX;
      PWM4  = PWM_MOTOR_MAX;
    }
      
    while(KEY_WU == 1) {
      PWM1  = i;
      PWM2  = i;
      PWM3  = i;
      PWM4  = i;
      PWM5  = i;
      PWM6  = i;
      PWM7  = i;
      PWM8  = i;
      PWM9  = i;
      PWM10 = i;
      PWM11 = i;
      i++;
      if(i >= PWM_MOTOR_MAX) {
        i = PWM_MOTOR_MIN;
        LED_R = !LED_R;
      }
      Delay_100us(5);
    }

    Delay_100ms(1);
  }
}
Пример #10
0
int main(void)
{
    //uint16_t kezdet, vege;
    vSemaphoreCreateBinary(xADCSemaphore);
    RCC_Config();

    IO_Init();
    UART_Config();
    PWM_Config();
    DMA_Config();
    I2C_Config();
    NVIC_Config();
    DebugTimerInit();

    xTaskCreate(prvInitTask,(signed char*)"INIT", configMINIMAL_STACK_SIZE,NULL,TASK_INIT_PRIORITY,NULL);

    vTaskStartScheduler();
    while (1)
    {



    }
}
Пример #11
0
/*=====================================================================================================*/
int main( void )
{
  GPIO_Config();
	PWM_Config();
	ADC_Config();
  TIM_Config();
	
  while(1) {
		
		if(KEY_WU==1){
			while(KEY_WU==1);
			Kp+=1;
			if(Kp>=20) Kp = 0;
			Delay_10ms(2);
    }
		if(KEY_BO==1){
			while(KEY_BO==1);
			Kd+=0.1;
			if(Kd>=5) Kd = 0;
			Delay_10ms(2);
    }
    
  }
}
Пример #12
0
/**
	 * @brief Main thread of computation running in superloop to update sensor data and transmit
	 * and also subsequently run logic for PWM LED display and double tap detection
	 * @param void
   */
int main(void){	
		
	/* INITIALIZE SYSTEM CLOCK AND PERIPHERALS */
  HAL_Init();
  SystemClock_Config();	
	SPI_Init1();
	MEMS_Config();
	MEMS_Config_IT();
	ADC_Config();
	LED_Config();
	PWM_Config();
	
	/* CONFIG FOR PWM */
	#ifdef LED_SPEED_SLOWER
		speed = 1500;
	#endif

	#ifdef LED_SPEED_SLOW
		speed = 1000;
	#endif

	#ifdef LED_SPEED_MEDIUM
		speed = 800;
	#endif

	#ifdef LED_SPEED_FAST
		speed = 400;
	#endif

	#ifdef LED_SPEED_FASTER
		speed = 200;
	#endif			
	
	#ifdef LED_ALL_ON
		speed = 100;
	#endif
	
	/* CONFIG FOR DOUBLE TAP */
	counter2 = 0;
	thresh1 = 1300;
	assert1 = 0;
	assert2 = 0;
	assertFall = 0;
	assertRise2 = 0;
	assertDoubleTap = 0;
	
	/* BEGIN SUPERLOOP */
	while(1){
		
		/* SET SAMPLING DELAY FOR SENSORS */
		if(interrupt != 0){
			interrupt = 0;
			get_readings();			
		}		
		
		/* TRANSMIT SENSOR DATA TO MASTER */
		HAL_SPI_Transmit(&SpiHandle_2, txBuffer, 4, 10000);				
		
		/* LOGIC FOR IMPLEMENTING PWM DISPLAY LED */
		pwm_display();		
		
		/* LOGIG FOR IMPLEMENTING DOUBLE TAP DETECTION */
		double_tap();
	}
}
Пример #13
0
void Pulse_Config (void) {
	// Run timer config and initialise pulses to 50:50 duty cycle
	TIM3_Config();
	PWM_Config(TIM3_ARR);
}
Пример #14
0
uint8_t Servo::attach(int ulPin, int min, int max, int freq)
{      
	uint32_t ulValue=0;
	bpwm = 0;
	
	#ifdef USE_BoardToPin
	if(ulPin > BoardToPin_MAX_COUNT) return 0;
	
	if(ulPin > 5 && ulPin < 10) { // BPWM pins - 6, 7, 8, 9
		bpwm = 1;
	}
	
	if(ulPin > 17 && ulPin < 22) { // PWM at analog pins - A0, A1, A2, A3
		ulPin = ulPin + 8;
	}
	
	if(BoardToPinInfo[ulPin].type!=PWM_TYPE) return 0;
	
	ulPin=BoardToPinInfo[ulPin].num;
	
	if(bpwm) {
		if(ulPin > BPWM_MAX_COUNT || BPWM_Desc[ulPin].P == NULL) return 0;
	}
	else {
		if(ulPin  > PWM_MAX_COUNT || PWM_Desc[ulPin].P == NULL) return 0;
	}
	#else
		return 0;
	#endif	
	
	if(bpwm) 
	{
		BPWM_Config(BPWM_Desc[ulPin]); // Set Mutifunction pins
		BPWM_ConfigOutputChannel(BPWM_Desc[ulPin].P, BPWM_Desc[ulPin].ch, BPWM_Desc[ulPin].freq, ulValue); // Config BPWMs
		BPWM_EnableOutput(BPWM_Desc[ulPin].P, (1 << BPWM_Desc[ulPin].ch)); //Enable BPWM output
		BPWM_Start(BPWM_Desc[ulPin].P, (1 << BPWM_Desc[ulPin].ch)); //Start BPWM
	}
	
	else 
	{
		PWM_Config(PWM_Desc[ulPin]); // Set Mutifunction pins
		PWM_ConfigOutputChannel(PWM_Desc[ulPin].P, PWM_Desc[ulPin].ch, PWM_Desc[ulPin].freq, ulValue); // Config PWMs
		PWM_EnableOutput(PWM_Desc[ulPin].P, (1 << PWM_Desc[ulPin].ch)); //Enable PWM output
		PWM_Start(PWM_Desc[ulPin].P, (1 << PWM_Desc[ulPin].ch)); //Start PWM
	}
	
	Servo_MAX = max;
	Servo_MIN = min;
	Servo_Pin = ulPin;
	Servo_Freq = freq;
				
/*
#if defined(__M451__)
	if(ulValue==100)
	{  
		int32_t pin=PWM_Desc[ulPin].pintype.num;
		GPIO_Config(GPIO_Desc[pin]);
		GPIO_SetMode(GPIO_Desc[pin].P, GPIO_Desc[pin].bit, GPIO_MODE_OUTPUT);
		(GPIO_Desc[pin].P)->DOUT |= GPIO_Desc[pin].bit;
		pinEnabled[ulPin]= 0;
		fixValue[ulPin]=ulValue;
		//return 0;
	}
#elif defined(__NUC240__)
	if(ulValue==0)
	{  
		int32_t pin=PWM_Desc[ulPin].pintype.num;
		GPIO_Config(GPIO_Desc[pin]);
		GPIO_SetMode(GPIO_Desc[pin].P, GPIO_Desc[pin].bit, GPIO_PMD_OUTPUT);
		(GPIO_Desc[pin].P)->DOUT &= ~GPIO_Desc[pin].bit;
		pinEnabled[ulPin]= 0;
		fixValue[ulPin]=ulValue;
		//return 0;
	}
#elif defined(__NANO100__) | defined(__NANO1X2__)
	if(ulValue==0)
	{  
		int32_t pin=PWM_Desc[ulPin].pintype.num;
		GPIO_Config(GPIO_Desc[pin]);
		GPIO_SetMode(GPIO_Desc[pin].P, GPIO_Desc[pin].bit, GPIO_PMD_OUTPUT);
		(GPIO_Desc[pin].P)->DOUT &= ~GPIO_Desc[pin].bit;
		pinEnabled[ulPin]= 0;
		fixValue[ulPin]=ulValue;
		//return 0;
	}
#elif defined(__NUC131__)

	if(ulValue==0)
	{  
		uint32_t pin = PWM_Desc[ulPin].pintype.num;
		GPIO_Config(GPIO_Desc[pin]);
		GPIO_SetMode(GPIO_Desc[pin].P, GPIO_Desc[pin].bit, GPIO_PMD_OUTPUT);
		(GPIO_Desc[pin].P)->DOUT &= ~GPIO_Desc[pin].bit;
		pinEnabled[ulPin]= 0;
		fixValue[ulPin]=ulValue;
		//return 0;
	}
#endif

	if (!pinEnabled[ulPin]){
		//Set Mutifunction pins

		PWM_Config(PWM_Desc[ulPin]);		
    
		//Config PWMs
		PWM_ConfigOutputChannel(PWM_Desc[ulPin].P,PWM_Desc[ulPin].ch,50,0);
		
		//Enable PWM output
		PWM_EnableOutput(PWM_Desc[ulPin].P,(1<<PWM_Desc[ulPin].ch));
		
		//Start PWM
		PWM_Start(PWM_Desc[ulPin].P,(1<<PWM_Desc[ulPin].ch));
		
		pinEnabled[ulPin] = 1;
	}
	
	//Config PWMs		
	if(fixValue[ulPin]!=ulValue)
	{
		PWM_ConfigOutputChannel(PWM_Desc[ulPin].P,PWM_Desc[ulPin].ch,50,ulValue);
		fixValue[ulPin]=ulValue;
	}
*/

}
Пример #15
0
Файл: main.c Проект: jwag/BCI
//***************************************************************************************
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
        system_stm32f4xx.c file
     */

  /* Initialize Leds mounted on STM32F4-Discovery board */
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED5);
  STM_EVAL_LEDInit(LED6);

  init_USART1(9600); // initialize USART1 @ 9600 baud

  char hello[]  = "Init complete! Hello World!/n";
  USART_puts_chars(USART1, hello); // just send a message to indicate that it works


  /* ADC3 configuration *******************************************************/
  /*  - Enable peripheral clocks                                              */
  /*  - DMA2_Stream0 channel2 configuration                                   */
  /*  - Configure ADC Channel12 pin as analog input                           */
  /*  - Configure ADC3 Channel12                                              */
  ADC3_CH12_DMA_Config();

  /* Start ADC3 Software Conversion */
  ADC_SoftwareStartConv(ADC3);

  DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE);

  /* TIM Configuration */
  TIM_Config();

  PWM_Config();

  /* Setup SysTick Timer for 1 msec interrupts.
     ------------------------------------------
    1. The SysTick_Config() function is a CMSIS function which configure:
       - The SysTick Reload register with value passed as function parameter.
       - Configure the SysTick IRQ priority to the lowest value (0x0F).
       - Reset the SysTick Counter register.
       - Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
       - Enable the SysTick Interrupt.
       - Start the SysTick Counter.

    2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
       SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
       SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
       inside the misc.c file.

    3. You can change the SysTick IRQ priority by calling the
       NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function
       call. The NVIC_SetPriority() is defined inside the core_cm4.h file.

    4. To adjust the SysTick time base, use the following formula:

         Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)

       - Reload Value is the parameter to be passed for SysTick_Config() function
       - Reload Value should not exceed 0xFFFFFF
   */
  if (SysTick_Config(SystemCoreClock / (6250)))
  {
    /* Capture error */
    while (1);
  }

  set_PWM_duty( 75, LEFT_LED_880);
  static uint8_t duty_cycle = 0;
  while (1)
  {
    /* Toggle LED3 and LED6 */
    //STM_EVAL_LEDToggle(LED3);
    //Delay(100);
    STM_EVAL_LEDToggle(LED4);
    Delay(100);
    STM_EVAL_LEDToggle(LED6);
    Delay(100);
    STM_EVAL_LEDToggle(LED5);
    Delay(100);
  }
}
Пример #16
0
void main(void)
{
    /* Clock configuration -----------------------------------------*/
    CLK_Config();  
    /* GPIO configuration ------------------------------------------*/
    GPIO_Config_Init();
    UART1_Config();
    UART3_Config();
    PWM_Config();
    TIM2_Config();
    TIM3_Config();
    TIM4_Config();
    
    I2C_RTC_Init();
    /* Enable general interrupts */  
    enableInterrupts();
                  //【秒, 分, 时, 日, 星期, 月, 年】
    uint8_t time[] = {00, 12, 10, 1, 1, 6, 15};
    //Set_RT8563(time, 2, 7);
    ResetNetMode();
#if 0
    uint8_t Alarm[5][3] = {1, 16, 31, 1, 16, 33, 1, 16, 35};
    uint8_t Time[7] = {0};
    uint8_t AlarmState = 0;
    uint8_t AlarmDelay = 1;
    unsigned int NET_AUTO_SEND = 0;
#endif
    
    while (1)
    {
#if 0
        Delay(1000);
        Send_BAT_Voltage(Get_BAT_Value());
        UART3_SendString("\n", 1);
        AQI2PM25(Get_DS_Value());
#endif      
        if(DeviceStatus.Time_30ms == 1)
        {
            TouchKey_Read();
            DeviceStatus.Time_30ms = 0;
        }
        if(DeviceStatus.Time_100ms == 1)
        {
            if(UART1_GetFlagStatus(UART1_FLAG_IDLE) == SET)
            {
                if(DataSize != 0)
                {
                    DataResolve(RxRecvBuffer, DataSize); 
                    NetProcess();
                    DataSize = 0;
                }
            }
            DeviceStatus.Time_100ms = 0;
        }
        if(DeviceStatus.Time_1_s == 1)
        {
            Get_RT8563(time, 2, 7);
#if 0
            ArrayCopy((uint8_t *)&NetMode.SendData, time, 7);
            UART3_SendString((uint8_t *)&NetMode.SendData, 7);
            if(NetMode.Status & NET_CONNECT)    
            {
                NET_LED_FLASH;
                NET_AUTO_SEND++;
                if(NET_AUTO_SEND == 10)//自动发送数据
                {
                    NetSendDataLength();
                    
                    NET_AUTO_SEND = 0;
                }
            }
            else NET_AUTO_SEND = 0;
#endif
            
            DeviceStatus.Time_1_s = 0;
        }

        if(DeviceStatus.Time_30_s == 1)
        {
            NetModeErrorFix();
            DeviceStatus.Time_30_s = 0;
        }
#if 0
        GetTime(Time);
        if(ArrayCMP(Alarm, Time, 3) == 0 && AlarmState == 0) 
        {
            GPIO_WriteHigh(GPIOF, GPIO_PIN_5);
            FAN_SPEED_HIGH; //高速
            Alarm[2] += AlarmDelay;
            AlarmState = 1;
        }
        else if(ArrayCMP(Alarm, Time, 3) == 0 && AlarmState == 1)
        {
            GPIO_WriteLow(GPIOF, GPIO_PIN_5);
            FAN_SPEED_OFF;
            AlarmState = 0;
            Alarm[2] -= AlarmDelay;
        }
#endif
    }
  
}