From d31b26a705d0e4b6a75c174968fccca3590c2cc7 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 31 Jan 2022 17:03:33 +0100 Subject: fix timebase --- Year_3/LSM/ex_20190218.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Year_3/LSM/ex_20190218.c b/Year_3/LSM/ex_20190218.c index e43afd8..ac3bc45 100644 --- a/Year_3/LSM/ex_20190218.c +++ b/Year_3/LSM/ex_20190218.c @@ -13,7 +13,7 @@ typedef enum { status_t status = RUN; float real_root = 0; float new_want_root = 0; -float want_root = 0; +float want_root = 180; double rotation = 1; @@ -37,7 +37,7 @@ init() TIM_init(TIM2); TIM_set(TIM2, 0); TIM_on(TIM2); - TIM_config_timebase(TIM2, 8400, 840); + TIM_config_timebase(TIM2, 8400, 100); TIM_enable_irq(TIM2, IRQ_UPDATE); ADC_init(ADC1, ADC_RES_12, ADC_ALIGN_RIGHT); @@ -66,6 +66,10 @@ main() adc_read = (2 * adc_read) / 4095; real_root -= ((adc_read * 2) * (1.0 * rand()) / RAND_MAX - adc_read); + if (real_root > 180) + real_root = 180; + else if (real_root < -180) + real_root = -180; printf("%f %f %f\n", rotation, real_root, want_root); sprintf(s, "%f", real_root); -- cgit v1.2.3-18-g5258