Esempio n. 1
0
void Ultrasonic_Init(void) {
	HAL_TIM_Base_Stop(&htim_sonar);
	GPIO_TRIG->BSRR  |= (1 << GPIO_TRIG_PIN)<<16;
	
	Ultrasonic.status = USS_IDLE;
	Ultrasonic.altitude = 0.0f;
	Ultrasonic.callback = 0;
}
Esempio n. 2
0
void threewire_tim_set_prescaler(t_hydra_console *con)
{
	mode_config_proto_t* proto = &con->mode->proto;

	HAL_TIM_Base_Stop(&htim);
	HAL_TIM_Base_DeInit(&htim);
	htim.Init.Prescaler = (THREEWIRE_MAX_FREQ/proto->config.rawwire.dev_speed) - 1;
	HAL_TIM_Base_Init(&htim);
	TIM4->SR &= ~TIM_SR_UIF;  //clear overflow flag
	HAL_TIM_Base_Start(&htim);
}
/**
  * @brief  This function Pauses the audio file stream.
  * @retval AUDIO_OK if correct communication, else wrong communication
  */
uint8_t BSP_AUDIO_IN_Pause(void)
{    
  uint32_t ret = AUDIO_OK;
  
  /* Stop the time base triggering the ADC */
  if (HAL_TIM_Base_Stop(&hAudioInTim3) != HAL_OK)
  {
    ret = AUDIO_ERROR;
  } 
  
  /* Return AUDIO_OK if all operations are OK */
  return ret;
}
Esempio n. 4
0
void Ultrasonic_Echo(char high){
	if (Ultrasonic.status == USS_IDLE) return;
	
	if (high) { //超声波开始
		HAL_TIM_Base_Start(&htim_sonar);
		Ultrasonic.status = USS_TIMING;
	} else { //超声波结束
		HAL_TIM_Base_Stop(&htim_sonar);
		US_UPDATE(htim_sonar.Instance->CNT / Ultrasonic_SpeedFactor);
		if (Ultrasonic.callback)
			(*Ultrasonic.callback)();
		Ultrasonic.status = USS_IDLE;
	}
}
Esempio n. 5
0
File: aos.c Progetto: OUWECAD/MOWE
/* --- Load and start micro-second delay counter --- */
void startMicroDelay(uint16_t Delay)
{
	portENTER_CRITICAL();
	
	if (Delay)
	{
		htim7.Instance->ARR = Delay;
	
		HAL_TIM_Base_Start(&htim7);	

		while(htim7.Instance->CNT != 0)
		{
		}
		
		HAL_TIM_Base_Stop(&htim7);
	}
	
	portEXIT_CRITICAL();
}
Esempio n. 6
0
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{

    if (htim->Instance == htim17.Instance)
    {
        if (PWM1_DeltaCount > 0)
        {
            htim3.Instance->CCR4 += (PWM1_DeltaStep * PWM1_Direction);
            PWM1_DeltaCount--;
        }

        if (PWM2_DeltaCount > 0)
        {
            htim14.Instance->CCR1 += (PWM2_DeltaStep * PWM2_Direction);
            PWM2_DeltaCount--;
        }

        if (PWM1_DeltaCount == 0 && PWM2_DeltaCount == 0)
        {
            HAL_TIM_Base_Stop(&htim17);
        }
    }
}
/**
  * @brief  Stop audio recording
  * @retval None
  */
uint8_t BSP_AUDIO_IN_Stop(void)
{
  uint32_t ret = AUDIO_OK;
  
  /* Stop the time base triggering the ADC */
  if (HAL_TIM_Base_Stop(&hAudioInTim3) != HAL_OK)
  {
    ret = AUDIO_ERROR;
  } 
  
  if (HAL_ADC_Stop_DMA(&hAudioInAdc) != HAL_OK)
  {
    /* Return 0 if all operations are OK */
    ret = AUDIO_ERROR;
  }
  
  /* Disable OPAMPx */
  if (HAL_OPAMP_Stop(&hAudioInOpamp) != HAL_OK)
  {
    ret = AUDIO_ERROR;
  }  
  
  return ret;
}
Esempio n. 8
0
void TIMGenDisable(void){
  HAL_TIM_Base_Stop(&htim6);
	HAL_TIM_Base_Stop(&htim7);
}
Esempio n. 9
0
void TIMScopeDisable(){
	HAL_TIM_Base_Stop(&htim_scope);
}	
Esempio n. 10
0
void Ultrasonic_TimeoutCallback(void) {
	HAL_TIM_Base_Stop(&htim_sonar);
	Ultrasonic.status = USS_IDLE;
}
Esempio n. 11
0
/**
  * @brief  This function handles TIM interrupt request.
  * @param  None
  * @retval None
  */
void TIM7_IRQHandler(void)
{
			present_encoder_count = __HAL_TIM_GET_COUNTER(&TimHandle_Enc1);
			speed = present_encoder_count - previous_encoder_count ;
			local_time++;
	
			/* If control is PBC, turn off the motor when the present_encoder_count is greater than or equal to pOn */
			if(control == PBC && ((dir == pos && present_encoder_count >= pOn) || (dir == rev && present_encoder_count <= pOn)))
			{
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8 , GPIO_PIN_RESET);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
				isHigh = 1;			// Calculate PCC for adaptation
			}
			
			/* If control is TBC, turn off the motor when the local_time is greater than or equal to tOn */
			if(control == TBC && local_time>=tOn)
			{	
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8 , GPIO_PIN_RESET);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);	
			}
	
			/* Wait until motor settles */
			if(speed_count == 10 ) 
			{
				pS = present_encoder_count ;
								
				if(isHigh)		// If the control was PBC, calculate PCC for adaptation
				{
					pcc = (((float)x*pcc)+((float)y*pcc*((float)local_demand/(float)(absolute(pS - pSa)))))/((float)x+(float)y);
					isHigh = 0;}
				
				error = demand - pS;
				local_demand = absolute(error);
				pSa = __HAL_TIM_GET_COUNTER(&TimHandle_Enc1);

				if(local_demand <= 6);						// If error is less than 6 pulses, exit the control loop			
				else if(local_demand <= 100){			// If error is less than 100 pulses, use Time Based Control
					control = TBC;
					local_time=0;
					isDemandChanged=1;}
				else { 														// If error is greater tha 100 pulses, use Position Based Control
					control = PBC;
					isDemandChanged=1;}
				
				/* Set direction depending on the sign of the error */
				if(error < 0)
					dir = rev;
				else
					dir = pos;
				
				/* Disable Timer Interrupt */
				HAL_TIM_Base_Stop(&TimHandle_int);
				
				/* Reset Speed count*/
				speed_count = 0;
			}
			
			/* Wait for 10ms after speed becomes 0 ie., until the motor settles */
			if(speed == 0)
				speed_count++;		// If speed is 0, increment speed count
			else
				speed_count = 0;	// Else reset speed count 

			previous_encoder_count = present_encoder_count;
			HAL_TIM_IRQHandler(&TimHandle_int);
}