Answer the question
In order to leave comments, you need to log in
Implementation of the HC-SR04 rangefinder on stm32 using PWM?
For the rangefinder to work, you need to send a signal with a time length of 10 μs to one of its legs no more than every 50 ms, at first I implemented this work simply by delaying the timer
delay(50000);
GPIOB->ODR |= GPIO_ODR_ODR1;
delay(10);
GPIOB->ODR &= ~GPIO_ODR_ODR1;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
TIM3->PSC = SystemCoreClock / 1000000 -1; //отстчет каждую 1мкс
TIM3->ARR = 60000; //период 60мс
TIM3->CCR4 = 10; //время импульса 10мкс
TIM3->CCMR2 |= TIM_CCMR2_OC4M_0 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2;
TIM3->CCER |= TIM_CCER_CC4E;
TIM3->CR1 |= TIM_CR1_CEN;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question