This commit is contained in:
eddyem 2019-08-08 09:26:08 +03:00
parent abdbac3e38
commit 7e9f81ca54
9 changed files with 37 additions and 18 deletions

View File

@ -8,10 +8,10 @@ MCU ?= F103x8
# density (stm32f10x.h, lines 70-84)
DENSITY ?= MD
# change this linking script depending on particular MCU model,
LDSCRIPT ?= stm32f103x8.ld
LDSCRIPT ?= stm32f103xB.ld
DEFS = -DVERSION=\"0.0.1\"
# debug
DEFS += -DEBUG
#DEFS += -DEBUG
# proxy GPS output over USART1
DEFS += -DUSART1PROXY

View File

@ -19,8 +19,15 @@ Chronometer for downhill competitions
- PC13 - buzzer
## LEDS
- LED0 - shining when there's no PPS signal, fades for 0.25s on PPS
- LED1 - don't shines if no GPS found, shines when time not valid, blinks when time valid
### Not implemented yet:
- PA5,6,7 (SCK, MISO, MOSI) - SPI
- PB0 - TRIG4 - ADC channel 8
- PB6/7 (SCL, SDA) - I2C

Binary file not shown.

View File

@ -39,9 +39,7 @@
#include "adc.h"
#include "flash.h"
#include "lidar.h"
#ifdef EBUG
#include "usart.h"
#endif
#include "usart.h" // DBG
#include <string.h> // memcpy
extern uint32_t _edata, _etext, _sdata;
@ -49,22 +47,22 @@ static int maxnum = FLASH_BLOCK_SIZE / sizeof(user_conf);
typedef struct{
const user_conf all_stored;
const user_conf all_stored;
} flash_storage;
#define USERCONF_INITIALIZER { \
.userconf_sz = sizeof(user_conf) \
,.dist_min = LIDAR_MIN_DIST \
,.dist_max = LIDAR_MAX_DIST \
.userconf_sz = sizeof(user_conf) \
,.dist_min = LIDAR_MIN_DIST \
,.dist_max = LIDAR_MAX_DIST \
,.trig_pullups = 0xff \
,.trigstate = 0 \
,.trigpause = {400, 400, 400, 300, 300} \
,.ADC_min = ADC_MIN_VAL \
,.ADC_max = ADC_MAX_VAL \
}
}
__attribute__((section(".myvars"))) static const flash_storage Flash_Storage = {
.all_stored = USERCONF_INITIALIZER
.all_stored = USERCONF_INITIALIZER
};
static const user_conf *Flash_Data = &Flash_Storage.all_stored;

View File

@ -46,9 +46,11 @@ extern uint8_t buzzer_on;
// PPS and triggers state
// amount of triggers, should be less than 9; 5 - 0..2 - switches, 3 - LIDAR, 4 - ADC
#define TRIGGERS_AMOUNT (5)
#define TRIGGERS_AMOUNT (5)
// number of LIDAR trigger
#define LIDAR_TRIGGER (3)
// amount of digital triggers (on interrupts)
#define DIGTRIG_AMOUNT (3)
#define DIGTRIG_AMOUNT (3)
uint8_t gettrig(uint8_t N);
void fillshotms(int i);

View File

@ -50,7 +50,7 @@ void parse_lidar_data(char *txt){
savetrigtime();
triggered = 1;
lidar_triggered_dist = last_lidar_dist;
fillshotms(3);
fillshotms(LIDAR_TRIGGER);
#ifdef EBUG
SEND("Triggered! distance=");
printu(1, last_lidar_dist);

View File

@ -240,7 +240,7 @@ int main(void){
}
#endif
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
//iwdg_setup();
iwdg_setup();
while (1){
IWDG->KR = IWDG_REFRESH; // refresh watchdog

View File

@ -19,6 +19,7 @@
#include "adc.h"
#include "flash.h"
#include "GPS.h"
#include "lidar.h"
#include "str.h"
#include "time.h"
#include "usart.h"
@ -285,8 +286,14 @@ void show_trigger_shot(uint8_t tshot){
if(tshot & X) tshot &= ~X;
else continue;
if(trigger_shot & X) trigger_shot &= ~X;
USB_send("TRIG");
sendu(i);
if(i == LIDAR_TRIGGER){
USB_send("LIDAR, dist=");
sendu(lidar_triggered_dist);
USB_send(", TRIG=");
}else{
USB_send("TRIG");
sendu(i);
}
USB_send("=");
USB_send(get_time(&shottime[i].Time, shottime[i].millis));
USB_send("\n");

View File

@ -121,8 +121,9 @@ char *get_time(curtime *Tm, uint32_t T){
#ifdef EBUG
int32_t ticksdiff=0, timecntr=0, timerval, Tms1;
int32_t timerval, Tms1;
#endif
int32_t timecntr=0, ticksdiff=0;
uint32_t last_corr_time = 0;
@ -145,8 +146,10 @@ void systick_correction(){
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // stop systick for a while
uint32_t systick_val = SysTick->VAL, L = SysTick->LOAD + 1;
int32_t timer_val = Timer;
#ifdef EBUG
timerval = Timer;
Tms1 = Tms;
#endif
Timer = 0;
SysTick->VAL = SysTick->LOAD;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // start it again
@ -155,7 +158,9 @@ void systick_correction(){
if(last_corr_time){
if(Tms - last_corr_time < 1500){ // there was perevious PPS signal
int32_t D = L * (Tms - 1000 - last_corr_time) + (SysTick->LOAD - systick_val); // amount of spare ticks
#ifdef EBUG
++timecntr;
#endif
ticksdiff += D;
uint32_t ticksabs = (ticksdiff < 0) ? -ticksdiff : ticksdiff;
// 10000 == 30 seconds * 1000 interrupts per second