mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 10:45:11 +03:00
code tested
This commit is contained in:
parent
c2976d8ba1
commit
482b612e9f
75
F1:F103/shutter/Readme.md
Normal file
75
F1:F103/shutter/Readme.md
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
Shutter control
|
||||||
|
===============
|
||||||
|
|
||||||
|
Works with bi-stable shutter.
|
||||||
|
You can find the device in `/dev/shutterX` (symlink to `/dev/ttyUSBX`).
|
||||||
|
|
||||||
|
## Pinout
|
||||||
|
|
||||||
|
**PB0** (pullup in) - hall (or reed switch) sensor input (active low) - opened shutter detector
|
||||||
|
|
||||||
|
**PB11** (pullup in) - CCD or button input: open at low signal, close at high
|
||||||
|
|
||||||
|
**PA3** (ADC in) - shutter voltage (approx 1/12 U)
|
||||||
|
|
||||||
|
**PA5** (PP out) - TLE5205 IN2
|
||||||
|
|
||||||
|
**PA6** (PP out) - TLE5205 IN1
|
||||||
|
|
||||||
|
**PA7** (pullup in) - TLE5205 FB
|
||||||
|
|
||||||
|
**PA10** (PP out) - USB pullup (active low)
|
||||||
|
|
||||||
|
**PA11**, **PA12** - USB
|
||||||
|
|
||||||
|
**PA13**, **PA14** - SWD
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
* '0' - shutter CLO
|
||||||
|
* '1' - shutter OPE
|
||||||
|
* '2' - shutter HIZ
|
||||||
|
* 'A' - get raw ADC values
|
||||||
|
* 'C' - close shutter / abort exposition
|
||||||
|
* 'E n' - expose for n milliseconds
|
||||||
|
* 'O' - open shutter
|
||||||
|
* 'R' - software reset
|
||||||
|
* 'S' - get shutter state; also hall and ccd inputs state (1 - active)
|
||||||
|
* 't' - get MCU temperature (/10degC)
|
||||||
|
* '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
|
||||||
|
Commands '0', '1' and '2' 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).
|
||||||
|
|
||||||
|
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
|
||||||
|
* '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.
|
||||||
|
|
||||||
|
* 'T' - `tms=val`, val in ms.
|
||||||
|
|
||||||
|
* 'v' - `vdd=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
|
||||||
|
* `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)
|
||||||
|
* `hall=`: `0` or `1` - 1 for opened shutter, 0 for closed
|
||||||
|
* `ccd=`: `0` or `1` - 1 for active (closed contacts) state of "CCD" input
|
||||||
@ -1,19 +0,0 @@
|
|||||||
Shutter control
|
|
||||||
===============
|
|
||||||
|
|
||||||
Works with bi-stable shutter.
|
|
||||||
|
|
||||||
Pinout:
|
|
||||||
PB0 (pullup in) - hall (or reed switch) sensor input (active low) - opened shutter detector
|
|
||||||
PB11 (pullup in) - CCD or button input: open at low signal, close at high
|
|
||||||
|
|
||||||
PA3 (ADC in) - shutter voltage (approx 1/12 U)
|
|
||||||
PA5 (PP out) - TLE5205 IN2
|
|
||||||
PA6 (PP out) - TLE5205 IN1
|
|
||||||
PA7 (pullup in) - TLE5205 FB
|
|
||||||
PA10 (PP out) - USB pullup (active low)
|
|
||||||
PA11,12 - USB
|
|
||||||
PA13,14 - SWD
|
|
||||||
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
@ -1 +0,0 @@
|
|||||||
/home/eddy/Docs/SAO/Zeiss-1000/Small_photometer/shutter/kicad/shutter
|
|
||||||
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
#define BUILD_NUMBER "70"
|
|
||||||
#define BUILD_DATE "2023-09-21"
|
|
||||||
|
Before Width: | Height: | Size: 380 KiB After Width: | Height: | Size: 380 KiB |
38
F1:F103/shutter/kicad/shutter.csv
Normal file
38
F1:F103/shutter/kicad/shutter.csv
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"Source:","/home/eddy/Docs/SAO/Zeiss-1000/Small_photometer/shutter/kicad/shutter/shutter.kicad_sch"
|
||||||
|
"Date:","Вт 12 сен 2023 17:34:36"
|
||||||
|
"Tool:","Eeschema 7.0.5"
|
||||||
|
"Generator:","/usr/local/share/kicad/plugins/bom_csv_grouped_by_value.py"
|
||||||
|
"Component Count:","44"
|
||||||
|
|
||||||
|
"Collated Components:"
|
||||||
|
|
||||||
|
"Item","Qty","Reference(s)","Value","LibPart","Footprint","Datasheet","DNP"
|
||||||
|
"1","1","C1","2200u, 40V","ALL-rescue:CP1","Capacitor_THT:CP_Radial_D17.0mm_P7.50mm","",""
|
||||||
|
"2","1","C2","1u","Device:C","Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder","~",""
|
||||||
|
"3","5","C3, C5, C6, C7, C8","0.1","Device:C","Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder","~",""
|
||||||
|
"4","1","C4","47u","Device:C_Polarized","Capacitor_Tantalum_SMD:CP_EIA-6032-28_Kemet-C_Pad2.25x2.35mm_HandSolder","~",""
|
||||||
|
"5","2","C9, C10","6","Device:C","Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder","~",""
|
||||||
|
"6","5","D1, D2, D3, D4, D5","1N5819","Device:D_Schottky","Diode_SMD:D_SOD-323_HandSoldering","~",""
|
||||||
|
"7","1","DA1","TLE5205","my_elements:TLE5205","Package_TO_SOT_THT:TO-220-7_P2.54x3.8mm_StaggerEven_Lead5.85mm_TabDown","",""
|
||||||
|
"8","4","H1, H2, H3, H4","MountingHole","Mechanical:MountingHole","MountingHole:MountingHole_3.2mm_M3","~",""
|
||||||
|
"9","1","J1","shutter","Connector:Conn_01x02_Female","TerminalBlock_Phoenix:TerminalBlock_Phoenix_MKDS-1,5-2-5.08_1x02_P5.08mm_Horizontal","~",""
|
||||||
|
"10","1","J2","power","Connector:Conn_01x02_Female","TerminalBlock_Phoenix:TerminalBlock_Phoenix_MKDS-1,5-2-5.08_1x02_P5.08mm_Horizontal","~",""
|
||||||
|
"11","1","J3","SWD","Connector:Conn_01x06_Female","Connector_PinHeader_1.27mm:PinHeader_1x06_P1.27mm_Vertical","~",""
|
||||||
|
"12","1","J4","5v","Connector_Generic:Conn_01x01","Connector_PinHeader_2.54mm:PinHeader_1x01_P2.54mm_Vertical","~",""
|
||||||
|
"13","1","J5","GND","Connector_Generic:Conn_01x01","Connector_PinHeader_2.54mm:PinHeader_1x01_P2.54mm_Vertical","~",""
|
||||||
|
"14","1","J6","3v3","Connector_Generic:Conn_01x01","Connector_PinHeader_2.54mm:PinHeader_1x01_P2.54mm_Vertical","~",""
|
||||||
|
"15","1","J7","USB_B","Connector:USB_B","Connector_USB:USB_B_Lumberg_2411_02_Horizontal"," ~",""
|
||||||
|
"16","1","J8","hall","Connector:Conn_01x02_Female","Connector_JST:JST_PH_B2B-PH-K_1x02_P2.00mm_Vertical","~",""
|
||||||
|
"17","1","J9","ccd","Connector:Conn_01x02_Female","Connector_JST:JST_PH_B2B-PH-K_1x02_P2.00mm_Vertical","~",""
|
||||||
|
"18","1","Q1","DTA114Y","Transistor_BJT:DTA114Y","Package_TO_SOT_SMD:SOT-323_SC-70_Handsoldering","",""
|
||||||
|
"19","1","R1","6.9","Device:R","Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder","~",""
|
||||||
|
"20","1","R2","56k","Device:R","Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder","~",""
|
||||||
|
"21","3","R3, R5, R6","4k7","Device:R","Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder","~",""
|
||||||
|
"22","1","R4","300 II","Device:R","Resistor_THT:R_Axial_Power_L20.0mm_W6.4mm_P22.40mm","~",""
|
||||||
|
"23","1","R7","10k","Device:R","Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder","~",""
|
||||||
|
"24","2","R8, R9","22","Device:R","Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder","~",""
|
||||||
|
"25","1","R10","1k5","Device:R","Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder","~",""
|
||||||
|
"26","1","U1","LM1117-3.3","Regulator_Linear:LM1117-3.3","Package_TO_SOT_SMD:SOT-223-3_TabPin2","http://www.ti.com/lit/ds/symlink/lm1117.pdf",""
|
||||||
|
"27","1","U2","STM32F103C6Tx","MCU_ST_STM32F1:STM32F103C6Tx","Package_QFP:LQFP-48_7x7mm_P0.5mm","http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00210843.pdf",""
|
||||||
|
"28","1","U3","USBLC6-2SC6","Power_Protection:USBLC6-2SC6","Package_TO_SOT_SMD:SOT-23-6_Handsoldering","http://www2.st.com/resource/en/datasheet/CD00050750.pdf",""
|
||||||
|
"29","1","Y1","NX5032GA-8MHz","Device:Crystal","Crystal:Crystal_SMD_5032-2Pin_5.0x3.2mm","~",""
|
||||||
|
Can't render this file because it has a wrong number of fields in line 7.
|
@ -53,8 +53,8 @@
|
|||||||
)
|
)
|
||||||
(pad_to_mask_clearance 0)
|
(pad_to_mask_clearance 0)
|
||||||
(pcbplotparams
|
(pcbplotparams
|
||||||
(layerselection 0x0001000_ffffffff)
|
(layerselection 0x0000020_7ffffffe)
|
||||||
(plot_on_all_layers_selection 0x0000000_00000000)
|
(plot_on_all_layers_selection 0x0001080_00000000)
|
||||||
(disableapertmacros false)
|
(disableapertmacros false)
|
||||||
(usegerberextensions false)
|
(usegerberextensions false)
|
||||||
(usegerberattributes true)
|
(usegerberattributes true)
|
||||||
@ -80,11 +80,11 @@
|
|||||||
(plotinvisibletext false)
|
(plotinvisibletext false)
|
||||||
(sketchpadsonfab false)
|
(sketchpadsonfab false)
|
||||||
(subtractmaskfromsilk false)
|
(subtractmaskfromsilk false)
|
||||||
(outputformat 1)
|
(outputformat 5)
|
||||||
(mirror false)
|
(mirror false)
|
||||||
(drillshape 0)
|
(drillshape 2)
|
||||||
(scaleselection 1)
|
(scaleselection 1)
|
||||||
(outputdirectory "gerbers/")
|
(outputdirectory "svgs")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,7 +65,7 @@
|
|||||||
40
|
40
|
||||||
],
|
],
|
||||||
"visible_layers": "fffffff_ffffffff",
|
"visible_layers": "fffffff_ffffffff",
|
||||||
"zone_display_mode": 0
|
"zone_display_mode": 1
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
"filename": "shutter.kicad_prl",
|
"filename": "shutter.kicad_prl",
|
||||||
@ -3920,7 +3920,7 @@
|
|||||||
(property "Reference" "R4" (at 51.054 123.9774 90)
|
(property "Reference" "R4" (at 51.054 123.9774 90)
|
||||||
(effects (font (size 1.27 1.27)) (justify left))
|
(effects (font (size 1.27 1.27)) (justify left))
|
||||||
)
|
)
|
||||||
(property "Value" "300 II" (at 52.451 128.27 90)
|
(property "Value" "150 II" (at 52.451 128.27 90)
|
||||||
(effects (font (size 1.27 1.27)) (justify left))
|
(effects (font (size 1.27 1.27)) (justify left))
|
||||||
)
|
)
|
||||||
(property "Footprint" "Resistor_THT:R_Axial_Power_L20.0mm_W6.4mm_P22.40mm" (at 49.53 127.889 90)
|
(property "Footprint" "Resistor_THT:R_Axial_Power_L20.0mm_W6.4mm_P22.40mm" (at 49.53 127.889 90)
|
||||||
BIN
F1:F103/shutter/kicad/shutter.pdf
Normal file
BIN
F1:F103/shutter/kicad/shutter.pdf
Normal file
Binary file not shown.
1105
F1:F103/shutter/kicad/shutter.xml
Normal file
1105
F1:F103/shutter/kicad/shutter.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,7 @@
|
|||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "shutter.h"
|
#include "shutter.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
#include "version.inc"
|
||||||
|
|
||||||
char *omit_spaces(const char *buf){
|
char *omit_spaces(const char *buf){
|
||||||
while(*buf){
|
while(*buf){
|
||||||
@ -153,12 +154,13 @@ char *getnum(const char *txt, uint32_t *N){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* helpmsg =
|
const char* helpmsg =
|
||||||
|
"https://github.com/eddyem/stm32samples/tree/master/F1:F103/shutter build#" BUILD_NUMBER " @ " BUILD_DATE "\n"
|
||||||
"'0' - shutter CLO\n"
|
"'0' - shutter CLO\n"
|
||||||
"'1' - shutter OPE\n"
|
"'1' - shutter OPE\n"
|
||||||
"'2' - shutter HIZ\n"
|
"'2' - shutter HIZ\n"
|
||||||
"'A' - get raw ADC values\n"
|
"'A' - get raw ADC values\n"
|
||||||
"'C' - close shutter\n"
|
"'C' - close shutter / abort exposition\n"
|
||||||
//"'N' - read number (dec, 0xhex, 0oct, bbin) and show it in decimal\n"
|
"'E n' - expose for n milliseconds\n"
|
||||||
"'O' - open shutter\n"
|
"'O' - open shutter\n"
|
||||||
"'R' - software reset\n"
|
"'R' - software reset\n"
|
||||||
"'S' - get shutter state; also hall and ccd inputs state (1 - active)\n"
|
"'S' - get shutter state; also hall and ccd inputs state (1 - active)\n"
|
||||||
@ -186,7 +188,7 @@ void bufputchar(char c){
|
|||||||
*bptr = 0;
|
*bptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint8_t usbON;
|
static const char *OK = "OK", *ERR = "ERR";
|
||||||
const char *parse_cmd(const char *buf){
|
const char *parse_cmd(const char *buf){
|
||||||
uint32_t u3;
|
uint32_t u3;
|
||||||
initbuf();
|
initbuf();
|
||||||
@ -213,12 +215,12 @@ const char *parse_cmd(const char *buf){
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
if(close_shutter()) add2buf("OK");
|
if(close_shutter()) add2buf(OK);
|
||||||
else add2buf("ERR");
|
else add2buf(ERR);
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
if(open_shutter()) add2buf("OK");
|
if(open_shutter()) add2buf(OK);
|
||||||
else add2buf("ERR");
|
else add2buf(ERR);
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
USB_sendstr("Soft reset\n");
|
USB_sendstr("Soft reset\n");
|
||||||
@ -258,29 +260,29 @@ const char *parse_cmd(const char *buf){
|
|||||||
default:
|
default:
|
||||||
return helpmsg;
|
return helpmsg;
|
||||||
}
|
}
|
||||||
bufputchar('\n');
|
}else{ // long messages
|
||||||
return stbuf;
|
|
||||||
}
|
|
||||||
uint32_t Num = 0;
|
uint32_t Num = 0;
|
||||||
char *nxt;
|
char *nxt;
|
||||||
switch(*buf){ // long messages
|
switch(*buf){
|
||||||
case 'N':
|
case 'E':
|
||||||
++buf;
|
++buf;
|
||||||
nxt = getnum(buf, &Num);
|
nxt = getnum(buf, &Num);
|
||||||
if(buf == nxt){
|
if(buf == nxt){
|
||||||
if(Num == 0) return "Wrong number\n";
|
if(Num == 0) return "ERRNUM\n";
|
||||||
return "Integer32 overflow\n";
|
return "I32OVERFLOW\n";
|
||||||
}
|
}
|
||||||
add2buf("You give: ");
|
if(shutterstate != SHUTTER_RELAX){
|
||||||
add2buf(u2str(Num));
|
add2buf(ERR);
|
||||||
if(*nxt && *nxt != '\n'){
|
break;
|
||||||
add2buf(", the rest of string: ");
|
}
|
||||||
add2buf(nxt);
|
if(expose_shutter(Num)) add2buf(OK);
|
||||||
}else add2buf("\n");
|
else add2buf(ERR);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
bufputchar('\n');
|
||||||
return stbuf;
|
return stbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
BIN
F1:F103/shutter/shutter.bin
Executable file
BIN
F1:F103/shutter/shutter.bin
Executable file
Binary file not shown.
@ -27,21 +27,29 @@ static const char *states[SHUTTER_STATE_AMOUNT] = {
|
|||||||
[SHUTTER_RELAX] = "relax",
|
[SHUTTER_RELAX] = "relax",
|
||||||
[SHUTTER_PROCESS] = "process",
|
[SHUTTER_PROCESS] = "process",
|
||||||
[SHUTTER_WAIT] = "wait",
|
[SHUTTER_WAIT] = "wait",
|
||||||
|
[SHUTTER_EXPOSE] = "exposing",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *regstates[4] = {"open", "close", "off", "hiZ"};
|
||||||
|
|
||||||
static const char *opcl[2] = {"closed", "opened"};
|
static const char *opcl[2] = {"closed", "opened"};
|
||||||
|
|
||||||
shutter_state shutterstate = SHUTTER_ERROR;
|
shutter_state shutterstate = SHUTTER_ERROR;
|
||||||
|
static shutter_state nextstate = SHUTTER_RELAX;
|
||||||
|
|
||||||
static uint32_t Tstart = 0;
|
static uint32_t Tstart = 0, Texp = 0, Topened = 0;
|
||||||
|
|
||||||
static int changestate(int open){
|
static int changestate(int open, shutter_state nxt){
|
||||||
if(open == CHKHALL()) return TRUE; // already opened or closed
|
if(open == CHKHALL()){
|
||||||
|
shutterstate = SHUTTER_RELAX;
|
||||||
|
return TRUE; // already opened or closed
|
||||||
|
}
|
||||||
if(getADCvoltage(CHSHTR) < SHTR_WORK_VOLTAGE / SHTRVMUL) return FALSE;
|
if(getADCvoltage(CHSHTR) < SHTR_WORK_VOLTAGE / SHTRVMUL) return FALSE;
|
||||||
if(shutterstate == SHUTTER_ERROR) return FALSE;
|
if(shutterstate == SHUTTER_ERROR) return FALSE;
|
||||||
if(open) SHTROPEN();
|
if(open) SHTROPEN();
|
||||||
else SHTRCLOSE();
|
else SHTRCLOSE();
|
||||||
shutterstate = SHUTTER_PROCESS;
|
shutterstate = SHUTTER_PROCESS;
|
||||||
|
nextstate = nxt;
|
||||||
Tstart = Tms;
|
Tstart = Tms;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -51,25 +59,29 @@ static int changestate(int open){
|
|||||||
* @return false if can't work due to error (no shutter) or insufficient voltage
|
* @return false if can't work due to error (no shutter) or insufficient voltage
|
||||||
*/
|
*/
|
||||||
int open_shutter(){
|
int open_shutter(){
|
||||||
return changestate(1);
|
return changestate(1, SHUTTER_RELAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
int close_shutter(){
|
int close_shutter(){
|
||||||
return changestate(0);
|
return changestate(0, SHUTTER_RELAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
int expose_shutter(uint32_t exptime){
|
||||||
|
if(!changestate(1, SHUTTER_EXPOSE)) return FALSE;
|
||||||
|
Texp = exptime;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_shutter(){
|
void process_shutter(){
|
||||||
#ifdef EBUG
|
|
||||||
static uint32_t T = 0;
|
static uint32_t T = 0;
|
||||||
#endif
|
|
||||||
uint32_t V = getADCvoltage(CHSHTR)*SHTRVMUL;
|
uint32_t V = getADCvoltage(CHSHTR)*SHTRVMUL;
|
||||||
switch(shutterstate){
|
switch(shutterstate){
|
||||||
case SHUTTER_ERROR:
|
case SHUTTER_ERROR: // error state: no shutter?
|
||||||
SHTROFF();
|
SHTROFF();
|
||||||
shutterstate = SHUTTER_WAIT;
|
shutterstate = SHUTTER_WAIT;
|
||||||
Tstart = Tms;
|
Tstart = Tms;
|
||||||
break;
|
break;
|
||||||
case SHUTTER_PROCESS:
|
case SHUTTER_PROCESS: // process opening or closing
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
if(T != Tms){
|
if(T != Tms){
|
||||||
T = Tms;
|
T = Tms;
|
||||||
@ -83,14 +95,27 @@ void process_shutter(){
|
|||||||
Tstart = Tms;
|
Tstart = Tms;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SHUTTER_WAIT:
|
case SHUTTER_WAIT: // wait for mechanical work done
|
||||||
if(Tms - Tstart > WAITING_TIME){
|
if(Tms - Tstart > WAITING_TIME){
|
||||||
SHTRHIZ();
|
SHTRHIZ();
|
||||||
shutterstate = SHUTTER_RELAX;
|
shutterstate = nextstate;
|
||||||
USB_sendstr("shutter=");
|
int h = CHKHALL();
|
||||||
USB_sendstr(opcl[CHKHALL()]);
|
if(h) Topened = Tms;
|
||||||
|
else{
|
||||||
|
USB_sendstr("exptime=");
|
||||||
|
USB_sendstr(u2str(Tms - Topened - SHUTTER_TIME));
|
||||||
USB_putbyte('\n');
|
USB_putbyte('\n');
|
||||||
}
|
}
|
||||||
|
USB_sendstr("shutter=");
|
||||||
|
USB_sendstr(opcl[h]);
|
||||||
|
USB_putbyte('\n');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SHUTTER_EXPOSE: // wait for exposition ends to close 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");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(CHKFB()) shutterstate = SHUTTER_ERROR;
|
if(CHKFB()) shutterstate = SHUTTER_ERROR;
|
||||||
@ -102,11 +127,11 @@ void process_shutter(){
|
|||||||
// check button only when can open/close & shutter operations done
|
// check button only when can open/close & shutter operations done
|
||||||
if(V >= SHTR_WORK_VOLTAGE && shutterstate == SHUTTER_RELAX){ // shutter state allows to open/close
|
if(V >= SHTR_WORK_VOLTAGE && shutterstate == SHUTTER_RELAX){ // shutter state allows to open/close
|
||||||
if(s){ // pressed
|
if(s){ // pressed
|
||||||
if(!CHKHALL()){ if(open_shutter()){oldbtnstate = s; USB_sendstr(" open, old->1\n");}}
|
if(!CHKHALL()){ if(open_shutter()){oldbtnstate = s; /*USB_sendstr(" open, old->1\n");*/}}
|
||||||
else{USB_sendstr("pressed when CHKHALL(), old->1\n"); oldbtnstate = s;}
|
else{/*USB_sendstr("pressed when CHKHALL(), old->1\n");*/ oldbtnstate = s;}
|
||||||
}else{ // released
|
}else{ // released
|
||||||
if(CHKHALL()){ if(close_shutter()){oldbtnstate = s; USB_sendstr(" close, old->0\n");}}
|
if(CHKHALL()){ if(close_shutter()){oldbtnstate = s; /*USB_sendstr(" close, old->0\n");*/}}
|
||||||
else{USB_sendstr("released when !CHKHALL(), old->0\n"); oldbtnstate = s;}
|
else{/*USB_sendstr("released when !CHKHALL(), old->0\n");*/ oldbtnstate = s;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,8 +140,12 @@ void print_shutter_state(){
|
|||||||
add2buf("shutter=");
|
add2buf("shutter=");
|
||||||
if(shutterstate != SHUTTER_RELAX) add2buf(states[shutterstate]);
|
if(shutterstate != SHUTTER_RELAX) add2buf(states[shutterstate]);
|
||||||
else add2buf(opcl[CHKHALL()]);
|
else add2buf(opcl[CHKHALL()]);
|
||||||
|
if(CHKHALL()){
|
||||||
|
add2buf("\nexptime=");
|
||||||
|
add2buf(u2str(Tms - Topened));
|
||||||
|
}
|
||||||
add2buf("\nregstate=");
|
add2buf("\nregstate=");
|
||||||
bufputchar('0' + SHTRSTATE());
|
add2buf(regstates[SHTRSTATE()]);
|
||||||
add2buf("\nfbstate=");
|
add2buf("\nfbstate=");
|
||||||
bufputchar('0' + CHKFB());
|
bufputchar('0' + CHKFB());
|
||||||
bufputchar('\n');
|
bufputchar('\n');
|
||||||
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stm32f1.h>
|
||||||
|
|
||||||
// opening/closing time (ms)
|
// opening/closing time (ms)
|
||||||
#define SHUTTER_TIME (20)
|
#define SHUTTER_TIME (20)
|
||||||
// waiting for getting status time (ms)
|
// waiting for getting status time (ms)
|
||||||
@ -28,6 +30,7 @@ typedef enum{
|
|||||||
SHUTTER_RELAX, // powered off
|
SHUTTER_RELAX, // powered off
|
||||||
SHUTTER_PROCESS, // opened or closed
|
SHUTTER_PROCESS, // opened or closed
|
||||||
SHUTTER_WAIT, // wait in off state before turn to hi-z
|
SHUTTER_WAIT, // wait in off state before turn to hi-z
|
||||||
|
SHUTTER_EXPOSE, //
|
||||||
SHUTTER_STATE_AMOUNT
|
SHUTTER_STATE_AMOUNT
|
||||||
} shutter_state;
|
} shutter_state;
|
||||||
|
|
||||||
@ -36,4 +39,5 @@ extern shutter_state shutterstate;
|
|||||||
void process_shutter();
|
void process_shutter();
|
||||||
int open_shutter();
|
int open_shutter();
|
||||||
int close_shutter();
|
int close_shutter();
|
||||||
|
int expose_shutter(uint32_t exptime);
|
||||||
void print_shutter_state();
|
void print_shutter_state();
|
||||||
@ -131,7 +131,7 @@ _USB_LANG_ID_(LD, LANG_US);
|
|||||||
_USB_STRING_(SD, u"0.0.1");
|
_USB_STRING_(SD, u"0.0.1");
|
||||||
_USB_STRING_(MD, u"Prolific Technology Inc.");
|
_USB_STRING_(MD, u"Prolific Technology Inc.");
|
||||||
_USB_STRING_(PD, u"USB-Serial Controller");
|
_USB_STRING_(PD, u"USB-Serial Controller");
|
||||||
_USB_STRING_(ID, u"shutter_emulator");
|
_USB_STRING_(ID, u"shutter");
|
||||||
static void const *StringDescriptor[iDESCR_AMOUNT] = {
|
static void const *StringDescriptor[iDESCR_AMOUNT] = {
|
||||||
[iLANGUAGE_DESCR] = &LD,
|
[iLANGUAGE_DESCR] = &LD,
|
||||||
[iMANUFACTURER_DESCR] = &MD,
|
[iMANUFACTURER_DESCR] = &MD,
|
||||||
2
F1:F103/shutter/version.inc
Normal file
2
F1:F103/shutter/version.inc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define BUILD_NUMBER "80"
|
||||||
|
#define BUILD_DATE "2023-09-22"
|
||||||
Loading…
x
Reference in New Issue
Block a user