本文整理汇总了C++中HAL_TIM_ReadCapturedValue函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_TIM_ReadCapturedValue函数的具体用法?C++ HAL_TIM_ReadCapturedValue怎么用?C++ HAL_TIM_ReadCapturedValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_TIM_ReadCapturedValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HAL_TIM_IC_CaptureCallback
/**
* @brief Conversion complete callback in non blocking mode
* @param htim: TIM handle
* @retval None
*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
{
if(uhCaptureIndex == 0)
{
/* Get the 1st Input Capture value */
uwIC2Value1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
uhCaptureIndex = 1;
}
else if(uhCaptureIndex == 1)
{
/* Get the 2nd Input Capture value */
uwIC2Value2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
/* Capture computation */
if (uwIC2Value2 > uwIC2Value1)
{
uwDiffCapture = (uwIC2Value2 - uwIC2Value1);
}
else /* (uwIC2Value2 <= uwIC2Value1) */
{
uwDiffCapture = ((0xFFFF - uwIC2Value1) + uwIC2Value2);
}
/* Frequency computation: for this example TIMx (TIM1) is clocked by
2xAPB2Clk */
uwFrequency = (2*HAL_RCC_GetPCLK2Freq()) / uwDiffCapture;
uhCaptureIndex = 0;
}
}
}
示例2: HAL_TIM_IC_CaptureCallback
/**
* @brief Conversion complete callback in non blocking mode
* @param htim : htim handle
* @retval None
*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4)
{
if(uhCaptureIndex == 0)
{
/* Get the 1st Input Capture value */
uwIC2Value1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
uhCaptureIndex = 1;
}
else if(uhCaptureIndex == 1)
{
/* Get the 2nd Input Capture value */
uwIC2Value2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
/* Capture computation */
if (uwIC2Value2 > uwIC2Value1)
{
uwDiffCapture = (uwIC2Value2 - uwIC2Value1);
}
else if (uwIC2Value2 < uwIC2Value1)
{
uwDiffCapture = ((0xFFFF - uwIC2Value1) + uwIC2Value2);
}
else
{
uwDiffCapture = 0;
}
/* Compute the pulse width in us */
uwMeasuredPulse = (uint32_t)(((uint64_t) uwDiffCapture * 1000000) / HAL_RCC_GetPCLK1Freq());
uhCaptureIndex = 0;
}
}
}
示例3: HAL_TIM_OC_DelayElapsedCallback
/**
* @brief Output Compare callback in non blocking mode
* @param htim : TIM OC handle
* @retval None
*/
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{
/* TIM3_CH1 toggling with frequency = 195 Hz */
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
{
uhCapture = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
/* Set the Capture Compare Register value */
__HAL_TIM_SET_COMPARE(&TimHandle, TIM_CHANNEL_1, (uhCapture + uhCCR1_Val));
}
/* TIM3_CH2 toggling with frequency = 390 Hz */
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
{
uhCapture = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
/* Set the Capture Compare Register value */
__HAL_TIM_SET_COMPARE(&TimHandle, TIM_CHANNEL_2, (uhCapture + uhCCR2_Val));
}
/* TIM3_CH3 toggling with frequency = 780 Hz */
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3)
{
uhCapture = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
/* Set the Capture Compare Register value */
__HAL_TIM_SET_COMPARE(&TimHandle, TIM_CHANNEL_3, (uhCapture + uhCCR3_Val));
}
/* TIM3_CH4 toggling with frequency = 1560 Hz */
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4)
{
uhCapture = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
/* Set the Capture Compare Register value */
__HAL_TIM_SET_COMPARE(&TimHandle, TIM_CHANNEL_4, (uhCapture + uhCCR4_Val));
}
}
示例4: Get_Speed
/**
* @brief 获得两次时间间隔中的编码器读数差.
* @param None
* @retval None
*/
void Get_Speed(void){
uint32_t TempL,TempR;
TempL=HAL_TIM_ReadCapturedValue(&TimHandleT9, TIM_CHANNEL_1);//编码器读取
Speed_L=TempL;
/*
Speed_L=TempL-Pre_Speed_L;
Pre_Speed_L=TempL;
if(Speed_L<-20000){
Speed_L+=65535;}
else if(Speed_L>20000){
Speed_L-=65535;}
*/
TempR=HAL_TIM_ReadCapturedValue(&TimHandleT5, TIM_CHANNEL_1);//编码器读取
Speed_R=TempR;
/*
Speed_R=TempR-Pre_Speed_R;
Pre_Speed_R=TempR;
if(Speed_R<-20000){
Speed_R+=65535;}
else if(Speed_R>20000){
Speed_R-=65535;}
//一阶低通滤波
Speed_A_Last=(Speed_L-Speed_R)/2;
Speed_A*=0.7;
Speed_A+=Speed_A_Last*0.3;
*/
}
示例5: HAL_TIM_IC_CaptureCallback
/**
* @brief Conversion complete callback in non blocking mode
* @param htim: TIM handle
* @retval None
*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
uint16_t captureVal;
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
captureVal = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
motorHallTimoutCnt[0] = 0;
motorHallPeriode[0] = captureVal - motorHallLastCapVal[0];
motorHallLastCapVal[0] = captureVal;
}
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {
captureVal = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
motorHallTimoutCnt[0] = 0;
motorHallPeriode[0] = captureVal - motorHallLastCapVal[1];
motorHallLastCapVal[1] = captureVal;
}
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
captureVal = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
motorHallTimoutCnt[1] = 0;
motorHallPeriode[1] = captureVal - motorHallLastCapVal[2];
motorHallLastCapVal[2] = captureVal;
}
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) {
captureVal = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
motorHallTimoutCnt[1] = 0;
motorHallPeriode[1] = captureVal - motorHallLastCapVal[3];
motorHallLastCapVal[3] = captureVal;
}
}
示例6: HAL_TIM_IC_CaptureCallback
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if(edge == TIM_INPUTCHANNELPOLARITY_RISING) {
edge = TIM_INPUTCHANNELPOLARITY_FALLING;
capture_value_raising = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
}
else if(edge == TIM_INPUTCHANNELPOLARITY_FALLING) {
capture_value_falling = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
float capture_value = capture_value_falling - capture_value_raising;
distance = ((sonic_velocity * (capture_value / tim_clock)) / 2.0) * 10000; // mm
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, (uint8_t*)&distance, CUSTOM_HID_EPOUT_SIZE);
}
}
示例7: HAL_TIM_IC_CaptureCallback
// Callback for sonar echo
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
int idx;
uint32_t ic_val = 0;
// >>>>> Which sonar has received the echo?
if (htim->Instance == TIM2)
{
idx = SONAR_0;
elapsed_tick[idx] = HAL_GetTick() - trigger_tick[COUPLE_0_2];
// Update Input Capture times
ic_val = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
}
else if (htim->Instance == TIM3)
{
idx = SONAR_1;
elapsed_tick[idx] = HAL_GetTick() - trigger_tick[COUPLE_0_2];
// Update Input Capture times
ic_val = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
}
else if (htim->Instance == TIM4)
{
idx = SONAR_2;
elapsed_tick[idx] = HAL_GetTick() - trigger_tick[COUPLE_1_3];
// Update Input Capture times
ic_val = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
}
else if (htim->Instance == TIM5)
{
idx = SONAR_3;
elapsed_tick[idx] = HAL_GetTick() - trigger_tick[COUPLE_1_3];
// Update Input Capture times
ic_val = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
}
else
return; // Should never be here!!!
// <<<<< Which sonar has received the echo?
// >>>>> Durations update
if (ic_val > MAX_DURATION_10_USEC)
distValid[idx] = 0;
else
distValid[idx] = 1;
echo_duration[idx] = ic_val;
// <<<<< Durations update
}
示例8: HAL_TIM_IC_CaptureCallback
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
uint32_t CCRx_tn=0, CCRx_tn_1=0;
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
CCRx_tn = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
if(htim->Instance == TIM3x) {
RC2_tn = CCRx_tn;
intflag2 = 0;
} else if(htim->Instance == TIM4x) {
RC3_tn = CCRx_tn;
intflag3 = 0;
}
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {
CCRx_tn_1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2); // Input capture value
if(htim->Instance == TIM3x) {
RC2_tn_1 = CCRx_tn_1;
intflag2 = 1;
} else if(htim->Instance == TIM4x) {
RC3_tn_1 = CCRx_tn_1;
intflag3 = 1;
}
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
CCRx_tn = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
if(htim->Instance == TIM3x) {
RC1_tn = CCRx_tn;
intflag1 = 0;
} else if(htim->Instance == TIM4x) {
RC4_tn = CCRx_tn;
intflag4 = 0;
}
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) {
CCRx_tn_1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4); // Input capture value
if(htim->Instance == TIM3x) {
RC1_tn_1 = CCRx_tn_1;
intflag1 = 1;
} else if(htim->Instance == TIM4x) {
RC4_tn_1 = CCRx_tn_1;
intflag4 = 1;
}
// ExpLedToggle(GREEN_LED);
}
}
示例9: TIM1_TRG_COM_TIM17_IRQHandler
// Timer 17 update and capture compare interrupt
void TIM1_TRG_COM_TIM17_IRQHandler(void)
{
if(__HAL_TIM_GET_FLAG(&TimHandle[0], TIM_FLAG_CC1) != RESET)
{
if(__HAL_TIM_GET_ITSTATUS(&TimHandle[0], TIM_IT_CC1) !=RESET)
{
{
__HAL_TIM_CLEAR_IT(&TimHandle[0], TIM_IT_CC1);
encoderSpeed[0] = HAL_TIM_ReadCapturedValue(&TimHandle[0], TIM_CHANNEL_1);
TIM17->CNT = 0;
}
}
}
if(__HAL_TIM_GET_FLAG(&TimHandle[0], TIM_FLAG_UPDATE) != RESET)
{
if(__HAL_TIM_GET_ITSTATUS(&TimHandle[0], TIM_IT_UPDATE) !=RESET)
{
__HAL_TIM_CLEAR_IT(&TimHandle[0], TIM_IT_UPDATE);
encoderSpeed[0] = PERIOD; // If timer expires we have got no pulse during measurment period, set max time
}
}
}
示例10: HAL_TIM_IC_CaptureCallback
/* USER CODE BEGIN 0 */
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
uint8_t i;
uint16_t temp;
temp = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
if ((temp > 5000) && (!data_ready))
{
pointer = 0;
for (i = 0; i < 4; i++)
{
if (captured_value[i] < 1000)
captured_value[i] = 1000;
else if (captured_value[i] > 2000)
captured_value[i] = 2000;
rc_data[i] = captured_value[i]-1000;
};
rc_data[4] = 0;
if (captured_value[4] > 1500)
rc_data[4] |= (1<<4);
if (captured_value[5] > 1500)
rc_data[4] |= (1<<5);
if (captured_value[6] > 1500)
rc_data[4] |= (1<<6);
if (captured_value[7] > 1500)
rc_data[4] |= (1<<7);
data_ready = 1;
}
else
{
captured_value[pointer] = temp;
pointer++;
};
if (pointer == 8)
pointer = 0;
};
示例11: HAL_TIM_OC_DelayElapsedCallback
/**
* @brief Output Compare callback in non blocking mode
* @param htim: TIM OC handle
* @retval None
*/
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{
uint32_t capture = 0;
/* Get the TIM4 Input Capture 1 value */
capture = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
/* Set the TIM4 Capture Compare1 Register value */
__HAL_TIM_SET_COMPARE(htim, TIM_CHANNEL_1, (CCR1Val + capture));
}
示例12: detect
void detect(DETECTORSTATUS *st, TIM_HandleTypeDef *htim)
{
int8_t shift;
int16_t diff;
uint16_t lastDelta;
uint16_t capturedValue;
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
{
capturedValue = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
if(st->initialized)
{
lastDelta = capturedValue - st->prevCapture;
st->accumulator += lastDelta;
//st->debug[st->counter] = lastDelta;
if(++st->counter == g_config.mccount)
{
//HAL_GPIO_TogglePin(ACTIVE1_GPIO_Port, ACTIVE1_Pin);
st->lastMeasured = st->accumulator;
st->accumulator = 0;
st->counter = 0;
if(!st->sum)
st->sum = (uint32_t)st->lastMeasured << g_config.sumshift;
else
{
st->avg = st->sum >> g_config.sumshift;
st->threshold = st->avg / g_config.thdiv;
st->diff = (int32_t)st->lastMeasured - st->avg;
st->tolerance = st->threshold >> SHIFT_TOLERANCE;
diff = -st->diff;
if (diff < 0)
st->state = st->tolerance + diff < 0 ? BELOW:BASE;
else if(diff < st->tolerance)
st->state = BASE;
else if(diff < st->threshold)
st->state = ABOVE;
else if(st->state < ACTIVE) { //!ACTIVE && !TIMEOUT
st->activeStart = HAL_GetTick();
st->state = ACTIVE;
} else if(HAL_GetTick() - st->activeStart > g_config.tlimit * 1000)
st->state = TIMEOUT;
shift = g_config.shifts[st->state];
if(shift != SCHAR_MIN) {
st->correction = (shift >= 0) ? (((int32_t)st->diff) << shift) : (((int32_t)st->diff) >> -shift);
st->sum += st->correction;
} else
示例13: HAL_TIM_IC_CaptureCallback
/**
* @brief Conversion complete callback in non blocking mode
* @param htim : hadc handle
* @retval None
*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
{
if(uhCaptureIndex == 0)
{
/* Get the 1st Input Capture value */
uwIC2Value1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
uhCaptureIndex = 1;
}
else if(uhCaptureIndex == 1)
{
/* Get the 2nd Input Capture value */
uwIC2Value2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
/* Capture computation */
if (uwIC2Value2 > uwIC2Value1)
{
uwDiffCapture = (uwIC2Value2 - uwIC2Value1);
}
else if (uwIC2Value2 < uwIC2Value1)
{
/* 0xFFFF is max TIM3_CCRx value */
uwDiffCapture = ((0xFFFF - uwIC2Value1) + uwIC2Value2) + 1;
}
else
{
/* If capture values are equal, we have reached the limit of frequency
measures */
Error_Handler();
}
/* Frequency computation: for this example TIMx (TIM3) is clocked by
2xAPB1Clk */
uwFrequency = (2*HAL_RCC_GetPCLK1Freq()) / uwDiffCapture;
uhCaptureIndex = 0;
}
}
}
示例14: HAL_TIM_IC_CaptureCallback
/**
* Callback function implementation.
* @param htim timer handle which trigger the callback
*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
static uint8_t steerRise = 0;
if (htim->Instance == TIM4) {
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
/* TIM4 Channel 1 (Motor input) */
uwIC1Value = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
/* TIM4 Channel 3 (Steer input) */
uwIC2Value = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3) - uwIC1Value;
steerRise = 1;
if (_signalDetected == RESET) {
_signalDetected = SET;
if (_servo == ENABLE)
HAL_TIM_PWM_Start_IT(&htim4, TIM_CHANNEL_4);
}
/* Connect to servo output */
if (_connected == ENABLE) {
BSP_Radio_SetSteer(uwIC2Value - 1500);
}
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {
/* TIM4 Channel 2 (Motor input, fall edge) */
if (!steerRise && _signalDetected == SET) {
_signalDetected = RESET;
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4);
} else if (steerRise) {
steerRise = 0;
}
}
}
}
示例15: HAL_TIM_IC_CaptureCallback
/**
* @brief Input Capture callback in non blocking mode
* @param htim : TIM IC handle
* @retval None
*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
{
/* Get the Input Capture value */
uwIC2Value = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
if (uwIC2Value != 0)
{
/* Duty cycle computation */
uwDutyCycle = ((HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1)) * 100) / uwIC2Value;
/* uwFrequency computation
TIM4 counter clock = (RCC_Clocks.HCLK_Frequency)/2 */
uwFrequency = (HAL_RCC_GetHCLKFreq())/2 / uwIC2Value;
}
else
{
uwDutyCycle = 0;
uwFrequency = 0;
}
}
}