diff --git a/keil_project/Services/RFInput.c b/keil_project/Services/RFInput.c index a1c771a..5042ddd 100644 --- a/keil_project/Services/RFInput.c +++ b/keil_project/Services/RFInput.c @@ -22,11 +22,11 @@ void RF_INPUT_Init(void) pb7_init_conf.Pull = LL_GPIO_PULL_DOWN; LL_GPIO_Init(GPIOB, &pb7_init_conf); - // timer setup + // timer setup to LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4); LL_TIM_InitTypeDef tim4_init_struct; - tim4_init_struct.Autoreload= 1000; // ?? + tim4_init_struct.Autoreload= 0xFFFF; // ?? tim4_init_struct.Prescaler=71; tim4_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1; 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_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.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.ICPrescaler = LL_TIM_ICPSC_DIV1; 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; - tim4_ic_conf_2.ICPolarity= LL_TIM_IC_POLARITY_RISING; - tim4_ic_conf_2.ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI; + tim4_ic_conf_2.ICPolarity= LL_TIM_IC_POLARITY_FALLING; + tim4_ic_conf_2.ICActiveInput = LL_TIM_ACTIVEINPUT_INDIRECTTI; tim4_ic_conf_2.ICFilter = LL_TIM_IC_FILTER_FDIV1; 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) diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index b107345..3af9fa4 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -19,9 +19,11 @@ #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_system.h" // utile dans la fonction SystemClock_Config +#include "stm32f1xx_ll_bus.h" #include "RFInput.h" #include "IncrEncoder.h" +#include "DcMotor.h" void SystemClock_Config(void); @@ -33,7 +35,9 @@ void SystemClock_Config(void); * @retval None */ - +int val = 0; +int val2 = 0; +int counter = 0; int main(void) { @@ -41,11 +45,18 @@ int main(void) SystemClock_Config(); 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 */ while (1) { - + LL_mDelay(1000); + counter = (counter + 1) % 100; + DC_MOTOR_SetSpeed(counter); + val = RF_INPUT_GetValue1(); + val2 = RF_INPUT_GetValue2(); } }