diff --git a/F1:F103/shutter/Readme.md b/F1:F103/shutter/Readme.md index 999afd0..3519dc4 100644 --- a/F1:F103/shutter/Readme.md +++ b/F1:F103/shutter/Readme.md @@ -4,6 +4,21 @@ Shutter control Works with bi-stable shutter. You can find the device in `/dev/shutterX` (symlink to `/dev/ttyUSBX`). +After powered on, the device will try to close shutter (during one second). + +The CCD (or manual) controlled input allows to open/close shutter by changing its level (depending on `ccdactive` parameter). +If current configuration can't open or close the shutter immediately, it will be opened/closed as soon as possible, while the input holds its level. + +When the shutter is closed, the device will send over USB a message like +``` +exptime=10000 +shutter=closed +``` +with calculated value of opened time and current shutter state. +If the error occured and shutter can't be closed, user will read `exp=cantclose`, shutter will come into error state. You should close the shutter by external command in that case. + +After the shutter completely opened, user can read a message `shutter=opened`. + ## Pinout **PB0** (pullup in) - hall (or reed switch) sensor input (active low) - opened shutter detector @@ -58,20 +73,20 @@ You can find the device in `/dev/shutterX` (symlink to `/dev/ttyUSBX`). * 'v' - get Vdd (/100V) * 'V' - get shutter voltage (/100V) - -If you will enter wrong long message, will receive its echo back. Any wrong short command will show help list. +Any wrong long message will echo back. Any wrong short command will show help list. ## Shutter control -Commands '0', '1' and '2' should be used only for debugging purposes. +Commands '0' ... '3' should be used only for debugging purposes. To open/close shutter use only 'O', 'C' and 'E' commands. When opening or closing shutter you will first receive an answer: `OK` if command could be done or `ERR` if there's insufficient voltage on capacitor or shutter is absent. After opened the message `shutter=opened` will appear. After closing you will receive messages `exptime=xxx` (when `xxx` is approx. exp. time in milliseconds) and `shutter=closed`. Command 'E' could return `OK`, `ERR` or `ERRNUM`/`I32OVERFLOW` in wrong number format (number could be decimal, 0x.. - hexadecimal, b.. - binary or 0.. - octal). +"Status" command in this case will return `shutter=exposing` and `expfor=xxx` - the given exposition time. 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'. +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 * '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`. @@ -82,7 +97,7 @@ If shutter can't be closed, you will give a lots of "exp=cantclose" and differen * 'v' - `vdd=val`, val in V*100 -* 'V' - "voltage=val", val in V*100 +* 'V' - `voltage=val`, val in V*100 * 'S' - several answers: * `shutter=`: `closed`, `opened`, `error`, `process`, `wait` or `exposing` - shutter state @@ -104,9 +119,17 @@ workvoltage=700 shuttertime=20 waitingtime=30 shtrvmul=143 -shtrdiv=25 +shtrvdiv=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 +* `userconf_sz` - "magick" number to determine first non-empty record in flash storage. The aligned size of one record in bytes. +* `ccdactive` - is level of 'CCD' input to open shutter (1 to open on high and 0 to open on low signal), change this value with command `c`. +* `hallactive` - the same for Hall sensor or reed switch mounted on shutter to indicate opened state, change with `h`. +* `minvoltage` - voltage level on discharged capacitor (V*100 Volts), when shutter is in opened/closed state, the power will be off from coils reaching this level. Can be from 1V to 10V. Change with `<`. +* `workvoltage` - minimal level (V*100 Volts) of charged capacitor to start process of opening/closing, you can open/close shutter only with higher voltage. Can be from 5V to 100V. Change with `>`. +* `shuttertime` - maximal time (milliseconds) of holding active voltage on shutter's coils. Can be from 5ms to 1s. Change with `#`. +* `waitingtime` - waiting time for the shutter to finish its job. The expose time can't be less than this value. Can be from 5ms to 1s. Change with `$`. +* `shtrvmul` - multiplier to calculate capacitor voltage from voltage on ADC input of MCU. Vcap = V*shtrvmul/shtrvdiv. Can be from 1 to 65535. Change with `*`. +* `shtrvdiv` - divider of capacitor voltage calculation. Can be from 1 to 65535. Change with `/`. + +All changes of configuration processed in RAM and acts immediately after changed. If you want to store changes, use command `s`. \ No newline at end of file diff --git a/F1:F103/shutter/flash.c b/F1:F103/shutter/flash.c index f400eb2..d67241c 100644 --- a/F1:F103/shutter/flash.c +++ b/F1:F103/shutter/flash.c @@ -187,6 +187,6 @@ void dump_userconf(){ 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)); + USB_sendstr("\nshtrvdiv="); USB_sendstr(u2str(the_conf.shtrVdiv)); newline(); } diff --git a/F1:F103/shutter/main.c b/F1:F103/shutter/main.c index 4da817c..523a1fa 100644 --- a/F1:F103/shutter/main.c +++ b/F1:F103/shutter/main.c @@ -41,7 +41,7 @@ int main(void){ 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; + while(!close_shutter() && Tms < 1000) IWDG->KR = IWDG_REFRESH; USBPU_ON(); uint32_t Terr = Tms + 2*ERRPERIOD; diff --git a/F1:F103/shutter/shutter.bin b/F1:F103/shutter/shutter.bin index 31e0f25..82e4095 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 6419177..afe2b8b 100644 --- a/F1:F103/shutter/shutter.c +++ b/F1:F103/shutter/shutter.c @@ -39,7 +39,7 @@ static const char *regstates[4] = { static const char *opcl[2] = {"closed", "opened"}; -shutter_state shutterstate = SHUTTER_ERROR; +shutter_state shutterstate = SHUTTER_RELAX; static shutter_state nextstate = SHUTTER_RELAX; static uint32_t Tstart = 0, Texp = 0, Topened = 0; @@ -117,7 +117,7 @@ void process_shutter(){ } break; case SHUTTER_WAIT: // wait for mechanical work done - if(Tms - Tstart > the_conf.waitingtime){ + if(Tms - Tstart >= the_conf.waitingtime){ SHTRHIZ(); shutterstate = nextstate; int h = CHKHALL(); diff --git a/F1:F103/shutter/version.inc b/F1:F103/shutter/version.inc index 9e69f18..bf5098f 100644 --- a/F1:F103/shutter/version.inc +++ b/F1:F103/shutter/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "103" -#define BUILD_DATE "2023-12-07" +#define BUILD_NUMBER "107" +#define BUILD_DATE "2023-12-08"