diff options
author | Santo Cariotti <santo@dcariotti.me> | 2022-01-31 17:03:33 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2022-01-31 17:03:33 +0100 |
commit | d31b26a705d0e4b6a75c174968fccca3590c2cc7 (patch) | |
tree | 1398f190eed1b2fb0bebfd3556104a5c49f9b9b2 /Year_3/LSM | |
parent | 3bf905caad2975e036b623eb1cd985631d2d044c (diff) |
fix timebase
Diffstat (limited to 'Year_3/LSM')
-rw-r--r-- | Year_3/LSM/ex_20190218.c | 8 |
1 files 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); |