pwm input working (at least for one channel)
This commit is contained in:
parent
ee441c7d95
commit
6157f5b790
2 changed files with 31 additions and 12 deletions
|
@ -22,11 +22,11 @@ void RF_INPUT_Init(void)
|
||||||
pb7_init_conf.Pull = LL_GPIO_PULL_DOWN;
|
pb7_init_conf.Pull = LL_GPIO_PULL_DOWN;
|
||||||
LL_GPIO_Init(GPIOB, &pb7_init_conf);
|
LL_GPIO_Init(GPIOB, &pb7_init_conf);
|
||||||
|
|
||||||
// timer setup
|
// timer setup to
|
||||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||||
LL_TIM_InitTypeDef tim4_init_struct;
|
LL_TIM_InitTypeDef tim4_init_struct;
|
||||||
|
|
||||||
tim4_init_struct.Autoreload= 1000; // ??
|
tim4_init_struct.Autoreload= 0xFFFF; // ??
|
||||||
tim4_init_struct.Prescaler=71;
|
tim4_init_struct.Prescaler=71;
|
||||||
tim4_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
|
tim4_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
|
||||||
tim4_init_struct.CounterMode=LL_TIM_COUNTERMODE_UP;
|
tim4_init_struct.CounterMode=LL_TIM_COUNTERMODE_UP;
|
||||||
|
@ -34,22 +34,30 @@ void RF_INPUT_Init(void)
|
||||||
|
|
||||||
LL_TIM_Init(TIM4, &tim4_init_struct);
|
LL_TIM_Init(TIM4, &tim4_init_struct);
|
||||||
|
|
||||||
/*LL_TIM_IC_InitTypeDef tim4_ic_conf;
|
|
||||||
|
// setup channel 1 to capture period of pwm
|
||||||
|
LL_TIM_IC_InitTypeDef tim4_ic_conf;
|
||||||
tim4_ic_conf.ICPolarity= LL_TIM_IC_POLARITY_RISING;
|
tim4_ic_conf.ICPolarity= LL_TIM_IC_POLARITY_RISING;
|
||||||
tim4_ic_conf.ICActiveInput = LL_TIM_ACTIVEINPUT_TRC;
|
tim4_ic_conf.ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
|
||||||
tim4_ic_conf.ICFilter = LL_TIM_IC_FILTER_FDIV1;
|
tim4_ic_conf.ICFilter = LL_TIM_IC_FILTER_FDIV1;
|
||||||
tim4_ic_conf.ICPrescaler = LL_TIM_ICPSC_DIV1;
|
tim4_ic_conf.ICPrescaler = LL_TIM_ICPSC_DIV1;
|
||||||
|
|
||||||
LL_TIM_IC_Init(TIM4, LL_TIM_CHANNEL_CH1, &tim4_ic_conf);
|
LL_TIM_IC_Init(TIM4, LL_TIM_CHANNEL_CH1, &tim4_ic_conf);
|
||||||
*/
|
|
||||||
|
// setup channel 2 to capture duty time of pwm
|
||||||
LL_TIM_IC_InitTypeDef tim4_ic_conf_2;
|
LL_TIM_IC_InitTypeDef tim4_ic_conf_2;
|
||||||
tim4_ic_conf_2.ICPolarity= LL_TIM_IC_POLARITY_RISING;
|
tim4_ic_conf_2.ICPolarity= LL_TIM_IC_POLARITY_FALLING;
|
||||||
tim4_ic_conf_2.ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
|
tim4_ic_conf_2.ICActiveInput = LL_TIM_ACTIVEINPUT_INDIRECTTI;
|
||||||
tim4_ic_conf_2.ICFilter = LL_TIM_IC_FILTER_FDIV1;
|
tim4_ic_conf_2.ICFilter = LL_TIM_IC_FILTER_FDIV1;
|
||||||
tim4_ic_conf_2.ICPrescaler = LL_TIM_ICPSC_DIV1;
|
tim4_ic_conf_2.ICPrescaler = LL_TIM_ICPSC_DIV1;
|
||||||
|
|
||||||
LL_TIM_IC_Init(TIM4, LL_TIM_CHANNEL_CH1, &tim4_ic_conf_2);
|
LL_TIM_IC_Init(TIM4, LL_TIM_CHANNEL_CH2, &tim4_ic_conf_2);
|
||||||
|
|
||||||
|
// setup reset of clock at rising edge
|
||||||
|
LL_TIM_SetSlaveMode(TIM4, LL_TIM_SLAVEMODE_RESET);
|
||||||
|
LL_TIM_SetTriggerInput(TIM4, LL_TIM_TS_TI1FP1);
|
||||||
|
|
||||||
|
LL_TIM_EnableCounter(TIM4);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RF_INPUT_GetValue1(void)
|
int RF_INPUT_GetValue1(void)
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
#include "stm32f1xx_ll_rcc.h" // utile dans la fonction SystemClock_Config
|
#include "stm32f1xx_ll_rcc.h" // utile dans la fonction SystemClock_Config
|
||||||
#include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config
|
#include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config
|
||||||
#include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
|
#include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
|
||||||
|
#include "stm32f1xx_ll_bus.h"
|
||||||
|
|
||||||
#include "RFInput.h"
|
#include "RFInput.h"
|
||||||
#include "IncrEncoder.h"
|
#include "IncrEncoder.h"
|
||||||
|
#include "DcMotor.h"
|
||||||
|
|
||||||
void SystemClock_Config(void);
|
void SystemClock_Config(void);
|
||||||
|
|
||||||
|
@ -33,7 +35,9 @@ void SystemClock_Config(void);
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int val = 0;
|
||||||
|
int val2 = 0;
|
||||||
|
int counter = 0;
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -41,11 +45,18 @@ int main(void)
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
|
|
||||||
RF_INPUT_Init();
|
RF_INPUT_Init();
|
||||||
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
|
||||||
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||||
|
DC_MOTOR_Init();
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
LL_mDelay(1000);
|
||||||
|
counter = (counter + 1) % 100;
|
||||||
|
DC_MOTOR_SetSpeed(counter);
|
||||||
|
val = RF_INPUT_GetValue1();
|
||||||
|
val2 = RF_INPUT_GetValue2();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue