diff --git a/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_prl b/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_prl index fde1055..bd88ef8 100644 --- a/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_prl +++ b/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_prl @@ -3,10 +3,12 @@ "active_layer": 0, "active_layer_preset": "All Layers", "auto_track_width": true, + "hidden_netclasses": [], "hidden_nets": [], "high_contrast_mode": 0, "net_color_mode": 1, "opacity": { + "images": 0.6, "pads": 1.0, "tracks": 1.0, "vias": 1.0, diff --git a/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_pro b/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_pro index c252899..b3d2e47 100644 --- a/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_pro +++ b/F0:F030,F042,F072/usbcan_relay/kicad/stm32.kicad_pro @@ -1,5 +1,6 @@ { "board": { + "3dviewports": [], "design_settings": { "defaults": { "board_outline_line_width": 0.15, @@ -138,7 +139,8 @@ "zones_allow_external_fillets": false, "zones_use_no_outline": true }, - "layer_presets": [] + "layer_presets": [], + "viewports": [] }, "boards": [], "cvpcb": { @@ -322,18 +324,23 @@ "rule_severities": { "bus_definition_conflict": "error", "bus_entry_needed": "error", - "bus_label_syntax": "error", "bus_to_bus_conflict": "error", "bus_to_net_conflict": "error", + "conflicting_netclasses": "error", "different_unit_footprint": "error", "different_unit_net": "error", "duplicate_reference": "error", "duplicate_sheet_names": "error", + "endpoint_off_grid": "warning", "extra_units": "error", "global_label_dangling": "warning", "hier_label_mismatch": "error", "label_dangling": "error", "lib_symbol_issues": "warning", + "missing_bidi_pin": "warning", + "missing_input_pin": "warning", + "missing_power_pin": "error", + "missing_unit": "warning", "multiple_net_names": "warning", "net_not_bus_member": "warning", "no_connect_connected": "warning", @@ -343,6 +350,7 @@ "pin_to_pin": "warning", "power_pin_not_driven": "error", "similar_labels": "warning", + "simulation_model_issue": "ignore", "unannotated": "error", "unit_value_mismatch": "error", "unresolved_variable": "error", @@ -360,7 +368,7 @@ "net_settings": { "classes": [ { - "bus_width": 12.0, + "bus_width": 12, "clearance": 0.2, "diff_pair_gap": 0.25, "diff_pair_via_gap": 0.25, @@ -374,10 +382,10 @@ "track_width": 0.2, "via_diameter": 0.8, "via_drill": 0.4, - "wire_width": 6.0 + "wire_width": 6 }, { - "bus_width": 12.0, + "bus_width": 12, "clearance": 0.3, "diff_pair_gap": 0.25, "diff_pair_via_gap": 0.25, @@ -386,16 +394,15 @@ "microvia_diameter": 0.3, "microvia_drill": 0.1, "name": "0.5", - "nets": [], "pcb_color": "rgba(0, 0, 0, 0.000)", "schematic_color": "rgba(0, 0, 0, 0.000)", "track_width": 0.5, "via_diameter": 1.2, "via_drill": 0.6, - "wire_width": 6.0 + "wire_width": 6 }, { - "bus_width": 12.0, + "bus_width": 12, "clearance": 0.5, "diff_pair_gap": 0.25, "diff_pair_via_gap": 0.25, @@ -404,19 +411,20 @@ "microvia_diameter": 0.3, "microvia_drill": 0.1, "name": "1", - "nets": [], "pcb_color": "rgba(0, 0, 0, 0.000)", "schematic_color": "rgba(0, 0, 0, 0.000)", "track_width": 1.0, "via_diameter": 1.2, "via_drill": 0.6, - "wire_width": 6.0 + "wire_width": 6 } ], "meta": { - "version": 2 + "version": 3 }, - "net_colors": null + "net_colors": null, + "netclass_assignments": null, + "netclass_patterns": [] }, "pcbnew": { "last_paths": { @@ -432,6 +440,8 @@ "schematic": { "annotate_start_num": 0, "drawing": { + "dashed_lines_dash_length_ratio": 12.0, + "dashed_lines_gap_length_ratio": 3.0, "default_bus_thickness": 12.0, "default_junction_size": 40.0, "default_line_thickness": 6.0, @@ -466,7 +476,11 @@ "page_layout_descr_file": "", "plot_directory": "", "spice_adjust_passive_values": false, + "spice_current_sheet_as_root": false, "spice_external_command": "spice \"%I\"", + "spice_model_current_sheet_as_root": true, + "spice_save_all_currents": false, + "spice_save_all_voltages": false, "subpart_first_id": 65, "subpart_id_separator": 0 }, diff --git a/F1:F103/shutter/Readme.md b/F1:F103/shutter/Readme.md index f61bfa6..999afd0 100644 --- a/F1:F103/shutter/Readme.md +++ b/F1:F103/shutter/Readme.md @@ -26,11 +26,29 @@ You can find the device in `/dev/shutterX` (symlink to `/dev/ttyUSBX`). ## Commands -* '0' - shutter CLO -* '1' - shutter OPE -* '2' - shutter HIZ +### debugging options: +* '0' - shutter OPE +* '1' - shutter CLO +* '2' - shutter OFF +* '3' - shutter HIZ +* 'W' - test watchdog + +### configuration: +* '< n' - voltage on discharged capacitor (*100) +* '> n' - voltage on fully charged capacitor (*100) +* '# n' - duration of electrical pulse to open/close shutter (ms) +* '$ n' - duration of mechanical work to completely open/close shutter (ms) +* '* n' - shutter voltage multiplier +* '/ n' - shutter voltage divider (V=Vadc*M/D) +* 'c n' - open shutter when CCD ext level is n (0/1) +* 'd' - dump current config +* 'e' - erase flash storage +* 'h n' - shutter is opened when hall level is n (0/1) +* 's' - save configuration into flash + +### common control: * 'A' - get raw ADC values -* 'C' - close shutter / abort exposition +* 'C' - close shutter / abort exposition * 'E n' - expose for n milliseconds * 'O' - open shutter * 'R' - software reset @@ -39,11 +57,11 @@ You can find the device in `/dev/shutterX` (symlink to `/dev/ttyUSBX`). * 'T' - get Tms * 'v' - get Vdd (/100V) * 'V' - get shutter voltage (/100V) -* 'W' - test watchdog + If you will enter wrong long message, will receive its echo back. Any wrong short command will show help list. -### Shutter control +## Shutter control Commands '0', '1' and '2' should be used only for debugging purposes. To open/close shutter use only 'O', 'C' and 'E' commands. @@ -55,7 +73,7 @@ Command 'E' could return `OK`, `ERR` or `ERRNUM`/`I32OVERFLOW` in wrong number f When exposition starts you will receive message `OK` and `shutter=opened`. After its end you'll got `exptime=...`, `shutter=closed`. If shutter can't be closed, you will give a lots of "exp=cantclose" and different error messages until problem be solved. To stop this error messages give command 'O'. -### Different commands +## Different commands * 'A' will show raw values for all ADC channels: 0. - capacitor voltage, 1 - MCU temperature, 2 - MCU Vdd. You will give messages like `adcX=val`. * 't' - `mcut=val`, where val = T*10 degrC. @@ -68,8 +86,27 @@ If shutter can't be closed, you will give a lots of "exp=cantclose" and differen * 'S' - several answers: * `shutter=`: `closed`, `opened`, `error`, `process`, `wait` or `exposing` - shutter state + * `expfor=...` (only when exposing by command Exxx) - show given exposition time * `exptime=...` (only when shutter is opened) - show time since opening * `regstate=`: `open`, `close`, `off` or `hiZ` - TLE5205 outputs state - * `fbstate=`: `0` or `1` - TLE5205 FB out state (1 - error) + * `fbstate=`: `0` or `1` - TLE5205 FB out state (1 - error: insufficient voltage or shutter absent) * `hall=`: `0` or `1` - 1 for opened shutter, 0 for closed * `ccd=`: `0` or `1` - 1 for active (closed contacts) state of "CCD" input + +## Configuration +All configuration stored in MCU flash memory, to dump current config just enter command 'd' and you will give an answer like +``` +userconf_sz=16 +ccdactive=1 +hallactive=0 +minvoltage=400 +workvoltage=700 +shuttertime=20 +waitingtime=30 +shtrvmul=143 +shtrdiv=25 +``` + +* `` +* `ccdactive` - is level of 'CCD' input to open shutter (1 to open on high and 0 to open on low signal) +* `hallactive` \ No newline at end of file diff --git a/F1:F103/shutter/adc.c b/F1:F103/shutter/adc.c index 0390993..723199a 100644 --- a/F1:F103/shutter/adc.c +++ b/F1:F103/shutter/adc.c @@ -44,8 +44,11 @@ void adc_setup(){ ADC1->SQR3 = (3 << 0) | (16<<5) | (17 << 10); ADC1->SQR1 = (NUMBER_OF_ADC_CHANNELS - 1) << 20; // amount of conversions ADC1->CR1 = ADC_CR1_SCAN; // scan mode - // continuous mode & DMA; enable vref & Tsens; wake up ADC - ADC1->CR2 = ADC_CR2_DMA | ADC_CR2_TSVREFE | ADC_CR2_CONT | ADC_CR2_ADON; + // DMA, continuous mode; enable vref & Tsens; enable SWSTART as trigger + ADC1->CR2 = ADC_CR2_DMA | ADC_CR2_TSVREFE | ADC_CR2_CONT | ADC_CR2_EXTSEL | ADC_CR2_EXTTRIG; + // wake up ADC + ADC1->CR2 |= ADC_CR2_ADON; + __DSB(); // wait for Tstab - at least 1us while(++ctr < 0xff) nop(); // calibration @@ -53,12 +56,9 @@ void adc_setup(){ ctr = 0; while((ADC1->CR2 & ADC_CR2_RSTCAL) && ++ctr < 0xfffff); ADC1->CR2 |= ADC_CR2_CAL; ctr = 0; while((ADC1->CR2 & ADC_CR2_CAL) && ++ctr < 0xfffff); - // turn ON ADC - //ADC1->CR2 |= ADC_CR2_ADON; - __DSB(); + // clear possible errors and start ADC1->SR = 0; ADC1->CR2 |= ADC_CR2_SWSTART; - } diff --git a/F1:F103/shutter/flash.c b/F1:F103/shutter/flash.c index 68972cb..f400eb2 100644 --- a/F1:F103/shutter/flash.c +++ b/F1:F103/shutter/flash.c @@ -31,8 +31,12 @@ static uint32_t maxCnum = 1024 / sizeof(user_conf); // can't use blocksize here .userconf_sz = sizeof(user_conf) \ ,.hallactive = 0 \ ,.ccdactive = 1 \ - ,.minvoltage = 500 \ - ,.workvoltage = 1300 \ + ,.minvoltage = 400 \ + ,.workvoltage = 700 \ + ,.shutterrime = 20 \ + ,.waitingtime = 30 \ + ,.shtrVmul = 143 \ + ,.shtrVdiv = 25 \ } static int write2flash(const void*, const void*, uint32_t); @@ -180,5 +184,9 @@ void dump_userconf(){ USB_sendstr("\nhallactive="); USB_putbyte('0' + the_conf.hallactive); USB_sendstr("\nminvoltage="); USB_sendstr(u2str(the_conf.minvoltage)); USB_sendstr("\nworkvoltage="); USB_sendstr(u2str(the_conf.workvoltage)); + USB_sendstr("\nshuttertime="); USB_sendstr(u2str(the_conf.shutterrime)); + USB_sendstr("\nwaitingtime="); USB_sendstr(u2str(the_conf.waitingtime)); + USB_sendstr("\nshtrvmul="); USB_sendstr(u2str(the_conf.shtrVmul)); + USB_sendstr("\nshtrdiv="); USB_sendstr(u2str(the_conf.shtrVdiv)); newline(); } diff --git a/F1:F103/shutter/flash.h b/F1:F103/shutter/flash.h index e24fce7..d701410 100644 --- a/F1:F103/shutter/flash.h +++ b/F1:F103/shutter/flash.h @@ -32,6 +32,10 @@ typedef struct __attribute__((packed, aligned(4))){ uint8_t hallactive : 1; // hall sensor active (shutter is opened when): 0 - low, 1 - high uint16_t minvoltage; // minimal voltage on C (*100) uint16_t workvoltage; // working voltage (*100) + uint16_t shutterrime; // opening/closing time (ms) + uint16_t waitingtime; // time to wait for mechanical work done (ms) + uint16_t shtrVmul; // multiplier of shutter voltage calculation + uint16_t shtrVdiv; // divider -//- } user_conf; extern user_conf the_conf; diff --git a/F1:F103/shutter/hardware.c b/F1:F103/shutter/hardware.c index ba875bc..83ffaad 100644 --- a/F1:F103/shutter/hardware.c +++ b/F1:F103/shutter/hardware.c @@ -17,6 +17,7 @@ */ #include "adc.h" +#include "flash.h" #include "hardware.h" static inline void iwdg_setup(){ @@ -67,12 +68,13 @@ static inline void gpio_setup(){ // ADC (PA3), OD out (PA5,6), PU in (PA7) GPIOA->ODR = 1 << 7; SHTROFF(); - GPIOA->CRL = CRL(3, CNF_ANALOG|MODE_INPUT) | CRL(5, CNF_PPOUTPUT|MODE_SLOW) | CRL(6, CNF_PPOUTPUT|MODE_SLOW) | + GPIOA->CRL = CRL(3, CNF_ANALOG | MODE_INPUT) | CRL(5, CNF_PPOUTPUT|MODE_SLOW) | CRL(6, CNF_PPOUTPUT|MODE_SLOW) | CRL(7, CNF_PUDINPUT | MODE_INPUT); // USB pullup (PA10) - pushpull output GPIOA->CRH = CRH(8, CNF_PPOUTPUT | MODE_SLOW) | CRH(10, CNF_PPOUTPUT | MODE_SLOW); - // hall/ccd - GPIOB->ODR = 1 | 1<<11; + // hall/ccd: pulled up or down depending on settings + // if ccdactive==0 - shutter is closed when no output signals + GPIOB->ODR = ((the_conf.hallactive) ? 0: 1) | ((the_conf.ccdactive) ? 0 : 1<<11); GPIOB->CRL = CRL(0, CNF_PUDINPUT | MODE_INPUT); GPIOB->CRH = CRH(11, CNF_PUDINPUT | MODE_INPUT); } @@ -83,3 +85,8 @@ void hw_setup(){ adc_setup(); } +uint32_t getShutterVoltage(){ + uint32_t val = getADCvoltage(CHSHTR); + val *= the_conf.shtrVmul; + return val / the_conf.shtrVdiv; +} diff --git a/F1:F103/shutter/hardware.h b/F1:F103/shutter/hardware.h index bc5fb4e..5ab75ce 100644 --- a/F1:F103/shutter/hardware.h +++ b/F1:F103/shutter/hardware.h @@ -57,10 +57,7 @@ typedef enum{ #define CHKHALL() ((HALLPIN == (BTNPORT->IDR & HALLPIN)) == the_conf.hallactive) #define CHKCCD() ((CCDPIN == (BTNPORT->IDR & CCDPIN)) == the_conf.ccdactive) -// multiplyer of shutter voltage (due to R divider) -#define SHTRVMUL (13) - extern volatile uint32_t Tms; void hw_setup(); - +uint32_t getShutterVoltage(); diff --git a/F1:F103/shutter/main.c b/F1:F103/shutter/main.c index 04d102d..4da817c 100644 --- a/F1:F103/shutter/main.c +++ b/F1:F103/shutter/main.c @@ -35,16 +35,15 @@ void sys_tick_handler(void){ int main(void){ char inbuff[MAXSTRLEN+1]; StartHSE(); - hw_setup(); SysTick_Config(72000); USBPU_OFF(); - hw_setup(); flashstorage_init(); + hw_setup(); USB_setup(); + // close shutter and only after that turn on USB pullup + while(!close_shutter() && Tms < the_conf.waitingtime) IWDG->KR = IWDG_REFRESH; USBPU_ON(); - close_shutter(); - uint32_t Terr = Tms + 2*ERRPERIOD; while(1){ IWDG->KR = IWDG_REFRESH; // refresh watchdog diff --git a/F1:F103/shutter/proto.c b/F1:F103/shutter/proto.c index 0dee2de..377d0cb 100644 --- a/F1:F103/shutter/proto.c +++ b/F1:F103/shutter/proto.c @@ -156,16 +156,7 @@ char *getnum(const char *txt, uint32_t *N){ const char* helpmsg = "https://github.com/eddyem/stm32samples/tree/master/F1:F103/shutter build#" BUILD_NUMBER " @ " BUILD_DATE "\n" - "'0' - shutter CLO\n" - "'1' - shutter OPE\n" - "'2' - shutter HIZ\n" - "'< n' - voltage on discharged capacitor (*100)\n" - "'> n' - voltage on fully charged capacitor (*100)\n" - "'c n' - open shutter when CCD ext level is n (0/1)\n" - "'d' - dump current config\n" - "'e' - erase flash storage\n" - "'h n' - shutter is opened when hall level is n (0/1)\n" - "'s' - save configuration into flash\n" + " common control:\n" "'A' - get raw ADC values\n" "'C' - close shutter / abort exposition\n" "'E n' - expose for n milliseconds\n" @@ -176,6 +167,23 @@ const char* helpmsg = "'T' - get Tms\n" "'v' - get Vdd (/100V)\n" "'V' - get shutter voltage (/100V)\n" + " configuration:\n" + "'< n' - voltage on discharged capacitor (*100)\n" + "'> n' - voltage on fully charged capacitor (*100)\n" + "'# n' - duration of electrical pulse to open/close shutter (ms)\n" + "'$ n' - duration of mechanical work to completely open/close shutter (ms)\n" + "'* n' - shutter voltage multiplier\n" + "'/ n' - shutter voltage divider (V=Vadc*M/D)\n" + "'c n' - open shutter when CCD ext level is n (0/1)\n" + "'d' - dump current config\n" + "'e' - erase flash storage\n" + "'h n' - shutter is opened when hall level is n (0/1)\n" + "'s' - save configuration into flash\n" + " debugging options:\n" + "'0' - shutter OPE\n" + "'1' - shutter CLO\n" + "'2' - shutter OFF\n" + "'3' - shutter HIZ\n" "'W' - test watchdog\n" ; @@ -198,19 +206,22 @@ void bufputchar(char c){ static const char *OK = "OK", *ERR = "ERR"; const char *parse_cmd(const char *buf){ - uint32_t u3; initbuf(); if(buf[1] == '\n' || buf[1] == '\r' || !buf[1]){ // one symbol commands switch(*buf){ case '0': - SHTRCLOSE(); - add2buf("regstate=close"); - break; - case '1': SHTROPEN(); add2buf("regstate=open"); break; + case '1': + SHTRCLOSE(); + add2buf("regstate=close"); + break; case '2': + SHTROFF(); + add2buf("regstate=off"); + break; + case '3': SHTRHIZ(); add2buf("regstate=hiz"); break; @@ -267,9 +278,8 @@ const char *parse_cmd(const char *buf){ add2buf(u2str(getVdd())); break; case 'V': - u3 = getADCvoltage(CHSHTR) * SHTRVMUL; add2buf("voltage="); - add2buf(u2str(u3)); + add2buf(u2str(getShutterVoltage())); break; case 'W': USB_sendstr("Wait for reboot\n"); @@ -301,6 +311,30 @@ const char *parse_cmd(const char *buf){ the_conf.workvoltage = Num; add2buf("workvoltage="); add2buf(u2str(the_conf.workvoltage)); break; + case '#': // shuttertime + if(errnum) break; + if(Num < 5 || Num > 1000) return "ERRVAL\n"; + the_conf.shutterrime = Num; + add2buf("shuttertime="); add2buf(u2str(the_conf.shutterrime)); + break; + case '$': // waitingtime + if(errnum) break; + if(Num < 5 || Num > 1000) return "ERRVAL\n"; + the_conf.waitingtime = Num; + add2buf("waitingtime="); add2buf(u2str(the_conf.waitingtime)); + break; + case '*': // mult + if(errnum) break; + if(Num < 1) return "ERRVAL\n"; // avoid zeroing + the_conf.shtrVmul = Num; + add2buf("shtrvmul="); add2buf(u2str(the_conf.shtrVmul)); + break; + case '/': // div + if(errnum) break; + if(Num < 1) return "ERRVAL\n"; // avoid zero dividing + the_conf.shtrVdiv = Num; + add2buf("shtrvdiv="); add2buf(u2str(the_conf.shtrVdiv)); + break; case 'c': // CCD active @ if(errnum) break; the_conf.ccdactive = Num; diff --git a/F1:F103/shutter/shutter.bin b/F1:F103/shutter/shutter.bin index 78419b0..31e0f25 100755 Binary files a/F1:F103/shutter/shutter.bin and b/F1:F103/shutter/shutter.bin differ diff --git a/F1:F103/shutter/shutter.c b/F1:F103/shutter/shutter.c index 1e64615..6419177 100644 --- a/F1:F103/shutter/shutter.c +++ b/F1:F103/shutter/shutter.c @@ -30,7 +30,12 @@ static const char *states[SHUTTER_STATE_AMOUNT] = { [SHUTTER_EXPOSE] = "exposing", }; -static const char *regstates[4] = {"open", "close", "off", "hiZ"}; +static const char *regstates[4] = { + [REG_OPEN] = "open", + [REG_CLOSE] = "close", + [REG_OFF] = "off", + [REG_HIZ] = "hiZ" +}; static const char *opcl[2] = {"closed", "opened"}; @@ -39,13 +44,18 @@ static shutter_state nextstate = SHUTTER_RELAX; static uint32_t Tstart = 0, Texp = 0, Topened = 0; +/** + * @brief changestate - open/close shutter and set next state to nxt + * @return TRUE if success + */ static int changestate(int open, shutter_state nxt){ + if(shutterstate != SHUTTER_RELAX && shutterstate != SHUTTER_EXPOSE) return FALSE; // don't ready if(open == CHKHALL()){ - shutterstate = SHUTTER_RELAX; + //shutterstate = SHUTTER_RELAX; return TRUE; // already opened or closed } - if(getADCvoltage(CHSHTR) < the_conf.workvoltage / SHTRVMUL) return FALSE; - if(shutterstate == SHUTTER_ERROR) return FALSE; + if(getShutterVoltage() < the_conf.workvoltage) return FALSE; + //if(shutterstate == SHUTTER_ERROR) return FALSE; if(open) SHTROPEN(); else SHTRCLOSE(); shutterstate = SHUTTER_PROCESS; @@ -74,12 +84,23 @@ int expose_shutter(uint32_t exptime){ void process_shutter(){ static uint32_t T = 0; - uint32_t V = getADCvoltage(CHSHTR)*SHTRVMUL; + uint32_t V = getShutterVoltage(); switch(shutterstate){ - case SHUTTER_ERROR: // error state: no shutter? - SHTROFF(); - shutterstate = SHUTTER_WAIT; - Tstart = Tms; + case SHUTTER_ERROR: // error state: no shutter? - switch HIZ/OFF each 10ms + if(SHTRSTATE() == REG_HIZ){ // check in HiZ state: if the error still occurs? + if(!CHKFB()){ + shutterstate = SHUTTER_RELAX; + nextstate = SHUTTER_RELAX; + }else if(Tms - T > 10){ + T = Tms; + SHTROFF(); // turn off for 10ms + } + }else{ + if(Tms - T > 10){ + T = Tms; + SHTRHIZ(); // and check error again + } + } break; case SHUTTER_PROCESS: // process opening or closing #ifdef EBUG @@ -89,21 +110,21 @@ void process_shutter(){ USB_putbyte('\n'); } #endif - if(Tms - Tstart > SHUTTER_TIME || V < the_conf.minvoltage){ + if(Tms - Tstart > the_conf.shutterrime || V < the_conf.minvoltage){ SHTROFF(); shutterstate = SHUTTER_WAIT; Tstart = Tms; } break; case SHUTTER_WAIT: // wait for mechanical work done - if(Tms - Tstart > WAITING_TIME){ + if(Tms - Tstart > the_conf.waitingtime){ SHTRHIZ(); shutterstate = nextstate; int h = CHKHALL(); if(h) Topened = Tms; else{ USB_sendstr("exptime="); - USB_sendstr(u2str(Tms - Topened - SHUTTER_TIME)); + USB_sendstr(u2str(Tms - Topened - the_conf.shutterrime)); USB_putbyte('\n'); } USB_sendstr("shutter="); @@ -115,10 +136,18 @@ void process_shutter(){ // now Tstart is time when shutter was opened; wait until Tms - Tstart >= Texp if(Tms - Tstart < Texp || T == Tms) break; // once per 1ms T = Tms; - if(!close_shutter()) USB_sendstr("exp=cantclose\n"); + if(!close_shutter()){ + if(Tms - Tstart > Texp + the_conf.waitingtime){ // try to close not more than `waitingtime` ms + USB_sendstr("exp=cantclose\n"); + shutterstate = SHUTTER_ERROR; + } + } break; default: - if(CHKFB()) shutterstate = SHUTTER_ERROR; + if(CHKFB()){ + shutterstate = SHUTTER_ERROR; + T = Tms; + } break; } static uint8_t oldbtnstate = 0; @@ -141,6 +170,9 @@ void print_shutter_state(){ if(shutterstate != SHUTTER_RELAX) add2buf(states[shutterstate]); else add2buf(opcl[CHKHALL()]); if(CHKHALL()){ + if(shutterstate == SHUTTER_EXPOSE){ + add2buf("\nexpfor="); add2buf(u2str(Texp)); + } add2buf("\nexptime="); add2buf(u2str(Tms - Topened)); } diff --git a/F1:F103/shutter/shutter.creator.user b/F1:F103/shutter/shutter.creator.user index 776d6d6..3bbad23 100644 --- a/F1:F103/shutter/shutter.creator.user +++ b/F1:F103/shutter/shutter.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 0 + 0 ProjectExplorer.Project.EditorSettings @@ -28,7 +28,7 @@ QmlJSGlobal - 2 + 2 KOI8-R false 4 @@ -54,16 +54,29 @@ *.md, *.MD, Makefile true true + true ProjectExplorer.Project.PluginSettings + + true + false + true + true + true + true + + + 0 + true true true Builtin.DefaultTidyAndClazy 4 + false @@ -78,9 +91,9 @@ Desktop Desktop {91347f2c-5221-46a7-80b1-0a054ca02f79} - 0 - 0 - 0 + 0 + 0 + 0 /home/eddy/Docs/SAO/ELECTRONICS/STM32/F1-srcs/shutter @@ -91,7 +104,7 @@ true GenericProjectManager.GenericMakeStep - 1 + 1 Сборка Сборка ProjectExplorer.BuildSteps.Build @@ -104,7 +117,7 @@ true GenericProjectManager.GenericMakeStep - 1 + 1 Очистка Очистка ProjectExplorer.BuildSteps.Clean @@ -117,10 +130,10 @@ По умолчанию GenericProjectManager.GenericBuildConfiguration - 1 + 1 - 0 + 0 Развёртывание Развёртывание ProjectExplorer.BuildSteps.Deploy @@ -130,24 +143,26 @@ false ProjectExplorer.DefaultDeployConfiguration - 1 + 1 + true + true + true 2 + false ProjectExplorer.CustomExecutableRunConfiguration - false true - false true - 1 + 1 ProjectExplorer.Project.TargetCount - 1 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/F1:F103/shutter/shutter.h b/F1:F103/shutter/shutter.h index 3c4359b..cc254bb 100644 --- a/F1:F103/shutter/shutter.h +++ b/F1:F103/shutter/shutter.h @@ -20,11 +20,6 @@ #include -// opening/closing time (ms) -#define SHUTTER_TIME (20) -// waiting for getting status time (ms) -#define WAITING_TIME (60) - typedef enum{ SHUTTER_ERROR, // shutter is absent? SHUTTER_RELAX, // powered off diff --git a/F1:F103/shutter/usbhw.c b/F1:F103/shutter/usbhw.c index ea62831..ef5387f 100644 --- a/F1:F103/shutter/usbhw.c +++ b/F1:F103/shutter/usbhw.c @@ -23,7 +23,6 @@ void USB_setup(){ NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn); - USBPU_OFF(); RCC->APB1ENR |= RCC_APB1ENR_USBEN; RCC->APB2ENR |= USB_RCC; USB->CNTR = USB_CNTR_FRES; // Force USB Reset @@ -35,7 +34,6 @@ void USB_setup(){ USB->ISTR = 0; USB->CNTR = USB_CNTR_RESETM | USB_CNTR_WKUPM; // allow only wakeup & reset interrupts NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); - USBPU_ON(); } static uint16_t lastaddr = LASTADDR_DEFAULT; diff --git a/F1:F103/shutter/version.inc b/F1:F103/shutter/version.inc index 4ae7bc7..9e69f18 100644 --- a/F1:F103/shutter/version.inc +++ b/F1:F103/shutter/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "84" -#define BUILD_DATE "2023-11-29" +#define BUILD_NUMBER "103" +#define BUILD_DATE "2023-12-07"