Exemplo n.º 1
0
void pwmout_free(pwmout_t* obj) {
    TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
  
    HAL_TIM_PWM_DeInit(&TimHandle);
  
    pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));    
}
Exemplo n.º 2
0
Status_t xMotorDeInit(TIM_HandleTypeDef* pxTIMHandle)
{
  if(HAL_TIM_PWM_DeInit(pxTIMHandle) != HAL_OK)
  {
    /* Initialization Error */
    return STATUS_ERROR;
  }

  /* Enable MOTOR_TIMx Clock */
  MOTOR_TIMx_CLK_DISABLE();

  /* Return OK */
  return STATUS_OK;
}
Exemplo n.º 3
0
void CAM_changeClockSpeed(CLOCKSPEED speed)
{
	/* Wait for clock falling edge */
	CAM_waitClockFalling();

	/* Stop the timer */
	HAL_TIM_PWM_Stop_IT(&htim, TIM_CHANNEL_2);
	HAL_TIM_Base_Stop_IT(&htim);

	/* De-initialize the timer */
	HAL_TIM_PWM_DeInit(&htim);
	HAL_TIM_Base_DeInit(&htim);

	/* Re-initialize the timer */
	CAM_TIM_init(speed);

	/* And finally restart it along with PWM */
	HAL_TIM_Base_Start_IT(&htim);					// Providing PeriodElapsed Callback
	HAL_TIM_PWM_Start_IT(&htim, TIM_CHANNEL_2);	// Providing PulseFinished Callback
}
Exemplo n.º 4
0
/**
  * @brief  This function will disable the PWM
  * @param  port : the gpio port to use
  * @param  pin : the gpio pin to use
  * @retval None
  */
void pwm_stop(PinName pin)
{
  TIM_HandleTypeDef timHandle;
  uint32_t timChannel;

  timHandle.Instance = pinmap_peripheral(pin, PinMap_PWM);
  if (timHandle.Instance == NP) return;
  timChannel = get_pwm_channel(pin);
  if (!IS_TIM_CHANNELS(timChannel)) return;

#if !defined(STM32L0xx) && !defined(STM32L1xx)
  if (STM_PIN_INVERTED(pinmap_function(pin, PinMap_PWM))) {
    HAL_TIMEx_PWMN_Stop(&timHandle, timChannel);
  } else
#endif
  {
    HAL_TIM_PWM_Stop(&timHandle, timChannel);
  }

  HAL_TIM_PWM_DeInit(&timHandle);
}
Exemplo n.º 5
0
void ultrasound_generator( uint32_t chanel ){
/* ##-1- Configure the TIM peripheral ****************************************************************************
  TIM2 Configuration: generate 4 PWM signals with 4 different duty cycles.

    In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1),
    since APB1 prescaler is equal to 1.
      TIM2CLK = PCLK1
      PCLK1 = HCLK
      => TIM2CLK = HCLK = SystemCoreClock

    To get TIM2 counter clock at 16 MHz, the prescaler is computed as follows:
       Prescaler = (TIM2CLK / TIM2 counter clock) - 1
       Prescaler = ((SystemCoreClock) /16 MHz) - 1

    To get TIM2 output clock at 24 KHz, the period (ARR)) is computed as follows:
       ARR = (TIM2 counter clock / TIM2 output clock) - 1
           = 665

    TIM2 Channel1 duty cycle = (TIM2_CCR1/ TIM2_ARR + 1)* 100 = 50%
**************************
	20KHz-> Prescaler = ( (48MHz) / 20KHz) - 1=799
	30KHz->	Prescaler = ( (48MHz) / 30KHz) - 1=399
	*/
		SystemClock_Config_48MHz();
		MX_TIM3_Init();
		HAL_TIM_PWM_Init(&htim3);
		sConfigOC.Pulse=0;
	HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 );													///DCDC konverter engedélyezése (+15V)


			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_1);
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_2);
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_3);
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_4);
			HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
			HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
			HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
			HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);

for(int i=400; i < 700; i++){
	//HAL_TIM_PWM_Stop(&htim3,chanel);


	__HAL_TIM_SetAutoreload(&htim3,i*2);
	__HAL_TIM_SetCompare(&htim3,chanel, i);
//HAL_TIM_OC_Init(&htim3);
//TIM_OC2_SetConfig( TIM3, &sConfigOC);
	//HAL_TIM_PWM_Start( &htim3 , chanel );
HAL_Delay(30);
}
	__HAL_TIM_SetCompare(&htim3,chanel, 0);
	HAL_TIM_PWM_Stop( &htim3 , chanel );
	HAL_TIM_PWM_DeInit( &htim3 );
	HAL_TIM_Base_DeInit(&htim3);

		GPIO_TIM3_OFF();
	
		

	HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0);
	SystemClock_Config_8MHz();
	}
Exemplo n.º 6
0
void ultrasound (uint8_t bridge){				//ez a fv egyszerre csak egy hidat hajt meg!
		uint16_t i,old_i,temp_i,f;
	uint32_t CH1,CH2,CHx,CHy,tim,tim_now;

		//bridge1=0,bridge2=1-> hogy melyik hidat hajtsa meg 
	if(bridge){						//bridge1
		CH1=(uint32_t)TIM_CHANNEL_1;
		CH2=(uint32_t)TIM_CHANNEL_2;
		CHx=(uint32_t)TIM_CHANNEL_3;
		CHy=(uint32_t)TIM_CHANNEL_4;
	}else{								//bridge2
		CH1=(uint32_t)TIM_CHANNEL_3;
		CH2=(uint32_t)TIM_CHANNEL_4;
		CHx=(uint32_t)TIM_CHANNEL_1;
		CHy=(uint32_t)TIM_CHANNEL_2;
	}
			SystemClock_Config_48MHz();
	HAL_Delay(20);
	MX_TIM3_Init();

	HAL_TIM_PWM_Init(&htim3);

		
	sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH1);
	  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH2);
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHx);
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHy);

			HAL_TIM_PWM_Start(&htim3, CH1);
			HAL_TIM_PWM_Start(&htim3, CH2);
			HAL_TIM_PWM_Start(&htim3, CHx);
			HAL_TIM_PWM_Start(&htim3, CHy);


	//csattanás csökkentés, 19khz kiadás eloszor
			
			HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0 );	
		//	HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 );									//open drain kimenet,pch fet,
//*****************************************	
	/*for( i=900 ; i >= 620 ; i-=3){
							
			__HAL_TIM_SetAutoreload(&htim3,i*2);				
			__HAL_TIM_SetCompare(&htim3,CH1, i);
			__HAL_TIM_SetCompare(&htim3,CH2, i);

							HAL_Delay(1);
						}*/
	/***********************************	
						HAL_Delay(100);						
			__HAL_TIM_SetAutoreload(&htim3,i*2);				
			__HAL_TIM_SetCompare(&htim3,CH1, i);
			__HAL_TIM_SetCompare(&htim3,CH2, i);
						HAL_Delay(1000);*/
			HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 );								
			HAL_Delay(100);

		//19KHz-620  // 27KHz-440
				old_i=i;
		for(uint8_t x=0; x < soundNum; x++){
			
		// a következo hanghoz kis lépésenként jutunk, ígty nincs csattanás
			
			srand(HAL_GetTick());
			i=(rand()%210)+440;		
			//i=210+440;
		/*
			if(	old_i	<	i){
										
					// ha az új hang kissebb frekvenciájó -> nagyobb i
				for(	temp_i=old_i	;	i	>=	temp_i;	temp_i++){
			
			__HAL_TIM_SetAutoreload(&htim3,temp_i*2);				
			__HAL_TIM_SetCompare(&htim3,CH1, temp_i);
			__HAL_TIM_SetCompare(&htim3,CH2, temp_i);
					HAL_Delay(1);
				}
					
			}else{
				//ha az uj hang nagypbb frekvenciáju-> kisebb i
				for(	temp_i=old_i	;	i	<=	temp_i;	temp_i--){
			
			__HAL_TIM_SetAutoreload(&htim3,temp_i*2);				
			__HAL_TIM_SetCompare(&htim3,CH1, temp_i);
			__HAL_TIM_SetCompare(&htim3,CH2, temp_i);
					HAL_Delay(1);
				}
			}
			*/
			
						__HAL_TIM_SetAutoreload(&htim3,i*2);				
						__HAL_TIM_SetCompare(&htim3,CH1, i);
						__HAL_TIM_SetCompare(&htim3,CH2, i);
						
			
			old_i=i;
			tim=HAL_GetTick();							//jelenlegi ido lekérdezés
			tim_now=HAL_GetTick();
			f=i%5;
			while(  sDelay >= (tim_now-tim) && tim <= tim_now ){				///késleltetés
			if(f==3){
			for(temp_i=0 ; temp_i < 10 ;temp_i++){					//itt nagyobb lesz a frekvencia
				i+=1;
			__HAL_TIM_SetAutoreload(&htim3,i*2);				
			__HAL_TIM_SetCompare(&htim3,CH1, i);
			__HAL_TIM_SetCompare(&htim3,CH2, i);
				HAL_Delay(1);
			}
			
			for(temp_i=0 ; temp_i < 10 ;temp_i++){					//itt kissebb lesz a frekvencia 
			i-=1;
			__HAL_TIM_SetAutoreload(&htim3,i*2);				
			__HAL_TIM_SetCompare(&htim3,CH1, i);
			__HAL_TIM_SetCompare(&htim3,CH2, i);
				HAL_Delay(1);
			}
			
		}
				tim_now=HAL_GetTick();
			}
			
		//	HAL_Delay(sDelay);
			randCount++;
		}

	
		//csattanás csökkentés, 19khz kiadás eloszor
		HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0);						
		for( i=i ; i <= 900 ; i+=3){
							
			__HAL_TIM_SetAutoreload(&htim3,i*2);				
			__HAL_TIM_SetCompare(&htim3,CH1, i);
			__HAL_TIM_SetCompare(&htim3,CH2, i);

							HAL_Delay(1);
						}
	HAL_Delay(100);
	
		HAL_TIM_PWM_Stop( &htim3 , CH1 );
		HAL_TIM_PWM_Stop( &htim3 , CH2 );
		HAL_TIM_PWM_Stop( &htim3 , CHx );
		HAL_TIM_PWM_Stop( &htim3 , CHy );
		HAL_TIM_PWM_DeInit( &htim3 );


	//	HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 1);								//open drain kimenet,pch fet,
HAL_Delay(100);
	
	SystemClock_Config_8MHz();
			GPIO_TIM3_OFF();
	HAL_Delay(100);
}
Exemplo n.º 7
0
void beeps (uint8_t num,uint8_t bridge){
			uint16_t temp1;
			uint32_t CH1,CH2,CHx,CHy;
	//	HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 );									//open drain kimenet,pch fet,
	HAL_Delay(100);
		HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 );									//open drain kimenet,pch fet,

		//bridge1=0,bridge2=1-> hogy melyik hidat hajtsa meg 
	if(bridge){						//bridge1
		CH1=(uint32_t)TIM_CHANNEL_1;
		CH2=(uint32_t)TIM_CHANNEL_2;
		CHx=(uint32_t)TIM_CHANNEL_3;
		CHy=(uint32_t)TIM_CHANNEL_4;
	}else{								//bridge2
		CH1=(uint32_t)TIM_CHANNEL_3;
		CH2=(uint32_t)TIM_CHANNEL_4;
		CHx=(uint32_t)TIM_CHANNEL_1;
		CHy=(uint32_t)TIM_CHANNEL_2;
	}

		//SystemClock_Config_48MHz();
			MX_TIM3_Init();
			HAL_TIM_PWM_Init(&htim3);
	
			sConfigOC.OCMode = TIM_OCMODE_PWM1;
			sConfigOC.Pulse = 0;
			sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
			sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH1);
			sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH2);
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHx);
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHy);
	
			HAL_TIM_PWM_Start(&htim3, CH1);
			HAL_TIM_PWM_Start(&htim3, CH2);
			HAL_TIM_PWM_Start(&htim3, CHx);
			HAL_TIM_PWM_Start(&htim3, CHy);
			__HAL_TIM_SetCompare(&htim3,CH2,0);

			
	for( uint8_t i=0 ; i<num ; i++){
		temp1=3500;
		
		for(uint8_t ii=0; ii<10 ; ii++){
				__HAL_TIM_SetAutoreload(&htim3,temp1*2);
				__HAL_TIM_SetCompare(&htim3,CH1, temp1);
			//__HAL_TIM_SetCompare(&htim3,CH2,temp1);
			
				temp1 -=6;
				HAL_Delay(18);
		}/*
		for(uint8_t ii=0; ii<10 ; ii++){
				__HAL_TIM_SetAutoreload(&htim3,temp1*2);
				__HAL_TIM_SetCompare(&htim3,CH1, temp1);
				//		__HAL_TIM_SetCompare(&htim3,CH2,temp1);
				temp1 +=15;
				HAL_Delay(9);
		}*/
		__HAL_TIM_SetCompare(&htim3,CH1, 0);
			//		__HAL_TIM_SetCompare(&htim3,CH2,0);
		HAL_Delay(340);
	}
	
		__HAL_TIM_SetCompare(&htim3,CH1, 0);
		HAL_TIM_PWM_Stop( &htim3 , CH1 );
		HAL_TIM_PWM_Stop( &htim3 , CH2 );
		HAL_TIM_PWM_Stop( &htim3 , CHx );
		HAL_TIM_PWM_Stop( &htim3 , CHy );
		HAL_TIM_PWM_DeInit( &htim3 );
		HAL_TIM_Base_DeInit(&htim3);
		GPIO_TIM3_OFF();
			HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0 );									//open drain kimenet,pch fet,
		HAL_Delay(100);
	//		HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 );									
		HAL_Delay(1000);
}	
Exemplo n.º 8
0
void uartTester(){
	//UART fogadás, teszteléshez ---------------------------------------------------------

		uint8_t pData;
		PutString("S");

		HAL_UART_Receive(&huart1,&pData,1,100);
		if(pData=='O'){
			HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin);

			PutString("R");
			
			
				HAL_UART_Receive(&huart1,&pData,1,1000);
			while(pData != 'A')
							HAL_UART_Receive(&huart1,&pData,1,1000);
			
		HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 );	
			
		PutString("R");
			
				HAL_UART_Receive(&huart1,&pData,8,1000);
			while(pData != 'B')
							HAL_UART_Receive(&huart1,&pData,8,1000);
			
			
			soundNum=1;
			sounDelay=10;
									
	SystemClock_Config_48MHz();
	HAL_Delay(2);
	MX_TIM3_Init();

	HAL_TIM_PWM_Init(&htim3);

		
	sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_1);
	  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
			HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_2);
			HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin);
					HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
			HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
			uint16_t i=630;
		__HAL_TIM_SetAutoreload(&htim3,i*2);				
			__HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_1, i);
			__HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_2, i);	
				HAL_Delay(500);
				
			PutString("R");
			
				HAL_UART_Receive(&huart1,&pData,8,1000);
			while(pData != 'C')
							HAL_UART_Receive(&huart1,&pData,8,1000);
		
		HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0);				
		HAL_TIM_PWM_Stop( &htim3 , TIM_CHANNEL_1 );
		HAL_TIM_PWM_Stop( &htim3 , TIM_CHANNEL_2 );
		HAL_TIM_PWM_DeInit( &htim3 );
			SystemClock_Config_8MHz();
			
			HAL_ADC_MspDeInit(&hadc);
			HAL_UART_MspDeInit(&huart1);
			HAL_TIM_Base_DeInit(&htim3);
	
			

		
		while(1){
				HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin);
				HAL_Delay(200);
		}
	}
}
Exemplo n.º 9
0
/**
  * @brief  Execute the demo application.
  * @param  None
  * @retval None
  */
static void Demo_Exec(void)
{
    uint8_t togglecounter = 0x00;

    /* Initialize Accelerometer MEMS*/
    if(BSP_ACCELERO_Init() != HAL_OK)
    {
        /* Initialization Error */
        Error_Handler();
    }

    while(1)
    {
        DemoEnterCondition = 0x00;

        /* Reset UserButton_Pressed variable */
        UserButtonPressed = 0x00;

        /* Configure LEDs to be managed by GPIO */
        BSP_LED_Init(LED3);
        BSP_LED_Init(LED4);
        BSP_LED_Init(LED5);
        BSP_LED_Init(LED6);

        /* SysTick end of count event each 10ms */
        SystemCoreClock = HAL_RCC_GetHCLKFreq();
        SysTick_Config(SystemCoreClock / 100);

        /* Turn OFF all LEDs */
        BSP_LED_Off(LED4);
        BSP_LED_Off(LED3);
        BSP_LED_Off(LED5);
        BSP_LED_Off(LED6);

        /* Waiting User Button is pressed */
        while (UserButtonPressed == 0x00)
        {
            /* Toggle LED4 */
            BSP_LED_Toggle(LED4);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED3);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED5);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED6);
            HAL_Delay(10);
            togglecounter ++;
            if (togglecounter == 0x10)
            {
                togglecounter = 0x00;
                while (togglecounter < 0x10)
                {
                    BSP_LED_Toggle(LED4);
                    BSP_LED_Toggle(LED3);
                    BSP_LED_Toggle(LED5);
                    BSP_LED_Toggle(LED6);
                    HAL_Delay(10);
                    togglecounter ++;
                }
                togglecounter = 0x00;
            }
        }

        /* Waiting User Button is Released */
        while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {}
        UserButtonPressed = 0x00;

        /* TIM4 channels configuration */
        TIM4_Config();

        DemoEnterCondition = 0x01;

        /* USB configuration */
        Demo_USBConfig();

        /* Waiting User Button is pressed */
        while (UserButtonPressed == 0x00)
        {}

        /* Waiting User Button is Released */
        while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {}

        /* Disconnect the USB device */
        USBD_Stop(&hUSBDDevice);
        USBD_DeInit(&hUSBDDevice);
        if(HAL_TIM_PWM_DeInit(&htim4) != HAL_OK)
        {
            /* Initialization Error */
            Error_Handler();
        }
    }
}
Exemplo n.º 10
0
/**
 * @brief   Deintialize the buzzer
 * @param   None
 * @retval  None
 */
void BUZZER_DeInit()
{
  HAL_GPIO_DeInit(BUZZER_PORT, BUZZER_PIN);
  HAL_TIM_PWM_Stop(&prvTimerHandle, BUZZER_TIMER_CHANNEL);
  HAL_TIM_PWM_DeInit(&prvTimerHandle);
}