|
|
@ -1,16 +1,19 @@ |
|
|
|
#include <common.h> |
|
|
|
#include <common.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "utils/usart.h" |
|
|
|
#include "utils/usart.h" |
|
|
|
#include "utils/timebase.h" |
|
|
|
#include "utils/timebase.h" |
|
|
|
#include "utils/debounce.h" |
|
|
|
#include "utils/debounce.h" |
|
|
|
|
|
|
|
#include "utils/str_utils.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "init.h" |
|
|
|
#include "init.h" |
|
|
|
#include "blink.h" |
|
|
|
#include "blink.h" |
|
|
|
|
|
|
|
#include "capture.h" |
|
|
|
|
|
|
|
|
|
|
|
void say_hello(void) |
|
|
|
// Gate state
|
|
|
|
{ |
|
|
|
static bool gate_closed = false; |
|
|
|
usart_tx_string(USART3, "HELLO\r\n"); |
|
|
|
static uint32_t gate_cnt = 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** IRQ */ |
|
|
|
/** IRQ */ |
|
|
@ -24,8 +27,34 @@ void USART2_IRQHandler(void) |
|
|
|
if (USART2_SR & USART_SR_RXNE) { |
|
|
|
if (USART2_SR & USART_SR_RXNE) { |
|
|
|
blue_blink(); |
|
|
|
blue_blink(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// handle incoming char.
|
|
|
|
char c = usart_rx_char(USART2); |
|
|
|
char c = usart_rx_char(USART2); |
|
|
|
usart_tx_char(USART2, c); |
|
|
|
|
|
|
|
|
|
|
|
switch (c) { |
|
|
|
|
|
|
|
case 'g': // nulovat pocitadlo preruseni
|
|
|
|
|
|
|
|
gate_cnt = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'm': // zvysit DAC hodnotu
|
|
|
|
|
|
|
|
if (DAC_DHR12R1 < 4095) DAC_DHR12R1 += 117; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'n': // snizit DAC hodnotu
|
|
|
|
|
|
|
|
if (DAC_DHR12R1 > 0) DAC_DHR12R1 -= 117; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'b': // zvysit PWM stridu
|
|
|
|
|
|
|
|
if (TIM3_CCR1 < 1000) TIM3_CCR1 += 50; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'd': // snizit PWM stridu
|
|
|
|
|
|
|
|
if (TIM3_CCR1 > 0) TIM3_CCR1 -= 50; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USART2_SR ^= USART_SR_RXNE; |
|
|
|
USART2_SR ^= USART_SR_RXNE; |
|
|
|
} |
|
|
|
} |
|
|
@ -33,7 +62,21 @@ void USART2_IRQHandler(void) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Called by startup script, before main() */ |
|
|
|
// Gate close handler
|
|
|
|
|
|
|
|
void gate_close(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
gate_closed = 1; |
|
|
|
|
|
|
|
gate_cnt++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Gate open handler
|
|
|
|
|
|
|
|
void gate_open(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
gate_closed = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Init peripherals; Called by startup script, before main() */ |
|
|
|
void SystemInit(void) |
|
|
|
void SystemInit(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
init_clock(); |
|
|
|
init_clock(); |
|
|
@ -41,12 +84,62 @@ void SystemInit(void) |
|
|
|
init_gpios(); |
|
|
|
init_gpios(); |
|
|
|
init_usart(); |
|
|
|
init_usart(); |
|
|
|
init_adc(); |
|
|
|
init_adc(); |
|
|
|
|
|
|
|
init_dac(); |
|
|
|
|
|
|
|
init_pwm1(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register_periodic_task(green_toggle, 1000); // indicate running state
|
|
|
|
|
|
|
|
|
|
|
|
register_periodic_task(green_toggle, 1000); |
|
|
|
register_debounced_pin(GPIOB, 11, gate_close, gate_open); // gate handler
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(void) |
|
|
|
int main(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
while (1); |
|
|
|
char buf[200]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
usart_tx_string(USART2, "DAQ system started.\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (1) { |
|
|
|
|
|
|
|
delay_ms(200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float cels = measure_temp(); |
|
|
|
|
|
|
|
float angle = measure_angle(); |
|
|
|
|
|
|
|
float resis = measure_resistance(); |
|
|
|
|
|
|
|
float expos = measure_exposure(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_reset(buf); |
|
|
|
|
|
|
|
buf_append_str(buf, "T "); |
|
|
|
|
|
|
|
buf_append_flt(buf, cels, 1); |
|
|
|
|
|
|
|
buf_append_str(buf, "°C | "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_append_str(buf, "An "); |
|
|
|
|
|
|
|
buf_append_flt(buf, angle, 1); |
|
|
|
|
|
|
|
buf_append_str(buf, "° | "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_append_str(buf, "R "); |
|
|
|
|
|
|
|
buf_append_flt(buf, resis, 1); |
|
|
|
|
|
|
|
buf_append_str(buf, " | "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_append_str(buf, "L "); |
|
|
|
|
|
|
|
buf_append_flt(buf, expos, 1); |
|
|
|
|
|
|
|
buf_append_str(buf, "% | "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_append_str(buf, "G "); |
|
|
|
|
|
|
|
buf_append_str(buf, gate_closed ? "1" : "0"); |
|
|
|
|
|
|
|
buf_append_str(buf, ", #"); |
|
|
|
|
|
|
|
buf_append_int(buf, gate_cnt); |
|
|
|
|
|
|
|
buf_append_str(buf, " | "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_append_str(buf, "DA "); |
|
|
|
|
|
|
|
buf_append_int(buf, DAC_DHR12R1); |
|
|
|
|
|
|
|
buf_append_str(buf, " | "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_append_str(buf, "PWM "); |
|
|
|
|
|
|
|
buf_append_int(buf, TIM3_CCR1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_append_str(buf, "\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
usart_tx_string(USART2, buf); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|