ADD: analog commands via ADC

This commit is contained in:
Niklas Fauth 2018-02-26 22:00:09 +01:00
parent 8d31eaf8af
commit 30f8d97694
3 changed files with 564 additions and 547 deletions

View File

@ -9,7 +9,7 @@ volatile int posl = 0;
volatile int posr = 0; volatile int posr = 0;
volatile int pwml = 0; volatile int pwml = 0;
volatile int pwmr = 0; volatile int pwmr = 0;
float pwmrl = 0; int16_t pwmrl = 0;
extern volatile adc_buf_t adc_buffer; extern volatile adc_buf_t adc_buffer;
@ -166,13 +166,21 @@ void DMA1_Channel1_IRQHandler() {
pwmrl = 0; pwmrl = 0;
if(adccmd1 - 700 > 0){ if(adccmd1 - 700 > 0){
pwmrl += adccmd1 - 700; pwmrl -= adccmd1 - 700;
} }
if(adccmd2 - 700 > 0){ if(adccmd2 - 700 > 0){
pwmrl -= adccmd2 - 700; pwmrl += adccmd2 - 700;
} }
pwmrl = powf((pwmrl/4), 3) / 614125; if (pwmrl < -100 && enable == 1) {
buzzerFreq = 5;
buzzerPattern = 1;
} else if (enable == 1) {
buzzerFreq = 0;
buzzerPattern = 1;
}
pwmrl = powf((pwmrl/4), 3) / 255885;
pwml = -pwmrl; pwml = -pwmrl;
pwmr = pwmrl; pwmr = pwmrl;
@ -220,7 +228,7 @@ void DMA1_Channel1_IRQHandler() {
buzzerTimer++; buzzerTimer++;
if (buzzerFreq != 0 && (buzzerTimer / 1500) % (buzzerPattern + 1) == 0) { if (buzzerFreq != 0 && (buzzerTimer / 5000) % (buzzerPattern + 1) == 0) {
if (buzzerTimer % buzzerFreq == 0) { if (buzzerTimer % buzzerFreq == 0) {
HAL_GPIO_TogglePin(BUZZER_PORT, BUZZER_PIN); HAL_GPIO_TogglePin(BUZZER_PORT, BUZZER_PIN);
} }

View File

@ -133,6 +133,8 @@ int main(void) {
if (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) { if (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {
enable = 0; enable = 0;
while (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {} while (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {}
buzzerFreq = 0;
buzzerPattern = 0;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
buzzerFreq = i; buzzerFreq = i;
HAL_Delay(100); HAL_Delay(100);

File diff suppressed because it is too large Load Diff