code tested

This commit is contained in:
Edward Emelianov 2023-09-22 16:21:05 +03:00
parent c2976d8ba1
commit 482b612e9f
50 changed files with 1309 additions and 76 deletions

75
F1:F103/shutter/Readme.md Normal file
View 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

View File

@ -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:

View File

@ -1 +0,0 @@
/home/eddy/Docs/SAO/Zeiss-1000/Small_photometer/shutter/kicad/shutter

Binary file not shown.

View File

@ -1,2 +0,0 @@
#define BUILD_NUMBER "70"
#define BUILD_DATE "2023-09-21"

View File

Before

Width:  |  Height:  |  Size: 380 KiB

After

Width:  |  Height:  |  Size: 380 KiB

View 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.

View File

@ -53,8 +53,8 @@
)
(pad_to_mask_clearance 0)
(pcbplotparams
(layerselection 0x0001000_ffffffff)
(plot_on_all_layers_selection 0x0000000_00000000)
(layerselection 0x0000020_7ffffffe)
(plot_on_all_layers_selection 0x0001080_00000000)
(disableapertmacros false)
(usegerberextensions false)
(usegerberattributes true)
@ -80,11 +80,11 @@
(plotinvisibletext false)
(sketchpadsonfab false)
(subtractmaskfromsilk false)
(outputformat 1)
(outputformat 5)
(mirror false)
(drillshape 0)
(drillshape 2)
(scaleselection 1)
(outputdirectory "gerbers/")
(outputdirectory "svgs")
)
)

View File

@ -65,7 +65,7 @@
40
],
"visible_layers": "fffffff_ffffffff",
"zone_display_mode": 0
"zone_display_mode": 1
},
"meta": {
"filename": "shutter.kicad_prl",

View File

@ -3920,7 +3920,7 @@
(property "Reference" "R4" (at 51.054 123.9774 90)
(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))
)
(property "Footprint" "Resistor_THT:R_Axial_Power_L20.0mm_W6.4mm_P22.40mm" (at 49.53 127.889 90)

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@
#include "proto.h"
#include "shutter.h"
#include "usb.h"
#include "version.inc"
char *omit_spaces(const char *buf){
while(*buf){
@ -153,12 +154,13 @@ 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"
"'A' - get raw ADC values\n"
"'C' - close shutter\n"
//"'N' - read number (dec, 0xhex, 0oct, bbin) and show it in decimal\n"
"'C' - close shutter / abort exposition\n"
"'E n' - expose for n milliseconds\n"
"'O' - open shutter\n"
"'R' - software reset\n"
"'S' - get shutter state; also hall and ccd inputs state (1 - active)\n"
@ -186,7 +188,7 @@ void bufputchar(char c){
*bptr = 0;
}
extern uint8_t usbON;
static const char *OK = "OK", *ERR = "ERR";
const char *parse_cmd(const char *buf){
uint32_t u3;
initbuf();
@ -213,12 +215,12 @@ const char *parse_cmd(const char *buf){
}
break;
case 'C':
if(close_shutter()) add2buf("OK");
else add2buf("ERR");
if(close_shutter()) add2buf(OK);
else add2buf(ERR);
break;
case 'O':
if(open_shutter()) add2buf("OK");
else add2buf("ERR");
if(open_shutter()) add2buf(OK);
else add2buf(ERR);
break;
case 'R':
USB_sendstr("Soft reset\n");
@ -258,29 +260,29 @@ const char *parse_cmd(const char *buf){
default:
return helpmsg;
}
bufputchar('\n');
return stbuf;
}
uint32_t Num = 0;
char *nxt;
switch(*buf){ // long messages
case 'N':
++buf;
nxt = getnum(buf, &Num);
if(buf == nxt){
if(Num == 0) return "Wrong number\n";
return "Integer32 overflow\n";
}
add2buf("You give: ");
add2buf(u2str(Num));
if(*nxt && *nxt != '\n'){
add2buf(", the rest of string: ");
add2buf(nxt);
}else add2buf("\n");
break;
default:
return buf;
}else{ // long messages
uint32_t Num = 0;
char *nxt;
switch(*buf){
case 'E':
++buf;
nxt = getnum(buf, &Num);
if(buf == nxt){
if(Num == 0) return "ERRNUM\n";
return "I32OVERFLOW\n";
}
if(shutterstate != SHUTTER_RELAX){
add2buf(ERR);
break;
}
if(expose_shutter(Num)) add2buf(OK);
else add2buf(ERR);
break;
default:
return buf;
}
}
bufputchar('\n');
return stbuf;
}

BIN
F1:F103/shutter/shutter.bin Executable file

Binary file not shown.

View File

@ -27,21 +27,29 @@ static const char *states[SHUTTER_STATE_AMOUNT] = {
[SHUTTER_RELAX] = "relax",
[SHUTTER_PROCESS] = "process",
[SHUTTER_WAIT] = "wait",
[SHUTTER_EXPOSE] = "exposing",
};
static const char *regstates[4] = {"open", "close", "off", "hiZ"};
static const char *opcl[2] = {"closed", "opened"};
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){
if(open == CHKHALL()) return TRUE; // already opened or closed
static int changestate(int open, shutter_state nxt){
if(open == CHKHALL()){
shutterstate = SHUTTER_RELAX;
return TRUE; // already opened or closed
}
if(getADCvoltage(CHSHTR) < SHTR_WORK_VOLTAGE / SHTRVMUL) return FALSE;
if(shutterstate == SHUTTER_ERROR) return FALSE;
if(open) SHTROPEN();
else SHTRCLOSE();
shutterstate = SHUTTER_PROCESS;
nextstate = nxt;
Tstart = Tms;
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
*/
int open_shutter(){
return changestate(1);
return changestate(1, SHUTTER_RELAX);
}
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(){
#ifdef EBUG
static uint32_t T = 0;
#endif
uint32_t V = getADCvoltage(CHSHTR)*SHTRVMUL;
switch(shutterstate){
case SHUTTER_ERROR:
case SHUTTER_ERROR: // error state: no shutter?
SHTROFF();
shutterstate = SHUTTER_WAIT;
Tstart = Tms;
break;
case SHUTTER_PROCESS:
case SHUTTER_PROCESS: // process opening or closing
#ifdef EBUG
if(T != Tms){
T = Tms;
@ -83,15 +95,28 @@ void process_shutter(){
Tstart = Tms;
}
break;
case SHUTTER_WAIT:
case SHUTTER_WAIT: // wait for mechanical work done
if(Tms - Tstart > WAITING_TIME){
SHTRHIZ();
shutterstate = SHUTTER_RELAX;
shutterstate = nextstate;
int h = CHKHALL();
if(h) Topened = Tms;
else{
USB_sendstr("exptime=");
USB_sendstr(u2str(Tms - Topened - SHUTTER_TIME));
USB_putbyte('\n');
}
USB_sendstr("shutter=");
USB_sendstr(opcl[CHKHALL()]);
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;
default:
if(CHKFB()) shutterstate = SHUTTER_ERROR;
break;
@ -102,11 +127,11 @@ void process_shutter(){
// 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(s){ // pressed
if(!CHKHALL()){ if(open_shutter()){oldbtnstate = s; USB_sendstr(" open, old->1\n");}}
else{USB_sendstr("pressed when CHKHALL(), old->1\n"); oldbtnstate = s;}
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{ // released
if(CHKHALL()){ if(close_shutter()){oldbtnstate = s; USB_sendstr(" close, old->0\n");}}
else{USB_sendstr("released when !CHKHALL(), old->0\n"); oldbtnstate = s;}
if(CHKHALL()){ if(close_shutter()){oldbtnstate = s; /*USB_sendstr(" close, old->0\n");*/}}
else{/*USB_sendstr("released when !CHKHALL(), old->0\n");*/ oldbtnstate = s;}
}
}
}
@ -115,8 +140,12 @@ void print_shutter_state(){
add2buf("shutter=");
if(shutterstate != SHUTTER_RELAX) add2buf(states[shutterstate]);
else add2buf(opcl[CHKHALL()]);
if(CHKHALL()){
add2buf("\nexptime=");
add2buf(u2str(Tms - Topened));
}
add2buf("\nregstate=");
bufputchar('0' + SHTRSTATE());
add2buf(regstates[SHTRSTATE()]);
add2buf("\nfbstate=");
bufputchar('0' + CHKFB());
bufputchar('\n');

View File

@ -18,6 +18,8 @@
#pragma once
#include <stm32f1.h>
// opening/closing time (ms)
#define SHUTTER_TIME (20)
// waiting for getting status time (ms)
@ -28,6 +30,7 @@ typedef enum{
SHUTTER_RELAX, // powered off
SHUTTER_PROCESS, // opened or closed
SHUTTER_WAIT, // wait in off state before turn to hi-z
SHUTTER_EXPOSE, //
SHUTTER_STATE_AMOUNT
} shutter_state;
@ -36,4 +39,5 @@ extern shutter_state shutterstate;
void process_shutter();
int open_shutter();
int close_shutter();
int expose_shutter(uint32_t exptime);
void print_shutter_state();

View File

@ -131,7 +131,7 @@ _USB_LANG_ID_(LD, LANG_US);
_USB_STRING_(SD, u"0.0.1");
_USB_STRING_(MD, u"Prolific Technology Inc.");
_USB_STRING_(PD, u"USB-Serial Controller");
_USB_STRING_(ID, u"shutter_emulator");
_USB_STRING_(ID, u"shutter");
static void const *StringDescriptor[iDESCR_AMOUNT] = {
[iLANGUAGE_DESCR] = &LD,
[iMANUFACTURER_DESCR] = &MD,

View File

@ -0,0 +1,2 @@
#define BUILD_NUMBER "80"
#define BUILD_DATE "2023-09-22"