-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.c
executable file
·97 lines (77 loc) · 1.8 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* EGG Electric Unicycle firmware
*
* Copyright (C) Casainho, 2015, 2106.
*
* Released under the GPL License, Version 3
*/
#include "stm32f10x.h"
#include "gpio.h"
#include "main.h"
#include "stdio.h"
#include "leds.h"
#include "filter.h"
static unsigned int _ms;
void delay_ms (unsigned int ms)
{
_ms = 1;
while (ms >= _ms) ;
}
void SysTick_Handler(void) // runs every 1ms
{
// for delay_ms ()
_ms++;
}
void initialize (void)
{
/* Setup SysTick Timer for 1 millisecond interrupts, also enables Systick and Systick-Interrupt */
if (SysTick_Config(SystemCoreClock / 1000))
{
/* Capture error */
while (1);
}
// TIM2_init ();
gpio_init ();
adc_init ();
pwm_init ();
// buzzer_init ();
usart1_bluetooth_init ();
hall_sensor_init ();
// MPU6050_I2C_Init ();
// MPU6050_Initialize ();
}
int main(void)
{
initialize ();
/* needed for printf */
// turn off buffers, so IO occurs immediately
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
int value;
enable_phase_a ();
enable_phase_b ();
enable_phase_c ();
while (1)
{
delay_ms (10);
value = adc_get_potentiometer_value ();
value = ema_filter (value);
//value = (value * 1000) / 4096;
value = value - 2048;
value = value * 1000;
value = value / 2048;
motor_set_duty_cycle (value);
printf("pot: %d\n", value);
// apply_duty_cycle ();
// balance_controller ();
// value = (adc_get_phase_a_current_value ());
// printf("adc phase a: %d\n", value);
// //printf("voltage adc phase a: %d\n\n", ((value * K_ADC_VOLTAGE) / 100));
//
//
// value = (adc_get_battery_voltage_value ());
// printf("battery voltage: %d\n", value);
// //printf("voltage adc phase c: %d\n\n", ((value * K_ADC_VOLTAGE) / 100));
}
}